Skip to main content

get_swagger_ui_html

Generate and return the HTML that loads Swagger UI for the interactive API docs (normally served at /docs).

def get_swagger_ui_html(
openapi_url: str,
title: str,
swagger_js_url: str = https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js,
swagger_css_url: str = https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.css,
swagger_favicon_url: str = https://fastapi.tiangolo.com/img/favicon.png,
oauth2_redirect_url: str | None = None,
init_oauth: dict[str, Any] | None = None,
swagger_ui_parameters: dict[str, Any] | None = None
) - > HTMLResponse

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).

Parameters

NameTypeDescription
openapi_urlstrThe OpenAPI URL that Swagger UI should load and use. This is normally done automatically by FastAPI using the default URL /openapi.json. Read more about it in the FastAPI docs for Conditional OpenAPI
titlestrThe HTML < title > content, normally shown in the browser tab. Read more about it in the FastAPI docs for Custom Docs UI Static Assets
swagger_js_urlstr = https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.jsThe 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
swagger_css_urlstr = https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.cssThe 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
swagger_favicon_urlstr = https://fastapi.tiangolo.com/img/favicon.pngThe URL of the favicon to use. It is normally shown in the browser tab.
oauth2_redirect_url`strNone` = None
init_oauth`dict[str, Any]None` = None
swagger_ui_parameters`dict[str, Any]None` = None

Returns

TypeDescription
HTMLResponseThe HTML content that loads Swagger UI.