ADR-0148 — The contract is a package the web client compiles against
Status: Accepted · Date: 2026-08-31 · Supersedes: —
Context
shared/contracts/openapi.yaml has been a document nobody executes. The
standing repair on ROADMAP has always been to promote it to a generated-types
package the web client consumes, so API drift is a compile error rather than a
CI finding (ADR-0030 rule 1) — and the promotion was deliberately not started,
because nothing honest can be generated from a document that is not true. Five
slices earned the right to run a generator:
- names, types and nullability measured against the Go struct that serves each property, then drained to zero (ADR-0143, ADR-0144);
- operations and their parameters measured against the router that answers them (ADR-0145, ADR-0146);
- and which properties are always sent (ADR-0147).
What the web client had instead is a third statement of the same facts:
apps/web/src/types/api.ts, 1,003 hand-written lines, agreeing with the server
by whoever last remembered to edit it. It was not badly out of date — the six
resources were mostly right — which is exactly the failure mode: a hand-written
mirror is wrong rarely enough that nobody checks it, and the places it is wrong
are the places a track added a column.
Decision
packages/api-types is generated from the contract, and apps/web re-exports
it rather than declaring the same shapes.
scripts/gen-api-types.mjs writes packages/api-types/src/schemas.ts from the
document: the six schemas a Go struct serves whole, plus the enums they
reference. required decides optionality (ADR-0147), nullable decides | null, an inline enum becomes a union of literals — so lifecycle_state
arrives as its four states rather than as string — and each property carries
the document's own description as its doc comment.
The generator is its own checker. --check compares the committed file
against what today's contract produces and fails on any difference; the default
writes it. A checker written separately from a generator would be a third
statement of the same fact, which is the defect this repair is about.
One reader of the document. scripts/lib/openapi-schemas.mjs is extracted
from check-contract-parity.mjs and both consumers call it, for the same
reason: a repair whose subject is duplicated statements disagreeing does not get
to ship two parsers that could disagree about what the contract says.
What is generated is response shapes, and only the schemas a struct serves
whole. The envelope — APIResponse, Error, PaginationMeta — is flattened
in the document for readers rather than serialised field-for-field by one
struct, and apps/web keeps its own. Request bodies and operations are measured
but not generated: that is a client generator, and a larger decision than this
repair. Response shapes are what drift silently.
The remaining ~50 hand-written interfaces stay hand-written, and are now visibly the residue: each is a shape no single struct serves, or one the contract does not describe yet. Adding one to the document is a slice of its own, not a thing to do while passing.
Consequences
The chain closes. A struct field renamed fails check:contract-parity;
correcting the contract changes what the generator writes; the committed types
then fail check:api-types until regenerated; and the regenerated types fail
tsc at every call site that read the old name. Proved by removing
Link.clicks from the contract: C2 fires, and npm run web:build then reports
the property missing on five pages.
Two hand-written claims were already wrong, and the compile found them.
Plan.monthly_price and its two siblings are *float64 tagged omitempty, so
a rung not sold at that frequency is absent, not null; the hand-written type
said number | null and PlansPage's getPrice was declared to return
something the server may never send. It now coalesces, which is ADR-0138's
finding restated: an omitted price and a null price say the same thing. Two
BiolinkBlock fixtures were built without the workspace_id the server has
sent since 006.
apps/web/src/types/api.ts loses 155 lines and gains a header saying what
is generated and where. No served byte moves, and no runtime code changed except
the price coalesce.
Watched failing four ways: the contract moved and the types did not; the generated file edited by hand; an enum the generator emits removed from the document; and a property declared as a type the generator has no TypeScript for — the last two loudly, because a generator that quietly emits less than it was asked for is how a mirror goes stale in the first place.
Source: docs/decisions/0148-the-contract-is-a-package-the-web-client-compiles-against.md