Skip to content

feat(notification): define the legacy Event types as v1 Event contracts - #5552

Merged
chrisgacsal merged 3 commits into
mainfrom
feat/OM-567-notification-legacy-v1-event-types
Nov 17, 2026
Merged

chrisgacsal merged 3 commits into
mainfrom
feat/OM-567-notification-legacy-v1-event-types

Conversation

@gergely-kurucz-konghq

@gergely-kurucz-konghq gergely-kurucz-konghq commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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):

    Legacy name v1 contract
    invoice.created v1.billing.invoice.created
    invoice.updated v1.billing.invoice.updated
    entitlements.balance.threshold v1.entitlement.balance_threshold.triggered
    entitlements.reset v1.entitlement.usage_period.reset
  • Payload: the data of the legacy payload in the shape the v3 API returns (the snake_case BillingNotificationEventV1* copies). Rule configuration: the type-specific fields of the v3 Rule. Invoice Rules have an empty one.

  • @typespec/json-schema is patched to honor @encodedName("application/json", …).

Why

  • Registering the legacy types lets the registry, Event type listing and validation treat them like any versioned type during the interim. The contracts match what the v3 API already serves.
  • Each Event type needs its own contract root, so the two invoice types get separate payload models that spread the invoice copy.
  • The patch: the JSON Schema emitter wrote declared property names, so the filter operators $eq, $gte, … came out as eq, gte. Because the schemas are sealed, they rejected real payloads. @typespec/openapi3 already uses the encoded name. Upstream main still has the issue.

How

  • api/spec/packages/aip/src/notifications/legacy-v1-event-types.tsp declares the payload roots and Rule configurations.
    • event.tsp points each legacy payload's data at its root.
    • rule.tsp spreads the Rule configurations into the v3 Rule models, so the Rule API is unchanged.
  • api/spec/patches/@[email protected] resolves the application/json name 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.
    • The fixture (testdata/legacy_payloads.json) had placeholder values that broke the v1 patterns, such as "key_1" for decimals, a hyphenated feature key and an extra available_actions key. It now has values the server can send.
  • openmeter/notification/README.md links the legacy types to their contracts.

Jira: OM-567

Notes for reviewer

  • Stacked on the api/v3/models codegen PR.

  • v3 API: the JSON is unchanged, but some component names change:

    • BillingNotificationEventV1Invoice becomes BillingInvoiceCreatedV1Payload and BillingInvoiceUpdatedV1Payload;
    • the entitlement data models become EntitlementBalanceThresholdTriggeredV1Payload and EntitlementUsagePeriodResetV1Payload.

    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 apiv3models types, 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

  • New Features
    • Added versioned notification event definitions for invoice creation and updates, entitlement balance-threshold triggers, and usage-period resets.
    • Added event-specific payload formats and rule settings, including threshold selection and optional feature targeting. When no features are specified, entitlement rules apply to all features.
    • Added validation schemas for these event payloads and rule settings.
  • Improvements
    • Updated JavaScript and Go client models with event-specific payload types.
    • Clarified how notification payloads and rule settings correspond to their event types.

RetriggerView in GreptileConfidence 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.

  • Four legacy notification Events now have their own versioned contracts.
  • Generated JSON Schemas now use the encoded names found in JSON.

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 --> I
Loading

Reviews (4) · Last reviewed commit: "feat(notification): define the legacy Ev..." · Reviewed by Greptile

@CLAassistant

CLAassistant commented Nov 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@gergely-kurucz-konghq gergely-kurucz-konghq changed the title feat/OM 567 notification legacy v1 event types feat(notification): define the legacy Event types as v1 Event contracts Nov 16, 2026
@gergely-kurucz-konghq gergely-kurucz-konghq added the release-note/feature Release note: Exciting New Features label Nov 16, 2026
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The pull request defines versioned contracts for four legacy notification events. It generates corresponding schemas and client models, registers the event definitions, and adds a test that validates converted legacy payloads against those contracts.

Changes: Legacy notification event contracts

