Skip to main content
One of FastAPI’s most loved features is its automatic, interactive API documentation. The moment your application starts, FastAPI reads your Python type hints, Pydantic schemas, and docstrings, generates a standard OpenAPI specification, and hosts two interactive web portals where clients — and you — can explore and test every endpoint live. No extra tooling, no manual YAML files, no separate documentation project to maintain. This lesson shows you how to get the most out of it.

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., at http://127.0.0.1:8000), you automatically get access to two documentation UIs:
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
Swagger UI is the fastest way to test your API during development — no Postman or curl required.

App-Level Metadata

Customise the global documentation by passing metadata to the FastAPI() constructor:
The 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:
You can also use a Python docstring on the function as the description — FastAPI reads it automatically:

Parameter and Field Descriptions

Add descriptions to individual Pydantic fields and query parameters to make the Swagger UI self-explanatory:
All descriptions are parsed and rendered directly in Swagger UI and ReDoc — keeping your documentation always in sync with your code.

Tagging Endpoints

Use tags to group related endpoints together in the Swagger UI sidebar:
You can also add tags directly on individual route decorators:

Deprecating Endpoints

Mark an endpoint as deprecated without removing it — useful during API version transitions:
Deprecated endpoints are shown with a strikethrough in Swagger UI and are clearly marked in ReDoc.

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.