-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for ASGI root_path for openapi docs #1199
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1199 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 224 230 +6
Lines 6728 6862 +134
==========================================
+ Hits 6728 6862 +134
Continue to review full report at Codecov.
|
I guess this PR solves the same issue that I was having (I didn't even know about issue #829). I solved my problem by just adding the prefix to the redirect url. You can see what I did on my proposed PR #1159. But it seems to me that your solution involves more steps that I may have been missing. Could you explain? I will probably delete #1159 since it is redundant, now that you've done this 😄 |
Great! 🚀 Thanks for the patience, it took me a bit of time to review this as I wanted to first re-read the WSGI and ASGI specs to make sure I wasn't missing anything. And then to test it all with an actual reverse proxy with path prefix stripping (what the I refactored it a bit and took the opportunity to deprecate And I added a bunch of docs to explain how the Thanks for your contribution! 🚀 🎉 🍰 This is available in FastAPI |
* Use ASGI root_path when it is provided and openapi_prefix is empty. * Strip trailing slashes from root_path. * Please mypy. * Fix extending openapi test. * 📝 Add docs and tutorial for using root_path behind a proxy * ♻️ Refactor application root_path logic, use root_path, deprecate openapi_prefix * ✅ Add tests for Behind a Proxy with root_path * ♻️ Refactor test * 📝 Update/add docs for Sub-applications and Behind a Proxy * 📝 Update Extending OpenAPI with openapi_prefix parameter * ✅ Add test for deprecated openapi_prefix Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
ASGI specifies the
root_path
connection scope variable. This is the path the application is mounted under (the equivalent of WSGI'sSCRIPT_NAME
).This PR ensures that this root is used as a prefix for the openapi.json URL, as a prefix for paths contained in openapi.json and by the oauth2 redirect endpoint to redirect back to the swagger docs.
To override the path the ASGI server provides you can still explicitly set the
openapi_prefix
variable.Do note that this is a breaking change for applications that overriden
openapi()
themselves.This should fix/related to #829