8.9 API contract¶
ADR-0010 (docs/adr/adr-0010-api-gateway-and-api-contract.md).
- Code-first OpenAPI. springdoc-openapi derives the contract from the controllers; the
snapshot
api/openapi.yamlis committed, and./gradlew buildfails when it no longer matches. - Proof in the gate. MockMvc tests validate every request and response they make against the snapshot (swagger-request-validator-mockmvc, test scope); the controllers stay hand-written.
- One file, every consumer. The top-level
api/directory holds it; the web app's client is generated from it with Orval; laterapi/asyncapi.yaml(Springwolf, code-first) for the externalized events of the event backbone (8.16.3). - No version in the path. Changes are additive; Spring Framework 7's API versioning is used when a second consumer appears.
- No hand-shared Zod source. The contract is OpenAPI, code-first, and the snapshot is the one
source: Orval generates the web app's client from it, with Zod schemas switched on when a screen
needs them (ADR-0010 (
docs/adr/adr-0010-api-gateway-and-api-contract.md) §3 points 4, 6, 7; ADR-0003 open point 5 is annotated accordingly). - How the build proves it. The snapshot is compared with what the controllers describe, and a
difference fails the build with the name of the task that rewrites the file; the contract tests
run the validator in a class loader of its own, because it needs Jackson 2 beside the
application's Jackson 3. Every response a controller can give — each status, its
Locationheader, a required upload part — is part of the snapshot (spec 261 (docs/specs/261-openapi-contract.md)). - Lint and breaking changes. The build lints the snapshot with Spectral and fails on any warning
or error; a pull request that changes it is compared with main's by oasdiff, and a change that
breaks a client fails that check (#254, spec 261 (
docs/specs/261-openapi-contract.md) §4).