Skip to content

The OpenAPI lockfile and the wire contract are the compatibility authority

Accepted.

2026-05-27 (the date the lockfile was first committed; the enforcement steps were added over the following weeks).

The HTTP API has many consumers that the platform team does not release together:

  • the console, whose TypeScript client is generated from the API description;
  • the SDKs (Go, TypeScript, PHP, Java and others), several of them generated or hand-written against the same shapes;
  • every webhook subscriber, which depends on the delivery envelope and signature;
  • applications running in other organisations’ environments, upgraded on their own schedule.

Small changes that look harmless are breaking for those consumers: renaming a JSON field, changing an enum’s string value, turning a nullable field into a required one, returning a body where the contract says 204 No Content, changing 422 to 400, changing a pagination shape, or renaming an operationId (generated clients use operationId as a method name, so a rename renames a method and breaks the build).

A convention that says “do not do that” is not enough. Handlers are generated from typed Go code, so a change to a struct tag in a refactor changes the API with no one meaning to.

Make the compatibility surface a committed artefact that CI compares against the live code, and make the written rules the standing authority over style preferences.

  1. api/openapi.lock.json is the OpenAPI document generated from the registered routes, committed to the repository. make api-diff regenerates the document and fails if it differs from the lockfile; it is part of make ci. An intentional change is recorded with make api-bump, which puts the diff in code review where a reviewer sees it as a change to the contract.
  2. Each operation carries its SDK class in the lockfile (x-sdk: app | admin, absent for internal routes). The application-facing surface is exactly the x-sdk: app operations. Routes that the server mounts as plain handlers (batch ingest, the OAuth endpoints) are described by spec-only stubs so they are in the lock too.
  3. Downstream generation reads the lockfile: the console’s TypeScript client is regenerated and diffed (make frontend-types-verify), and the SDK generators take their input from the same file. Regenerating must not produce a diff unless the contract deliberately changed.
  4. docs/wire-contract.md lists what counts as a breaking change and fixes the details the OpenAPI document cannot express: RFC 3339 timestamps with six-digit microseconds, the {error, message} error envelope and the status mapping (no 422), pagination postures per endpoint, screaming-snake-case enums with lenient parsing, and the null-versus-missing posture per field.
  5. The code convention backs it up: if a Go-idiomatic change would alter a response shape, an OpenAPI definition, a JSON field name or a stored row layout, do not make it. API redesign is a separate, versioned effort, and an exception needs sign-off from the owner of the affected consumer.

The routes that are served by plain handlers and absent from the lock (login, session, discovery) are listed by hand in the wire-contract page, so their absence is deliberate rather than accidental.

Good

  • A contract change is visible as a diff to one file, in the pull request that causes it.
  • Generated clients cannot drift from the server without CI saying so.
  • Contributors can refactor internals freely, because the lock is the test.
  • New SDKs and the conformance material have one description to start from.

Bad

  • Cleaning up an awkward name or shape is expensive. Examples that remain on purpose: a $schema field on every response that no client needs, and some inconsistent pagination postures between endpoints.
  • The lockfile records shape, not behaviour. Rules such as ordering, idempotency or permission checks need their own tests and are written into the wire-contract page.
  • Routes outside the lock (the chi-mounted auth and session endpoints) rely on documentation and tests instead of the diff.
  • Semantic versioning of the API with a deprecation window. Still possible for a deliberate change, but it does not catch the accidental one, which is the common failure.
  • Contract tests only (record and replay). Useful alongside, but replay tests cover chosen requests, while the lock covers every operation.
  • Write the OpenAPI document by hand and generate server stubs from it. Rejected because it loses the property that the documented API is the API that runs.