-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Closed
Labels
Description
First check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn't find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google "How to X in FastAPI" and didn't find any information.
- I already read and followed all the tutorial in the docs and didn't find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
- After submitting this, I commit to:
- Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
- Or, I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.
- Implement a Pull Request for a confirmed bug.
I would like to see a parameter like custom_js_url in get_swagger_ui_html in FastAPI for more control over the docs page.
This can help if we want to insert certain missing components to the docs or be able to save tokens to the browser on redirect, etc. Furthermore, this gives us the freedom to choose to stick with CDN for serving swagger UI js and have more client-side flexibility.
A similar thing can be done for CSS files.
def get_swagger_ui_html(
*,
openapi_url: str,
title: str,
swagger_js_url: str = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@3/swagger-ui-bundle.js",
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[str, Any]] = None,
custom_js_url: Optional[str] = None,
) -> HTMLResponse:
...
if custom_js_url:
html += f"""<!-- custom javascript code goes here-->
<script src="{custom_js_url}"></script>
"""
html += """</body></html>"""
return HTMLResponse(html)
Reactions are currently unavailable