OpenAPI contract maintenance
Read AGENTS.md, app/src/plugins/swagger.ts, app/src/routes/schemas.ts, app/src/plugins/schema-registry.ts, and the affected route, schema, runtime plugin, and tests before changing the public API.
Trace the contract
Verify every changed behavior across the surfaces that own it:
- Route TypeBox schemas own validation, serialization, operation metadata, and response status declarations.
app/src/plugins/swagger.tsowns OpenAPI 3.1 transformation, shared response headers, error media types, and bearer security components.app/src/plugins/schema-registry.ts,app/src/routes/schemas.ts, and schema discovery own standalone Draft 2020-12 documents and responseLinkmetadata.- Runtime plugins and utilities own negotiation, RFC 9457 encoding, authentication, request IDs, pagination, and headers.
app/tests/integration/app.test.tsproves the composed public contract; focused unit tests prove lower-level transformations and failure paths.
Do not add a hand-maintained OpenAPI file or commit generated specifications.
Change checklist
- Keep summaries, descriptions, tags, paths, methods, parameters, constraints, and reachable statuses accurate.
- Keep every
operationIdstable and unique, preserve the relative/server, and register Swagger before route-producing plugins. - Reference reusable
$idschemas and keep component names stable unless breaking them is intentional. - Document Firebase bearer security only on protected operations.
- Keep route
schema.consumesandschema.producesaligned with runtime behavior. - Advertise errors as
application/problem+jsonandapplication/cbor, neverapplication/problem+cbor. - Keep
Link,Vary,X-Request-ID,Retry-After, and authentication headers aligned with runtime behavior. - Ensure every reference resolves, standalone schemas use local
$defs, and runtime errors matchErrorModelSchema. - Ensure response instances do not receive the JSON Schema
$schemakeyword. - Avoid unrelated schema churn.
Verification
Apply $adversarial-testing. Exercise the composed application with fastify.inject() and inspect /api-docs/json, affected operations and components, /schemas/<Name>.json when applicable, and representative runtime responses. Assert changed statuses, security, media types, schemas, and headers rather than snapshotting the entire generated document.
Run focused contract tests first, then just check and pnpm --dir app build.