From 3e2047571a38142148cc5fe7676d68b66c786d82 Mon Sep 17 00:00:00 2001 From: Samuel Rigaud Date: Thu, 1 Feb 2024 10:07:47 -0500 Subject: [PATCH] Generate cleaner OpenAPI HTML --- fastapi/openapi/docs.py | 76 ++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/fastapi/openapi/docs.py b/fastapi/openapi/docs.py index 69473d19c..0880defdd 100644 --- a/fastapi/openapi/docs.py +++ b/fastapi/openapi/docs.py @@ -114,45 +114,49 @@ def get_swagger_ui_html( if swagger_ui_parameters: current_swagger_ui_parameters.update(swagger_ui_parameters) + html_swagger_ui_parameters = "\n ".join( + [ + f"{json.dumps(key)}: {json.dumps(jsonable_encoder(value))}," + for key, value in current_swagger_ui_parameters.items() + ] + ) + html_oauth2_redirect_url = ( + f"oauth2RedirectUrl: window.location.origin + '{oauth2_redirect_url}'," + if oauth2_redirect_url + else "" + ) + init_oauth_html = ( + f"ui.initOAuth({json.dumps(jsonable_encoder(init_oauth))})" + if init_oauth + else "" + ) + html = f""" - - - - {title} - - -
-
- - - - + + + + {title} + + +
+
+ + + + """ return HTMLResponse(html)