Schema-first API development: agree on and govern the contract before coding
Schema-first development writes and reviews a machine-readable description such as OpenAPI before implementing the API. Consumers and providers can discuss paths, data shapes, statuses, and behavior before coding, then use the agreed description for docs, mocks, generated code, and validation tools. A specification does not make implementation match automatically: choose one source of truth and check for runtime drift in CI.
Schema-first development writes and reviews a machine-readable description such as OpenAPI before implementing the API. Consumers and providers can discuss paths, data shapes, statuses, and behavior before coding, then use the agreed description for docs, mocks, generated code, and validation tools. A specification does not make implementation match automatically: choose one source of truth and check for runtime drift in CI.
How it differs from code-first
Code-first implements the API first, then writes or generates its description from comments, annotations, or tooling. Schema-first/design-first agrees on the description first and implements against it. The OpenAPI Initiative notes that the description can provide an implementation skeleton and enable boilerplate generation, but OpenAPI cannot describe every possible HTTP API. Check those expressive limits early instead of forcing an incomplete description to fit later.
Either approach can work. The important choice is which artifact is authoritative. OAI recommends one source of truth, source control, and CI checks; do not treat both annotations and a separately edited YAML file as authoritative.
A practical workflow
Define consumers and use cases: agree on operations, data, responses, and errors clients need.
Write an OpenAPI description: document paths, operations, parameters, request/response schemas, statuses, security, and examples; pin the specification version and formatting rules.
Review and validate: use team review for meaning and compatibility, a validator for syntax/specification rules, and a linter for team conventions. These tools cannot identify every design omission.
Generate optional assets: docs, mocks, SDKs, or server skeletons can be generated; review generated code and behavior.
Check implementation alignment: add provider or contract verification to CI. Schema validation alone does not prove live responses match.
Govern changes: review consumer impact, compatibility, version/deprecation policy, and record verification results.
Keep one source of truth
Treat the OpenAPI description as a source file in version control, not just rendered documentation. Choose whether the source is YAML/JSON or code annotations. If code annotations generate a description, avoid independently editing both; make generation and consistency checks reproducible in CI.
Validation checks structure and specification rules; linting can add team conventions. OpenAPI Generator's validate command is one specification validator. Passing it does not prove good design, consumer usability, runtime conformance, performance, or security. Use reviews and tests for those questions.
When it helps and where to be careful
Schema-first is useful when consumer and provider teams work in parallel, external consumers need an early agreement, or mocks/SDKs should be available before implementation. Code-first may be simpler for a small team iterating quickly and generating descriptions automatically.
OpenAPI describes HTTP APIs but cannot express every possible behavior. If an important requirement is outside its model, make the gap explicit through supported extensions or separate documentation/tests. Review trust boundaries when tools automatically fetch external $ref documents.
Checklist
Does the team know the authoritative file and specification version?
Are consumer use cases, error responses, and statuses described?
Are generated docs, code, and mocks reproducible from the source?
Do validation, linting, and provider checks answer separate questions?
Does CI detect drift between the description and implementation?
Are review and compatibility steps defined for changes?
Are behaviors outside the specification handled explicitly?
Sources
[OpenAPI Initiative: design-first and single source of truth](https://learn.openapis.org/best-practices.html)
[OpenAPI Initiative: getting started and automation uses](https://learn.openapis.org/)
[OpenAPI Specification 3.2.1](https://spec.openapis.org/oas/latest.html)
[OpenAPI Generator: validation and code generation](https://openapi-generator.tech/docs/usage/)