Prompt
How do I create docs for an API that changes often?
Latest observation
For an API that changes often, the best docs are the ones that are easy to update, automatically generated where possible, and tightly tied to the source of truth.
Good approach
1. Make the API spec the source of truth
Use a machine-readable spec like:
- OpenAPI / Swagger for REST APIs
- GraphQL schema for GraphQL APIs
- AsyncAPI for event-driven APIs
This lets you generate docs, SDKs, examples, and validators from the same definition.
2. Automate documentation generation
Avoid hand-written docs for endpoints, schemas, and parameters if they change frequently.
Automate:
- endpoint reference docs
- request/response examples
- schema definitions
- auth requirements
- error codes
Tools:
- Swagger UI / Redoc for OpenAPI
- Stoplight
- Postman documentation
- Docusaurus or MkDocs with generated API sections
3. Keep narrative docs separate from reference docs
Split docs into:
- Reference docs: generated from spec, highly accurate, detailed
- Guides/tutorials: human-written, stable, explain workflows and use cases
This reduces maintenance because only the reference part changes often.
4. Version your API and docs
If the API changes often, assume breaking changes will happen.
Use:
/v1,/v2in routes or headers- separate docs per version
- changelogs and migration guides
Include:
- what changed
- whether it’s breaking
- how to migrate
5. Put docs in the same repo as the API
This makes it easier to update docs in the same pull request as code changes.
Best practice:
- changes to endpoints require docs updates in the same PR
- CI checks fail if spec/docs are out of sync
6. Add examples and tests
Docs stay useful when they’re validated.
Use:
- example requests/responses from real tests
- contract tests to ensure docs match behavior
- automated linting for specs
7. Document change frequency clearly
For fast-moving APIs, tell users:
- what is stable
- what is beta/experimental
- deprecation policy
- support window for old versions
Practical setup example
A common workflow:
- Define API in OpenAPI
- Generate docs with Redoc or Swagger UI
- Store spec in the API repo
- Add CI checks for:
- spec linting
- breaking change detection
- example validation
- Publish versioned docs automatically on release
What to avoid
- Long manually maintained endpoint pages
- Docs in a separate repo with no automation
- Unversioned APIs with no changelog
- Examples that aren’t tested
Recommended structure
A strong docs site usually has:
- Overview
- Quickstart
- Authentication
- Core concepts
- API reference auto-generated
- Examples / tutorials
- Errors
- Changelog
- Deprecation policy
If you want, I can also suggest a specific docs stack for your API type, like REST, GraphQL, or internal microservices.