Skip to main content
FastAPI automatically generates OpenAPI documentation for your API. You can customize the metadata that appears in the generated docs.

Metadata for API

You can configure metadata when creating your FastAPI application:
All metadata parameters are optional. You only need to include the ones you want to customize.

Metadata Parameters

1

title

The title of your API. Defaults to "FastAPI".
This appears as the main heading in the documentation.
2

summary

A short summary of the API. Added in OpenAPI 3.1.0.
3

description

A longer description of the API. Supports Markdown (CommonMark syntax).
The description can be multiline and include Markdown formatting.
4

version

The version of your API (not the OpenAPI version or FastAPI version).
5

terms_of_service

URL to your terms of service.
6

contact

Contact information for the API. A dictionary with:
  • name: Contact name
  • url: Contact URL
  • email: Contact email
7

license_info

License information for the API. A dictionary with:
  • name: License name (required)
  • identifier: SPDX license identifier (optional)
  • url: License URL (optional)

Metadata for Tags

You can add metadata for the tags used to group path operations:

Tag Metadata Structure

Each tag metadata dictionary can contain:
  • name: Tag name (must match the tag used in path operations)
  • description: Short description (supports Markdown)
  • externalDocs: External documentation
    • description: Description of external docs
    • url: URL to external documentation
You don’t have to add metadata for all tags. Tags without metadata will still work, they just won’t have additional descriptions.

Tag Ordering

The order of tags in the openapi_tags list determines the order shown in the automatic documentation (Swagger UI):
Tags will appear in the docs in this order: users, items, admin.

OpenAPI URL

By default, the OpenAPI schema is served at /openapi.json. You can customize this:
Now the OpenAPI schema will be available at /api/v1/openapi.json.

Disable OpenAPI Schema

To disable the OpenAPI schema entirely:
If you set openapi_url=None, the automatic documentation UIs (/docs and /redoc) will also be disabled since they depend on the OpenAPI schema.

Docs URLs

FastAPI provides two documentation UIs by default:
  • Swagger UI: at /docs
  • ReDoc: at /redoc

Customize Docs URLs

Disable Documentation UIs

To disable one or both:
In production, you might want to disable the documentation UIs for security reasons, or restrict access to them using dependencies.

OAuth2 Redirect URL

Swagger UI can use OAuth2 authentication. The redirect URL is at /docs/oauth2-redirect by default:
To disable it:

Custom OpenAPI

You can customize the generated OpenAPI schema by overriding the openapi() method:
The OpenAPI schema is cached in app.openapi_schema. It’s generated the first time it’s requested, then returned from cache on subsequent requests.

Servers Metadata

You can specify server URLs in the OpenAPI schema:
This allows users of Swagger UI to switch between different server environments.

Complete Example