I can't expand/collapse routes or see schemas when I access /docs. This started after the new swagger-ui version 3.30.1 CDN came out. As a work around I disabled automatic docs setting docs_url=None, downloaded the previous swagger-ui (3.29.0) and served them as static files.
Facing the same issue
Just to get it working for the moment you could monkey patch the function which is generating the html for the swagger documentation to force it to swagger v3.29 like this:
from fastapi import applications
from fastapi.openapi.docs import get_swagger_ui_html
def swagger_monkey_patch(*args, **kwargs):
"""
Wrap the function which is generating the HTML for the /docs endpoint and
overwrite the default values for the swagger js and css.
"""
return get_swagger_ui_html(
*args, **kwargs,
swagger_js_url="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-bundle.js",
swagger_css_url="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui.css")
# Actual monkey patch
applications.get_swagger_ui_html = swagger_monkey_patch
# Your normal code ...
app = FastAPI()
Just to get it working for the moment you could monkey patch the function which is generating the html for the swagger documentation to force it to swagger v3.29 like this:
from fastapi import applications from fastapi.openapi.docs import get_swagger_ui_html def swagger_monkey_patch(*args, **kwargs): """ Wrap the function which is generating the HTML for the /docs endpoint and overwrite the default values for the swagger js and css. """ return get_swagger_ui_html( *args, **kwargs, swagger_js_url="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui-bundle.js", swagger_css_url="https://cdn.jsdelivr.net/npm/[email protected]/swagger-ui.css") # Actual monkey patch applications.get_swagger_ui_html = swagger_monkey_patch # Your normal code ... app = FastAPI()
work for me
omg, just deployed in production and facing same issue :/
The braking change seems to be part of swagger-ui v3.30.1 as forcing it to v3.30.0 works for me.
The braking change seems to be part of swagger-ui v3.30.1 as forcing it to v3.30.0 works for me.
Youre monkey patch works for me as well, tks
Seems to be a known issue on swagger-ui side
https://github.com/swagger-api/swagger-ui/issues/6249
Thanks for reporting it and for all the discussion here everyone! :rocket: :coffee:
Indeed, it's a bug in Swagger UI, not in FastAPI, as @cimera255 noticed.
To alleviate it, I just released FastAPI 0.60.1
pinning the version of Swagger UI to the last working version 3.30.0
. :rocket:
If you can upgrade to the latest FastAPI version, it should then work correctly. Make sure to run your tests before upgrading the version. :heavy_check_mark:
Thanks for reporting it and for all the discussion here everyone! 🚀 ☕
Indeed, it's a bug in Swagger UI, not in FastAPI, as @cimera255 noticed.
To alleviate it, I just released FastAPI
0.60.1
pinning the version of Swagger UI to the last working version3.30.0
. 🚀If you can upgrade to the latest FastAPI version, it should then work correctly. Make sure to run your tests before upgrading the version. ✔️
When is docker available
Hello @tiangolo ,
Upgraded to v0.60.1 .. but failed to POST for starlette==0.13.6
Then downgraded starlette==0.13.4 , it works !
Pls advise. Thanks.
@XuChaoChi The Docker image should be fine, you should still install FastAPI with the version that works for you pinned, and update only after confirming that all the tests pass correctly: https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker#dependencies-and-packages
@lc2a please create a new issue following the guide and the template for your specific problem.
This was an excellent job releasing a fix for us so quickly. Thanks!
Is it worth adding swagger_ui_version
as an optional parameter to the built-in get_swagger_ui_html
so that users could easily override this in the future if necessary?
As I went through this I also noticed that the self-hosting docs are missing notes about the new root_path
feature.
I could probably put those in a pull request if there is interest.
released FastAP
did u solve the problem? It seems I am having some troubleshootings
released FastAP
did u solve the problem? It seems I am having some troubleshootings
Hi pedro, you can simply update your FastApi version with your preferred package management tool, or use the monkey patch referenced by @ratopythonista here
Just installed fastAPI 0.61.2 version yet the swagger UI isn't working.
@Christomesh please open a new issue
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.
Most helpful comment
Thanks for reporting it and for all the discussion here everyone! :rocket: :coffee:
Indeed, it's a bug in Swagger UI, not in FastAPI, as @cimera255 noticed.
To alleviate it, I just released FastAPI
0.60.1
pinning the version of Swagger UI to the last working version3.30.0
. :rocket:If you can upgrade to the latest FastAPI version, it should then work correctly. Make sure to run your tests before upgrading the version. :heavy_check_mark: