✨ Add support for setting Swagger UI initOAuth configs (clientId, appName) (#499)

This commit is contained in:
Zamir Amir
2019-10-04 01:41:04 +02:00
committed by Sebastián Ramírez
parent 78272ac1f3
commit 8505b716af
3 changed files with 42 additions and 1 deletions
+11 -1
View File
@@ -1,5 +1,7 @@
import json
from typing import Optional
from fastapi.encoders import jsonable_encoder
from starlette.responses import HTMLResponse
@@ -11,6 +13,7 @@ def get_swagger_ui_html(
swagger_css_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@3/swagger-ui.css",
swagger_favicon_url: str = "https://fastapi.tiangolo.com/img/favicon.png",
oauth2_redirect_url: Optional[str] = None,
init_oauth: Optional[dict] = None,
) -> HTMLResponse:
html = f"""
@@ -42,7 +45,14 @@ def get_swagger_ui_html(
],
layout: "BaseLayout",
deepLinking: true
})
})"""
if init_oauth:
html += f"""
ui.initOAuth({json.dumps(jsonable_encoder(init_oauth))})
"""
html += """
</script>
</body>
</html>