
API Contract, Versioning, and Deprecation Policy
An undocumented integration is an outage waiting for a vendor change. Here is a contract and versioning discipline: OpenAPI, consumer contract tests, and a breaking-change policy.
TL;DR: An integration whose shape lives in someone's memory is an outage waiting for a vendor change. The discipline is one machine-readable contract per integration, consumer contract tests that fail in CI before they fail in production, an explicit additive-versus-breaking change policy, and a deprecation process that uses the Deprecation and Sunset headers and treats vendor changelog monitoring as a standing operational task. This article gives you that discipline and a breaking-change policy table you can adopt as-is.
Tribal knowledge is not a contract
An integration without a written contract is not actually defined — it is reconstructed. Someone got a call working once, the response shape that day became the de facto truth, and the only record of it is the code that parses it plus a Slack thread nobody can find. That is fine until the vendor renames a field, tightens a type, or changes what a status value means. Then the only thing that "catches" the change is a customer hitting the broken path in production.
The decision to have a contract at all is made upstream, when the integration is scoped — it is one of the spine decisions every integration in a build inherits, alongside one auth model and one error taxonomy. This is not the place to re-argue that the contract should exist. It is the place to be precise about what the contract artifact is, how you keep it honest as both sides evolve, and what policy decides whether a change is safe to absorb or has to be versioned. A contract you wrote down but never test against drifts as silently as no contract at all.
OpenAPI as the source of truth
The contract artifact should be a single machine-readable specification per integration, versioned in the repository next to the code that depends on it. The OpenAPI Specification — in its own words, "a standard, programming language-agnostic interface description for HTTP APIs" — is one option, but the point is not the format — it is that one document, in version control, is the thing both your code and your tests reason about, instead of a shape that exists only in the parser.
Two things follow from having that document. You generate clients and types from it rather than hand-writing them, so the compiler is the first line that notices a mismatch. And you validate responses against it at the integration boundary, so a response that no longer matches the contract is rejected with a clear error at the edge instead of corrupting state three layers in. For a vendor that publishes its own spec, pin a copy in your repository rather than fetching it live — you want the contract you tested against to be the contract you ship against, not whatever the vendor served this morning.
The contract also needs an owner, because a document nobody is responsible for rots faster than no document at all. The owner is whoever decides what the integration's shape and lifecycle are — the same role assigned during scoping when the integration gets a named owner and a runbook owner. Their job here is narrow and continuous: when the contract changes, the change goes through the document first and the code second, never the reverse. The failure mode to watch for is a generated client that has quietly drifted from the spec it was generated from, because someone patched the client by hand under deadline pressure. The moment hand-edits accumulate in generated code, the contract is no longer the source of truth — it is a second opinion, and the two will disagree at the worst time. Regenerating from the spec on every build, and failing the build if the regenerated output differs from what is committed, is the cheap mechanical guard that keeps the document authoritative rather than aspirational.
# checkout-vendor.openapi.yaml — pinned in the repo, versioned with the code
openapi: 3.2.0
info: { title: Checkout vendor API (pinned copy), version: '1' }
paths:
/v1/charges:
post:
operationId: createCharge
responses:
'200':
content:
application/json:
schema:
type: object
required: [id, status, amount]
properties:
id: { type: string }
status: { type: string, enum: [pending, succeeded, failed] }
amount: { type: integer }Contract testing
A contract you only read is a wish. A consumer contract test makes it enforceable from your side: your code declares the shape and the fields it actually depends on, and a test asserts that the contract still provides them. In the full consumer-driven contract pattern, those expectations are also communicated to the provider and asserted on the provider's side; when the provider is a vendor that does not take part, the consumer-side check is all you have. The test runs in continuous integration against the pinned specification, or a stub generated from it — never against the live vendor.
Testing against a live vendor in CI is a common mistake with three predictable costs: it is flaky because their availability is not yours, it is rate-limited because CI runs constantly, and it tests their uptime rather than your assumptions. The job of a contract test is to fail the moment your dependency on a field would break, so it fails in a pull request instead of at launch. The pattern matters more than any particular tool — "this response still has the fields I consume" is a plain assertion, shown below with Jest's expect matchers.
// Consumer contract test — runs in CI against the pinned spec,
// never against the live vendor.
test('createCharge still provides the fields we depend on', () => {
// stubFromSpec: a project helper that builds a sample response from the pinned spec
const res = stubFromSpec('checkout-vendor.openapi.yaml', 'createCharge')
expect(Object.keys(res)).toEqual(expect.arrayContaining(['id', 'status', 'amount']))
expect(['pending', 'succeeded', 'failed']).toContain(res.status)
})Versioning strategy
Versioning is two questions: where the version lives, and what counts as a change that needs one. Path versioning puts the version in the URL — it is visible, cache-friendly, and trivial to observe in logs, at the cost of coarse granularity and URL churn. Header or media-type versioning keeps URLs stable and lets you version more finely, at the cost of being harder to debug and harder to see in a trace. Neither is universally right; a public, cached, marketing-facing surface is a case for keeping the version visible, while an internal integration can tolerate the header.
What needs a version is the more consequential decision, and it does not require a treatise on semantic versioning. An additive change — a new optional response field, a new endpoint, a new optional request parameter — is non-breaking, provided your consumers are tolerant readers that ignore fields they do not recognize. Building every parser as a tolerant reader is a cheap defense against additive vendor change. A breaking change is anything a tolerant reader cannot absorb: a removed or renamed field, a type or format change, tightened validation that now rejects input it used to accept, or — the most dangerous — a semantic change where the shape is identical but the meaning is not. The semantic case is dangerous precisely because shape-based contract tests still pass.
A worked example makes the boundary concrete. A vendor adds a risk_score field to a charge response: additive, a tolerant reader never notices, no version needed. The same vendor changes amount from an integer in minor units to a decimal string: identical field name, identical position, and a silent hundred-fold error in every order total in a two-decimal currency such as USD or EUR if your parser was not watching the type. The shape diff is zero; the policy classification is breaking. This is why the classification is a deliberate decision recorded against a table rather than an inference from whether the JSON "looks the same" — the cases that hurt most are exactly the ones that look harmless. When you produce an internal API consumed by your own frontend or storefront, the same discipline applies inward: a field your team renames for clarity is a breaking change to every consumer that has not been updated yet, and "it is just a rename" can cause an incident at launch just as a vendor change can.
| Change | Classification | What it requires |
|---|---|---|
| New optional field in a response | Additive | Nothing — tolerant readers ignore unknown fields |
| New endpoint or new optional request parameter | Additive | Document it; no version bump |
| Field removed or renamed | Breaking | New version; migration window; deprecation notice |
| Field type or format changed | Breaking | New version; consumers updated before cutover |
| Validation tightened (input once accepted now rejected) | Breaking | New version; treat as breaking even if the schema "looks unchanged" |
| Semantic change (same shape, different meaning) | Breaking | New version; the most dangerous because shape-based tests still pass |
| Endpoint removed | Breaking | Sunset header with a date; window before removal |
Deprecation and vendor change
Deprecation cuts both ways, because in a build you are both a producer of internal APIs and a consumer of vendor ones. When you retire your own surface, signal it rather than just deleting it. The RFC 8594 Sunset HTTP header announces the point in time when a resource is expected to become unresponsive, information clients can use to control their usage of the resource. RFC 8594 says clients SHOULD treat that timestamp as a hint rather than a guarantee, though one with some credibility because the resource itself provides it. Pair it with the Deprecation header (RFC 9745), which signals when the resource was or will be deprecated (RFC 9745 requires the Sunset date to be no earlier than the Deprecation date), and a documented window long enough for every known consumer to migrate. A deprecation with no date and no window is just a future incident with extra steps.
The length of the window is a decision, not a default. It is bounded below by the slowest consumer you know about and a margin for the ones you do not — a public integration with unknown third-party consumers needs a longer window than an internal one with two known callers you can message directly. Announce the date when you announce the deprecation, not when you are ready to remove the resource, so consumers plan migration against a fixed point rather than a moving one. The Sunset header is the machine-readable half of that announcement; the human half is the changelog entry and, for known consumers, a direct notice. A deprecation that exists only in a changelog nobody is subscribed to is functionally a silent removal with a paper trail.
The mirror obligation, when you consume a vendor API, is monitoring their changelog as a standing operational task with a named owner. A vendor's breaking-change notice, however much lead time it gives, is worthless if nobody is reading it. Concretely, that means a subscribed changelog or status feed, requests pinned to an explicit API version where the vendor supports it, so changes the vendor ships as a new version reach you when you move the pin rather than unannounced, and a canary that exercises the contract on a schedule so a change announced badly — or not at all — surfaces on your timeline instead of a customer's. The canary is the safety net for the case the changelog process misses: vendors do ship undocumented changes, and a scheduled call that asserts the contract can catch one before a customer does. Treat "watch the vendor's changelog" as a real assignment in the runbook with a named owner and a cadence, not an assumption that someone will notice in time.
The contract discipline summary
The discipline reduces to a small set of artifacts and one policy. There is one machine-readable contract per integration, in version control. There is a consumer contract test that fails in CI when a dependency would break. There is the breaking-change policy table above, applied the same way every time so "is this safe to absorb?" is a lookup, not a debate. And there is a deprecation process — Deprecation and Sunset headers outward, changelog monitoring inward — with an owner.
One boundary is worth stating plainly. This discipline tells you a contract has been violated; it does not, by itself, tell you when one is being violated in production. Detecting a failing call in a live system before a customer reports it is a separate operational concern with its own depth elsewhere on this topic. The contract discipline stops at the boundary it owns: making the agreement explicit, testable, and versioned so violations can be caught before they reach production.
Diagnostic checklist for the next planning cycle
- Write or pin one machine-readable contract per integration into the repository
- Generate clients and types from the contract; validate responses at the boundary
- Add a consumer contract test that runs in CI against the pinned spec, not a live vendor
- Adopt the breaking-change policy table and apply its classification to every proposed change
- Make every consumer a tolerant reader so additive change costs nothing
- Add the Deprecation header to any resource you deprecate, and the Sunset header with a documented window once you set a point in time when it is expected to become unresponsive
- Assign an owner to vendor changelog monitoring and put it in the runbook