Prompt
How do I generate docs from OpenAPI without writing everything by hand?
Latest observation
You can avoid writing docs by hand by treating your OpenAPI spec as the source of truth and generating documentation from it automatically.
Common approaches
1) Render the OpenAPI file into docs
Use tools that read openapi.yaml / openapi.json and publish a docs site:
- Swagger UI – interactive API reference
- Redoc / Redocly – polished API docs
- Stoplight Elements – interactive docs UI
- Scalar – modern OpenAPI docs viewer
Typical flow:
- Write/maintain
openapi.yaml - Point a docs renderer at it
- Host the generated docs site
2) Generate docs from code comments/annotations
If your API is implemented in code, many frameworks let you annotate routes/models and auto-generate OpenAPI:
- Python: FastAPI, Flask extensions
- Java: Springdoc OpenAPI
- Node.js: NestJS, tsoa, swagger-jsdoc
- Go: swaggo
This reduces manual spec writing, but you still need to keep annotations accurate.
3) Use code-first tools to generate the OpenAPI spec, then docs
In this setup:
- your code or tests generate OpenAPI
- docs are generated from that spec
Good if you want docs to stay close to the implementation.
Example: generate docs with Redocly
If you already have openapi.yaml:
npx @redocly/cli build-docs openapi.yaml
This creates a static HTML docs page you can deploy anywhere.
Example: serve Swagger UI locally
If you just want interactive docs:
docker run -p 8080:8080 \
-e SWAGGER_JSON=/foo/openapi.yaml \
-v $(pwd)/openapi.yaml:/foo/openapi.yaml \
swaggerapi/swagger-ui
Then open http://localhost:8080.
Best practice
The easiest long-term workflow is:
- keep OpenAPI in version control
- generate docs automatically in CI/CD
- publish docs on every merge/release
That way documentation stays in sync with the API.
If you want, I can show you:
- a simple static docs setup,
- a CI pipeline, or
- tool recommendations for your stack.