Skip to content
Toolkit

ADR-0147 — Every property is optional until the document says otherwise

Status: Accepted · Date: 2026-08-31 · Supersedes: —

Context

The standing repair is to promote shared/contracts 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). Both halves of the measurement that blocked it are now clean: every property of the six gated schemas agrees with the struct that serves it in name, type and nullability (ADR-0143, ADR-0144), and every operation agrees with the router in path, method, credential and parameter (ADR-0145, ADR-0146).

Generating from it now finds one more thing missing, and it is missing everywhere rather than anywhere: not one schema in the document declares required. Under OpenAPI that is not an omission a generator can work around — absent from required means optional — so the six schemas would generate as six objects of entirely optional properties:

interface Link { id?: number; url?: string; clicks?: number /* … */ }

Every read of link.id would then need a null check for a field the server has sent on every response since the port. A consumer handed that type does one of two things, and both are worse than the hand-written interface it replaced: it writes link.id! at each site, which is the type system turned off one character at a time, or it writes real branches for absences that cannot occur.

This is ADR-0144's finding one property short of the property. There, a name that agreed and a type that did not made a plausible and wrong document. Here every name, type and nullability agrees and the document is still not generatable — not because any one property is wrong, but because a fact about all of them was never written down.

Decision

check:contract-parity gains rule C6: the document says which properties are always sent, and omitempty alone decides it.

A field without omitempty is emitted by encoding/json on every response, so its property is listed in the schema's required. A field with omitempty is absent when its value is empty, so its property is not. The rule runs both ways — a missing entry and a surplus one each fail — and a required entry naming a property the schema does not declare fails as a third.

A null is a value, not an absence. models.Link.UpdatedAt is a *time.Time tagged json:"updated_at" with no omitempty: it marshals to null, and null is sent. So it is both required and nullable: true, which C5 and C6 assert independently and about different things — C5 about the value the caller may receive, C6 about whether the key is there at all. A generator reading both writes updated_at: string | null and asks for no optional chaining.

No ledger escape, for C4 and C5's reason. A name can disagree with the wire for a reason — the wire is frozen outside /api/v2/ and a rename must wait — but the presence of a field is not a matter of opinion, and there is no honest reason to describe a field the server always sends as one it might not.

The six required lists land in this commit, 71 properties of 117. They move no served byte: omitempty is unchanged in every struct, and the document is being made to say what the server already did.

Consequences

The contract is generatable. The package this repair exists to build can now be written from the document alone, and the types it emits will distinguish the field a caller must handle from the one it may assume. That is the whole reason the promotion was gated on measurement rather than started with a generator.

omitempty becomes a wire-visible decision. Adding or removing one is now a contract change that fails the build until the document follows, which is the correct direction: it changes what a caller receives.

Watched failing four ways: a required entry dropped for a field that carries no omitempty (Link.clicks); an omitempty field listed required (Link.archive_url, which is absent for every resource still holding its own name); a required entry naming a property no schema declares; and the struct side of the same rule — models.Plan.Color losing its omitempty, which the document then under-promises.

Source: docs/decisions/0147-every-property-is-optional-until-the-document-says-otherwise.md

Library