-
Notifications
You must be signed in to change notification settings - Fork 13
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
Versionized docs are not showing "servers" unless the base /docs is visited 1st #62
Comments
@jobewan And just to be clear, which version of fastapi are you using? |
fastapi version: 0.106.0 |
I've encountered the same issue, and I don’t believe it’s due to the FastAPI version, as the error occurs in both version 0.110.0 and the latest version 0.115.5. The behavior is identical to what @jobewan described. The root of the issue appears to be in the _add_version_docs method in fastapi-versionizer. More precisely from this code:
The issue is that when accessing a version-specific documentation path, the FastAPI OpenAPI constructor isn’t triggered. Instead, Versionizer’s custom OpenAPI is immediately initiated, which doesn’t properly include the root_path in self.app.servers. As a result, accessing root_path/docs makes everything work correctly because the FastAPI OpenAPI constructor is then applied. The solution is to add the following lines to the code above:
here is the complete new code.
this adds root_path management to fastapi-versionizer. |
Feel free to open up a PR |
Subject of the issue
Versionized docs are not showing "servers" and swagger api executions return 404 unless the base /docs is visited 1st
Your environment
Steps to reproduce
Run the with_root_path.py example, visit the versionized docs and execute an api call or pull the openapi schema json file
Expected behaviour
The servers should be populated in the versionized openapi shcema and the swagger executions should work
Actual behaviour
This is odd. When using the example with_root_path.py. While using the options: "include_main_docs=False, include_main_openapi_route=False", the versionized docs @ /root/path/api/v[1,2]/docs results in every swagger api execution to return a 404 due to it not using the root path (the api "servers" are not populated in the openapi schema file either). Although, if you change the parameters so that "include_main_docs=True, include_main_openapi_route=True", you can visit the /root/path/docs to see things working as expected, and THEN visit the /root/path/api/v[1,2]/docs paths and those versions work as expected by populating the "servers" param in the schema and the swagger api executions work.
The text was updated successfully, but these errors were encountered: