OpenAPI docs¶
Utilities to handle OpenAPI automatic UI documentation, including Swagger UI (by default at /docs) and ReDoc (by default at /redoc).
fastapi.openapi.docs.get_swagger_ui_html
¶
get_swagger_ui_html(
*,
openapi_url,
title,
swagger_js_url="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js",
swagger_css_url="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.css",
swagger_favicon_url="https://fastapi.tiangolo.com/img/favicon.png",
oauth2_redirect_url=None,
init_oauth=None,
swagger_ui_parameters=None
)
Generate and return the HTML that loads Swagger UI for the interactive
API docs (normally served at /docs).
You would only call this function yourself if you needed to override some parts, for example the URLs to use to load Swagger UI's JavaScript and CSS.
Read more about it in the FastAPI docs for Configure Swagger UI and the FastAPI docs for Custom Docs UI Static Assets (Self-Hosting).
| PARAMETER | DESCRIPTION |
|---|---|
openapi_url
|
The OpenAPI URL that Swagger UI should load and use. This is normally done automatically by FastAPI using the default URL
Read more about it in the FastAPI docs for Conditional OpenAPI
TYPE:
|
title
|
The HTML Read more about it in the FastAPI docs for Custom Docs UI Static Assets
TYPE:
|
swagger_js_url
|
The URL to use to load the Swagger UI JavaScript. It is normally set to a CDN URL. Read more about it in the FastAPI docs for Custom Docs UI Static Assets
TYPE:
|
swagger_css_url
|
The URL to use to load the Swagger UI CSS. It is normally set to a CDN URL. Read more about it in the FastAPI docs for Custom Docs UI Static Assets
TYPE:
|
swagger_favicon_url
|
The URL of the favicon to use. It is normally shown in the browser tab.
TYPE:
|
oauth2_redirect_url
|
The OAuth2 redirect URL, it is normally automatically handled by FastAPI. Read more about it in the FastAPI docs for Custom Docs UI Static Assets
TYPE:
|
init_oauth
|
A dictionary with Swagger UI OAuth2 initialization configurations. Read more about the available configuration options in the Swagger UI docs.
TYPE:
|
swagger_ui_parameters
|
Configuration parameters for Swagger UI. It defaults to swagger_ui_default_parameters. Read more about it in the FastAPI docs about how to Configure Swagger UI.
TYPE:
|
fastapi.openapi.docs.get_redoc_html
¶
get_redoc_html(
*,
openapi_url,
title,
redoc_js_url="https://cdn.jsdelivr.net/npm/redoc@2/bundles/redoc.standalone.js",
redoc_favicon_url="https://fastapi.tiangolo.com/img/favicon.png",
with_google_fonts=True
)
Generate and return the HTML response that loads ReDoc for the alternative
API docs (normally served at /redoc).
You would only call this function yourself if you needed to override some parts, for example the URLs to use to load ReDoc's JavaScript and CSS.
Read more about it in the FastAPI docs for Custom Docs UI Static Assets (Self-Hosting).
| PARAMETER | DESCRIPTION |
|---|---|
openapi_url
|
The OpenAPI URL that ReDoc should load and use. This is normally done automatically by FastAPI using the default URL
Read more about it in the FastAPI docs for Conditional OpenAPI
TYPE:
|
title
|
The HTML Read more about it in the FastAPI docs for Custom Docs UI Static Assets
TYPE:
|
redoc_js_url
|
The URL to use to load the ReDoc JavaScript. It is normally set to a CDN URL. Read more about it in the FastAPI docs for Custom Docs UI Static Assets
TYPE:
|
redoc_favicon_url
|
The URL of the favicon to use. It is normally shown in the browser tab.
TYPE:
|
with_google_fonts
|
Load and use Google Fonts.
TYPE:
|
fastapi.openapi.docs.get_swagger_ui_oauth2_redirect_html
¶
get_swagger_ui_oauth2_redirect_html()
Generate the HTML response with the OAuth2 redirection for Swagger UI.
You normally don't need to use or change this.
fastapi.openapi.docs.swagger_ui_default_parameters
module-attribute
¶
swagger_ui_default_parameters = {
"dom_id": "#swagger-ui",
"layout": "BaseLayout",
"deepLinking": True,
"showExtensions": True,
"showCommonExtensions": True,
}
Default configurations for Swagger UI.
You can use it as a template to add any other configurations needed.
