awesome-everything RU
↑ Back to the climb

APIs

OpenAPI: make the contract load-bearing

Crux Hands-on project — make an OpenAPI spec the enforced source of truth for a small API: generate a client, validate at the edge, and gate breaking changes in CI.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 220 min

Reading about contract drift is not the same as building the pipeline that makes it impossible. Take a small API, make its OpenAPI spec the enforced source of truth, then try to merge a breaking change and watch the build stop you — with evidence at every step.

Goal

Turn the unit’s model into a working pipeline: an OpenAPI 3.1 spec that generates a typed client, validates requests at the edge, and fails CI on a breaking-change diff — so the contract cannot drift or break silently.

Project
0 of 7
Objective

Take a small HTTP API (your own or a 3-endpoint orders service) and make its OpenAPI 3.1 spec the enforced source of truth: codegen a typed client, validate requests at the edge, and gate breaking changes in CI — then prove a breaking change is blocked before merge.

Requirements
Acceptance criteria
  • A before/after CI log: the breaking PR fails with oasdiff naming the specific breaking rule (e.g. api-required-request-property-added), and the compatible PR passes.
  • The generated client compiles with precise types — no any/unknown for fields the spec defines — proving the schemas are tight enough for honest codegen.
  • A malformed request to the validated endpoint returns a 400 naming the offending field, captured as a real response, not described.
  • A one-paragraph write-up: spec-first vs code-first choice and why, and which enforcement layers (codegen, edge validation, diff gate) defend against which failure mode.
Senior stretch
  • Add a mock server generated from the spec's examples and show a consumer integrating against it before the backend handler exists.
  • Extend the oasdiff gate to post the changed-endpoints summary as a PR comment, so reviewers see the contract delta inline.
  • Migrate one schema's nullability from 3.0 to 3.1 (nullable: true to type array) and show the diff classifies it correctly; confirm your generator supports 3.1.
  • Add contract tests that run the generated client against the real server in CI, catching drift the static spec diff cannot (e.g. a handler that ignores a documented field).
Recap

This is the pipeline you build for any API that more than one team consumes: a tight OpenAPI 3.1 spec as the source of truth, a generated client that kills hand-rolled-request bugs, edge validation that rejects malformed input precisely, and a CI breaking-change diff that fails the PR before any client breaks. Doing it once on a three-endpoint service makes the production version — where the Friday deploy never reaches mobile clients you cannot force-update — a pattern you already own.

Continue the climb ↑gRPC and Protobuf: the binary contract and what it costs you
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.