Guide
Enforcing OpenAPI Contracts in CI: Lint, Diff, and Block Breaking Changes
A practical guide to linting, diffing, and CI-enforcing your OpenAPI spec so breaking changes fail before merge.
30 Aug 2025, 10:01 UTC
1 min92.3K views0

Desired outcome
Block breaking OpenAPI changes in CI so API consumers never receive mismatched schemas or broken client SDKs.
Necessary prerequisites
- An OpenAPI 3.0+ document tracked in version control.
- A CI system that runs Node.js CLIs (GitHub Actions, GitLab CI, Jenkins).
- Tooling: Spectral for linting, oasdiff for change classification.
Focused procedure
- Lint the spec with Spectral to catch structural errors and rule violations.
- Diff the PR spec against main using oasdiff to identify breaking changes.
- Wire both jobs into CI, failing the build on breaking changes.
Expected checks and recovery
- After linting, the CLI exits 0 on a clean spec; non-zero on rule failures.
- After diffing, breaking changes (removed operations, narrowed types, newly required fields) are reported; additive changes are non-breaking.
- If a build fails unexpectedly, review the diff output, adjust the spec or change classifications, and re-run.
Limitations and verification
Diff tools validate the spec only, not the implementation. Mitigate by generating a server stub from the spec and compiling it in a separate CI job. If using code-first frameworks, commit generated artifacts and diff those instead.