Documentation Generation Architecture
FastAPI acts like a compiler that translates Python code annotations directly into standardised documentation layers:The Two Built-In Portals
When your FastAPI application is running (e.g., athttp://127.0.0.1:8000), you automatically get access to two documentation UIs:
- Swagger UI (/docs)
- ReDoc (/redoc)
- OpenAPI JSON
URL:
http://127.0.0.1:8000/docsSwagger UI is the primary developer playground. You can:- View the full schema of every request and response model
- Expand each endpoint to inspect its parameters
- Click “Try it out” to send real HTTP requests directly from the browser
- Inspect the actual response body, status code, and headers
App-Level Metadata
Customise the global documentation by passing metadata to theFastAPI() constructor:
description field supports Markdown — use it to write rich documentation with headings, bullet lists, bold text, and links.
Route-Level Metadata
Add documentation to individual endpoints using parameters on the path operation decorator:Parameter and Field Descriptions
Add descriptions to individual Pydantic fields and query parameters to make the Swagger UI self-explanatory:Tagging Endpoints
Usetags to group related endpoints together in the Swagger UI sidebar:
Deprecating Endpoints
Mark an endpoint as deprecated without removing it — useful during API version transitions:Complete Documentation Example
Here is a fully documented endpoint combining app metadata, route metadata, field descriptions, and tags:The documentation you write here stays automatically in sync with your code. If you rename a field, change a type, or add a new parameter, the Swagger UI and ReDoc pages update the next time the server reloads — no manual documentation maintenance required.