Layer / File(s) Summary
Define event payloads and rule configurations
api/spec/packages/aip/src/notifications/*, api/spec/packages/typespec-notification-events/*, api/spec/pnpm-workspace.yaml
TypeSpec adds event-specific payload and rule-configuration models for four notification events. Existing rule models use the new configurations. The emitter comment and expected test output drop a package qualifier, and the workspace maps a patched JSON Schema dependency.
Generate client and API contracts
api/spec/packages/aip-client-javascript/src/*, api/v3/client/models_notifications.go, api/v3/models/*, api/v3/api.gen.go
Generated JavaScript and Go models use separate invoice-created and invoice-updated payload types, plus event-specific entitlement payload types. The generated clients expose the new types and schemas. The embedded OpenAPI specification is replaced; its individual schema and endpoint differences are not readable from the encoded data.
Register event definitions
openmeter/notification/v4/definitions/*
Adds payload and rule-configuration schemas for the four events. All() now returns their definitions, and the registration test checks that the collection is non-empty.
Validate converted legacy payloads
api/v3/handlers/notification/events/convert_test.go, api/v3/handlers/notification/events/testdata/legacy_payloads.json, openmeter/notification/README.md
A test converts legacy fixtures and validates each payload’s data against its corresponding v1 contract. Fixture values are updated, and the README documents the relationship between legacy payloads, event contracts, rule configurations, and validation steps.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Definitions as v4 event definitions
  participant Converter as v3 event converter
  participant ContractTest as conversion contract test
  participant Fixtures as legacy payload fixtures
  ContractTest->>Definitions: Load event definitions
  ContractTest->>Fixtures: Decode legacy event fixtures
  ContractTest->>Converter: Convert fixture events
  Converter->>ContractTest: Return converted payloads
  ContractTest->>Definitions: Validate payload data against schemas
Loading

Possibly related PRs

  • openmeterio/openmeter#5499: Updates v3 notification Event endpoints to return full legacy payloads. Its payload mappings and schemas must align with the contracts defined here.

Suggested reviewers: chrisgacsal, borosr

Merge Risk: Minimal · up to f7979

This PR adds v1 contracts for four legacy notification event types and generates the matching schemas and models. No concrete merge-blocking risk was identified in the supplied evidence.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat(notification): define the legacy Event types as v1 Event contracts" matches the main change. The PR adds TypeSpec and generated v1 contracts for four legacy notification event types (i…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(notification): define the legacy Event types as v1 Event contracts" matches the main change. The PR adds TypeSpec and generated v1 contracts for four legacy notification event types (invoice created/updated, entitlement balance threshold, and entitlement usage-period reset), and the generated Go, JavaScript, and JSON Schema artifacts follow from them. The title is specific and concise. It does not mention the patch to @typespec/json-schema, which is a supporting change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e65cda6 and f797991.

Files ignored due to path filters: 4

  • api/spec/patches/@[email protected] is excluded by !api/spec/patches/**
  • api/spec/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
  • openmeter/notification/v4/definitions/definitions.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing: 1

  • api/v3/api.gen.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@chrisgacsal
chrisgacsal force-pushed the feat/OM-567-notification-legacy-v1-event-types branch from fc7ca33 to 4ea8124 Compare November 17, 2026 09:44
@gergely-kurucz-konghq
gergely-kurucz-konghq force-pushed the feat/OM-567-notification-legacy-v1-event-types branch from 4ea8124 to e65cda6 Compare November 17, 2026 10:02
Base automatically changed from refactor/OM-567-notification-event-types-in-v3-models to main November 17, 2026 10:43
@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.
@chrisgacsal
chrisgacsal force-pushed the feat/OM-567-notification-legacy-v1-event-types branch from e65cda6 to f797991 Compare November 17, 2026 10:43
@chrisgacsal
chrisgacsal enabled stacked auto-merge (squash) November 17, 2026 10:43
@chrisgacsal
chrisgacsal merged commit 2c6a8a4 into main Nov 17, 2026
37 checks passed
@chrisgacsal
chrisgacsal deleted the feat/OM-567-notification-legacy-v1-event-types branch November 17, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants