Repository navigation
feat(notification): define the legacy Event types as v1 Event contracts - #5552
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
fc7ca33 to
4ea8124
Compare
4ea8124 to
e65cda6
Compare
@typespec/json-schema writes property keys and required entries with the declared TypeSpec name and ignores @Encodedname("application/json", ...), while @typespec/openapi3 uses the encoded name. For the same model the two emitters then describe different JSON, and a sealed JSON Schema rejects documents the OpenAPI spec accepts. Notification Event contracts are JSON Schemas of v3 API models, so the v1 filter operators ($eq, $gte, ...) carried by legacy entitlement payloads came out as eq, gte. The patch resolves the application/json name in both property loops and both required-property collectors. Upstream main still has the issue.
…xture The fixture was generated from the v1 OpenAPI schemas with placeholder strings, such as "key_1" for decimal amounts and a hyphenated feature key, plus an extra key in available_actions. Validating it against the Event contract schemas, which keep the v1 patterns and are sealed, rejects those values. Use values the server can actually send.
The four legacy Event types get versioned contracts under the names the storage aliases already use: v1.billing.invoice.created, v1.billing.invoice.updated, v1.entitlement.balance_threshold.triggered and v1.entitlement.usage_period.reset. - Each payload is the data of the legacy payload in the shape the v3 API returns, the snake_case copies of the v1 models. Dedicated roots spread those models, because a contract root names one Event type, so the v3 Event payloads now reference them. The JSON is unchanged. - Each Rule configuration is the type-specific part of the v3 Rule. The v3 Rule models spread it, so the Rule API is unchanged; invoice Rules have an empty configuration. Since no operation references the configurations directly, they have schemas but no apiv3models types, and the generated comments no longer claim one. - The v3 handler tests validate every legacy fixture, as the v3 API returns it, against its contract.
e65cda6 to
f797991
Compare
Overview
What
The four legacy Event types get v1 contracts under the versioned names the storage already accepts (feat(notification): read versioned event types while preserving legacy writes #5546):
invoice.createdv1.billing.invoice.createdinvoice.updatedv1.billing.invoice.updatedentitlements.balance.thresholdv1.entitlement.balance_threshold.triggeredentitlements.resetv1.entitlement.usage_period.resetPayload: the
dataof the legacy payload in the shape the v3 API returns (the snake_caseBillingNotificationEventV1*copies). Rule configuration: the type-specific fields of the v3 Rule. Invoice Rules have an empty one.@typespec/json-schemais patched to honor@encodedName("application/json", …).Why
$eq,$gte, … came out aseq,gte. Because the schemas are sealed, they rejected real payloads.@typespec/openapi3already uses the encoded name. Upstream main still has the issue.How
api/spec/packages/aip/src/notifications/legacy-v1-event-types.tspdeclares the payload roots and Rule configurations.event.tsppoints each legacy payload'sdataat its root.rule.tspspreads the Rule configurations into the v3 Rule models, so the Rule API is unchanged.api/spec/patches/@[email protected]resolves theapplication/jsonname in both property loops and both required-property collectors.api/v3/handlers/notification/events/convert_test.go: each legacy fixture, as the v3 API returns it, must validate against its v1 contract.testdata/legacy_payloads.json) had placeholder values that broke the v1 patterns, such as"key_1"for decimals, a hyphenated feature key and an extraavailable_actionskey. It now has values the server can send.openmeter/notification/README.mdlinks the legacy types to their contracts.Jira: OM-567
Notes for reviewer
Stacked on the
api/v3/modelscodegen PR.v3 API: the JSON is unchanged, but some component names change:
BillingNotificationEventV1InvoicebecomesBillingInvoiceCreatedV1PayloadandBillingInvoiceUpdatedV1Payload;EntitlementBalanceThresholdTriggeredV1PayloadandEntitlementUsagePeriodResetV1Payload.The v3 notification endpoints are unstable. The invoice schema now appears twice in
api/v3/openapi.yaml.The Rule configurations have JSON Schemas but no
apiv3modelstypes, since no operation references them directly. The generated comments no longer claim one.The json-schema patch must be re-applied on TypeSpec upgrades until upstream fixes it. Filing the upstream issue is a follow-up.
Verified:
make gen-api(no drift),go build ./..., notification, v4 and v3 handler tests (live Svix included),make lint-go-fast,make test-api-spec,make lint-api-spec.Untracked design documents and local files are excluded.
Summary by CodeRabbit


Confidence Score: 5/5
The PR appears safe to merge; no actionable defects were found.Summary
Adds v1 contracts for the four legacy notification event types while keeping their v3 JSON shape unchanged.
No actionable issues were found. No tests were run during this review.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Legacy TypeSpec models] --> B[Event-specific v1 contracts] B --> C[JSON Schemas] B --> D[v3 API and client models] C --> E[Generated registry definitions] E --> F[Fingerprint check] G[Legacy payload fixtures] --> H[v3 payload conversion] H --> I[Contract validation test] C --> IReviews (4) · Last reviewed commit: "feat(notification): define the legacy Ev..." · Reviewed by Greptile