This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Ability to customise Redoc and Swagger UI HTML #1332
Labels
You can continue the conversation there. Go to discussion →
Is your feature request related to a problem? No
Currently, Redoc and Swagger UI are served from literal strings in the code with formatted-in options for Title, JS URL, etc. However, these are not customisable and the hardcoded defaults are always used.
The solution you would like
I propose to add some a
redoc_kwargs
anddocs_kwargs
(or similar) parameter to the FastAPI class (because having individual arguments would be too cumbersome) which are passed to theget_redoc_html
andget_swagger_ui_html
methods. I also propose adding some more arguments to those methods for custom CSS, fonts, or other HTML additions (perhaps a slot each for<head>
and<body>
after the rest of the content) if required.Describe alternatives you've considered
Currently you could implement your own Redoc/Swagger UI endpoints instead of using FastAPI's ones and returning your own HTML, but I feel that sort of defeats the purpose of having these features.
These endpoints could even be converted to full-blown Jinja2 templates or similar, although this does seem a bit excessive to me.
Additional context
(note: what follows are a bunch of rambled related ideas I came up with in the 5 minutes I spent writing this issue, in hindsight these could have been separate issues)
Perhaps as part of this revamp, the
get_redoc_html
andget_swagger_ui_html
methods could be closures, so that the static HTML is not recreated on every request (a separate issue, I know, and only a very minor performance bump as well)Another related suggestion would be to allow rewriting all requests to
/docs/*
//redoc/*
to those URLs to enable use of HTML5 history mode instead of anchors, SPA-style (although I believe currently neither Swagger UI nor Redoc actually support these)The text was updated successfully, but these errors were encountered: