Metadata for API
You can configure metadata when creating yourFastAPI 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 This appears as the main heading in the documentation.
"FastAPI".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 nameurl: Contact URLemail: 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 documentationdescription: Description of external docsurl: 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 theopenapi_tags list determines the order shown in the automatic documentation (Swagger UI):
OpenAPI URL
By default, the OpenAPI schema is served at/openapi.json. You can customize this:
/api/v1/openapi.json.
Disable OpenAPI Schema
To disable the OpenAPI schema entirely: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:OAuth2 Redirect URL
Swagger UI can use OAuth2 authentication. The redirect URL is at/docs/oauth2-redirect by default:
Custom OpenAPI
You can customize the generated OpenAPI schema by overriding theopenapi() 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.