Prompt
How do I create versioned API docs for v1 and v2?
Latest observation
A common way to create versioned API docs is to expose separate documentation endpoints or sections for each API version, then keep the specs in sync with the corresponding code.
Good options
1) Separate OpenAPI specs per version
Create one OpenAPI document for v1 and another for v2:
/openapi/v1.json/openapi/v2.json
Then serve docs UI for each:
/docs/v1/docs/v2
This is the simplest and cleanest approach.
2) Version in the API path
If your API routes are versioned like:
/api/v1/users/api/v2/users
then your docs should match that structure and show only the endpoints for that version.
3) Tag or group by version
If you use a single docs UI, group endpoints by version:
v1 Usersv2 Users
This works, but it can get messy if the versions diverge a lot.
Recommended structure
For OpenAPI
Maintain two specs:
# openapi-v1.yaml
openapi: 3.0.3
info:
title: My API
version: 1.0.0
paths:
/api/v1/users:
get:
summary: List users
# openapi-v2.yaml
openapi: 3.0.3
info:
title: My API
version: 2.0.0
paths:
/api/v2/users:
get:
summary: List users
Best practices
- Keep
v1docs frozen except for critical corrections. - Add a deprecation notice to old versions.
- Document breaking changes in
v2. - Include changelogs or migration notes between versions.
- Make sure examples match the actual request/response shapes for each version.
If you use Swagger UI
You can configure Swagger UI with a version selector, or run two instances:
swagger-ui?url=/openapi/v1.jsonswagger-ui?url=/openapi/v2.json
If you want a single docs site
You can create a landing page like:
- API Docs
- v1 Documentation
- v2 Documentation
- Migration Guide
That’s often the nicest UX for developers.
If you tell me what stack you’re using (FastAPI, Express, NestJS, Spring, Django, etc.), I can show you the exact setup.