feat: validate subscription destinations and add the missing update actions - #426
feat: validate subscription destinations and add the missing update actions#426korsvanloon wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: cd44ee2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Following up on the same point raised in #421 — whether this should come from the generator instead of being hand-written. I checked, and the flattening is deliberate: So this PR keeps the hand-written schema, in If you would rather have it come out of the generator, the change is contained to |
…ctions
The generated DestinationSchema is just { type: string }, because the spec models
Destination as a union and the generator flattens that to the base type. So even
in strict mode a draft whose destination was missing required properties was
accepted — which is the gap that started this issue: a consumer generating
subscriptions gets no error for an incomplete destination.
The destination is now checked against a discriminated union covering SQS, SNS,
EventBridge, GoogleCloudPubSub, EventGrid, AzureServiceBus and ConfluentCloud.
It lives in src/schemas/subscription.ts rather than in the generated directory,
and extends the generated draft schema so the rest of the draft keeps using it.
Also implements changeDestination, setChanges, setEvents and setMessages; setKey
was the only action the update handler had.
Refs #76
80050b4 to
cd44ee2
Compare
Addresses the concrete half of #76.
Destination validation
src/schemas/generated/common.tshasDestinationSchema = z.object({ type: z.string() })— the generator flattens theDestinationunion to its base type. So in strict mode a draft like{ "destination": { "type": "SQS", "queueUrl": "https://…/orders" } }was accepted, missing
regionentirely. That is the gap the issue describes: the Terraform provider sees no error when properties are missing.The destination is now validated as a
z.discriminatedUnion("type", …)over the seven types the SDK models: SQS, SNS, EventBridge, GoogleCloudPubSub, EventGrid, AzureServiceBus, ConfluentCloud. It lives in a hand-writtensrc/schemas/subscription.ts(the generated directory says not to edit it) and extendsSubscriptionDraftSchema, so everything else in the draft still uses the generated schema.Note this only bites with
strict: true—AbstractService.postonly validates drafts in strict mode. Worth knowing for the Terraform provider's use of the mock.Update actions
SubscriptionUpdateHandleronly hadsetKey. AddedchangeDestination,setChanges,setEventsandsetMessages, which is the fullSubscriptionUpdateActionunion.What is left of #76
The issue asks for a "proper mock implementation" in general; delivering an actual test message to a destination (the
TestDestinationbehaviour, currently faked by the hardcoded0000000000account id) is not part of this PR, so I have marked the commitRefs #76rather thanFixes.Coverage
subscription.test.ts: an incomplete SQS destination and an unknown destination type both rejected in strict mode, plus one test applying all five update actions in a single request.Full suite: 793 passing.