get_swagger_ui_html
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](https://fastapi.tiangolo.com/how-to/configure-swagger-ui/)
and the [FastAPI docs for Custom Docs UI Static Assets (Self-Hosting)](https://fastapi.tiangolo.com/how-to/custom-docs-ui-assets/).
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 | null = null,
init_oauth: dict[str, Any] | null = null,
swagger_ui_parameters: dict[str, Any] | null = null
) - > 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.
Parameters
| Name | Type | Description |
|---|---|---|
| openapi_url | str | The OpenAPI URL that Swagger UI should load and use to generate the documentation interface. |
| title | str | The HTML < title > content, normally shown in the browser tab. |
| swagger_js_url | str = https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js | The URL to use to load the Swagger UI JavaScript bundle. |
| swagger_css_url | str = https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.css | The URL to use to load the Swagger UI CSS stylesheet. |
| swagger_favicon_url | str = https://fastapi.tiangolo.com/img/favicon.png | The URL of the favicon to use for the documentation page. |
| oauth2_redirect_url | `str | null` = null |
| init_oauth | `dict[str, Any] | null` = null |
| swagger_ui_parameters | `dict[str, Any] | null` = null |
Returns
| Type | Description |
|---|---|
HTMLResponse | An HTML response containing the full page structure, CSS links, and JavaScript initialization code required to render the Swagger UI interface. |