Prompt
How do I keep API docs in sync with changing endpoints?
Latest observation
Keeping API docs in sync is mostly a process problem, not a writing problem. The best approach is to make docs part of the codebase and the release workflow so they change with the API.
Good practices
1. Use a single source of truth
Define the API in one place and generate docs from it when possible:
- OpenAPI / Swagger for REST APIs
- GraphQL schema for GraphQL
- gRPC proto files for gRPC
This reduces manual drift because docs are derived from the contract.
2. Keep docs close to code
Store docs in the same repo as the API implementation:
- same PRs
- same review process
- same release versioning
If endpoints change, docs should be updated in the same commit or pull request.
3. Automate documentation generation
Use tools to generate docs from code annotations or schemas:
- OpenAPI generators
- Swagger UI / Redoc
- typed route libraries with schema extraction
- doc generation from annotations/comments
Automation helps prevent forgotten updates.
4. Add CI checks
Fail builds if docs are stale or invalid:
- validate the OpenAPI spec
- compare generated docs against committed docs
- check that example requests/responses match schemas
- lint for missing descriptions or deprecated fields
This makes docs drift visible immediately.
5. Version your API and docs
When breaking changes happen:
- version endpoints or the whole API
- publish matching doc versions
- clearly mark deprecated endpoints and fields
This avoids confusion between old and new behavior.
6. Update docs in the same workflow as code changes
Make doc updates part of your definition of done:
- endpoint change
- schema update
- example update
- changelog/release notes update
A PR checklist can help enforce this.
7. Use contract tests
Run tests that verify the implementation matches the published contract:
- request/response shapes
- status codes
- required fields
- auth behavior
These catch cases where code changed but docs didn’t, or vice versa.
8. Track examples separately but validate them
Examples are often the first thing to go stale. If you include them:
- generate them from live/test fixtures when possible
- validate them in CI
- keep them small and representative
9. Deprecate explicitly
When endpoints change:
- mark old endpoints as deprecated in docs
- include removal dates or migration guidance
- document replacements clearly
That reduces surprises for consumers.
Practical setup that works well
A common robust setup is:
- Define API with OpenAPI/GraphQL/proto
- Generate docs/site from the spec
- Run spec validation in CI
- Require doc changes in the same PR as endpoint changes
- Version releases and publish changelogs
- Add contract tests against implementation
If you want the simplest rule
Never edit endpoint behavior without updating the API contract and regenerating docs in the same PR.
If you want, I can also suggest a workflow for your specific stack, like FastAPI, Express, Spring Boot, Django, or GraphQL.