diff --git a/fastapi/openapi/docs.py b/fastapi/openapi/docs.py index f7d8b6d50..b71adafee 100644 --- a/fastapi/openapi/docs.py +++ b/fastapi/openapi/docs.py @@ -2,7 +2,6 @@ import json from typing import Annotated, Any, Optional from annotated_doc import Doc -from fastapi.encoders import jsonable_encoder from starlette.responses import HTMLResponse swagger_ui_default_parameters: Annotated[ @@ -119,18 +118,20 @@ def get_swagger_ui_html( "showCommonExtensions": True, "presets": [ "SwaggerUIBundle.presets.apis", - "SwaggerUIBundle.SwaggerUIStandalonePreset" - ] + "SwaggerUIBundle.SwaggerUIStandalonePreset", + ], } - + if swagger_ui_parameters: swagger_config.update(swagger_ui_parameters) - + if oauth2_redirect_url: - swagger_config["oauth2RedirectUrl"] = f"window.location.origin + '{oauth2_redirect_url}'" - + swagger_config["oauth2RedirectUrl"] = ( + f"window.location.origin + '{oauth2_redirect_url}'" + ) + config_json = json.dumps(swagger_config, default=str) - + html = f''' @@ -144,17 +145,17 @@ def get_swagger_ui_html( -''' - +""" + return HTMLResponse(html) @@ -216,20 +217,20 @@ def get_redoc_html( Read more about it in the [FastAPI docs for Custom Docs UI Static Assets (Self-Hosting)](https://fastapi.tiangolo.com/how-to/custom-docs-ui-assets/). """ - - html = f''' + + html = f""" {title} -''' - +""" + if with_google_fonts: - html += ''' -''' - + html += """ +""" + html += f'''