In patched_get_swagger_ui_html the urls only reference self.app.docs_url. This works fine until the app itself is mounted under another app. When this occurs the mounted app gets the base path passed to it via root_path.
IE:
def create_app() -> FastAPI:
main_app = FastAPI(...)
app = FastAPI(...)
StandaloneDocs(app)
app.include_router(myroute1, prefix='myroute1')
app.include_router(myroute2, prefix='myroute2')
main_app,mount("/myapp1", app)
return main_app
In the above case, the full docs url is probably /myapp1/docs, but it then will try to read its static assets from /docs.
To fix this, patched_get_swagger_ui_html should prefix the passed urls to get_swager_ui_html with the apps current root_path.
Something like:
def patched_get_swagger_ui_html(*args, **kwargs):
return get_swagger_ui_html(
*args,
**kwargs,
swagger_favicon_url=swagger_favicon_url,
swagger_css_url=f"{self.app.root_path}{self.app.docs_url}/swagger-ui.css",
swagger_js_url=f"{self.app.root_path}{self.app.docs_url}/swagger-ui-bundle.js",
)
In
patched_get_swagger_ui_htmlthe urls only referenceself.app.docs_url. This works fine until the app itself is mounted under another app. When this occurs the mounted app gets the base path passed to it viaroot_path.IE:
In the above case, the full docs url is probably
/myapp1/docs, but it then will try to read its static assets from/docs.To fix this,
patched_get_swagger_ui_htmlshould prefix the passed urls toget_swager_ui_htmlwith the apps currentroot_path.Something like: