-
-
Notifications
You must be signed in to change notification settings - Fork 80
🐛 Fix hardcoded docs URL #386
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
Open
YuriiMotov
wants to merge
11
commits into
main
Choose a base branch
from
fix-docs-urls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1280603
feat: update discover functions to return fastapi app
FlavienRx a23816f
feat: refactor conditional printing api docs urls
FlavienRx 5e6e428
tests: conditional printing api docs urls
FlavienRx dda7dc6
fix: python 3.8 and 3.9 mypy error
FlavienRx edca1c7
Merge remote-tracking branch 'upstream/main' into docs-conditional-panel
YuriiMotov 03ea860
Split docs_url discovery from import_data discovery
YuriiMotov 4a7ea66
Refactor `docs_urls`-related tests
YuriiMotov 59fc428
Respect `root_path` in URLs
YuriiMotov bfdfa62
Refactor `get_docs_urls` to return list of URLs
YuriiMotov a320f5d
Revert adding empty lines
YuriiMotov b6f1b9e
Merge branch 'main' into fix-docs-urls
YuriiMotov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| from fastapi import FastAPI | ||
|
|
||
| # App 1: API documentation disabled via `openapi_url=None` | ||
| # ------------------------------------------------------------------------------------ | ||
|
|
||
| openapi_none = FastAPI(openapi_url=None) | ||
|
|
||
|
|
||
| @openapi_none.get("/") | ||
| def openapi_none_root(): | ||
| return {"message": "single file openapi_none"} | ||
|
|
||
|
|
||
| # App 2: Both docs and redoc disabled via `docs_url=None` and `redoc_url=None` | ||
| # ------------------------------------------------------------------------------------ | ||
|
|
||
| docs_none_redoc_none = FastAPI(docs_url=None, redoc_url=None) | ||
|
|
||
|
|
||
| @docs_none_redoc_none.get("/") | ||
| def docs_none_redoc_none_root(): | ||
| return {"message": "single file docs_none_redoc_none"} | ||
|
|
||
|
|
||
| # App 3: Only ReDoc. Swagger docs disabled via `docs_url=None` | ||
| # ------------------------------------------------------------------------------------ | ||
|
|
||
| only_redoc = FastAPI(docs_url=None) | ||
|
|
||
|
|
||
| @only_redoc.get("/") | ||
| def only_redoc_root(): | ||
| return {"message": "single file only_redoc"} | ||
|
|
||
|
|
||
| # App 4: Only Swagger docs. ReDoc disabled via `redoc_url=None` | ||
| # ------------------------------------------------------------------------------------ | ||
|
|
||
| only_docs = FastAPI(redoc_url=None) | ||
|
|
||
|
|
||
| @only_docs.get("/") | ||
| def only_docs_root(): | ||
| return {"message": "single file only_docs"} | ||
|
|
||
|
|
||
| # App 5: Both docs and redoc enabled with default URLs | ||
| # ------------------------------------------------------------------------------------ | ||
|
|
||
| full_docs = FastAPI() | ||
|
|
||
|
|
||
| @full_docs.get("/") | ||
| def full_docs_root(): | ||
| return {"message": "single file full_docs"} | ||
|
|
||
|
|
||
| # App 6: Swagger docs with custom URL. ReDoc with default URL. | ||
| # ------------------------------------------------------------------------------------ | ||
|
|
||
| custom_docs = FastAPI(docs_url="/custom-docs-url") | ||
|
|
||
|
|
||
| @custom_docs.get("/") | ||
| def custom_docs_root(): | ||
| return {"message": "single file custom_docs"} | ||
|
|
||
|
|
||
| # App 7: ReDoc with custom URL. Swagger docs with default URL. | ||
| # ------------------------------------------------------------------------------------ | ||
|
|
||
| custom_redoc = FastAPI(docs_url=None, redoc_url="/custom-redoc-url") | ||
|
|
||
|
|
||
| @custom_redoc.get("/") | ||
| def custom_redoc_root(): | ||
| return {"message": "single file custom_redoc"} | ||
|
|
||
|
|
||
| # App 8: Swagger docs enabled, root_path set to "/api". ReDoc disabled. | ||
| # ------------------------------------------------------------------------------------ | ||
|
|
||
| docs_root_path = FastAPI(redoc_url=None, root_path="/api") | ||
|
|
||
|
|
||
| @docs_root_path.get("/") | ||
| def docs_root_path_root(): | ||
| return {"message": "single file docs_root_path"} | ||
|
|
||
|
|
||
| # App 9: ReDoc enabled, root_path set to "/api". Swagger docs disabled. | ||
| # ------------------------------------------------------------------------------------ | ||
|
|
||
| redoc_root_path = FastAPI(docs_url=None, root_path="/api") | ||
|
|
||
|
|
||
| @redoc_root_path.get("/") | ||
| def redoc_root_path_root(): | ||
| return {"message": "single file redoc_root_path"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you create a list of url and just print the first ? What about swagger and redoc urls ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to keep it closer to the current behavior (only Swagger docs link is shown).
But I was in doubts about whether we should limit it to only first link or show all of them.
I actually wanted to highlight this in the comments, but forgot. So, thanks for pointing to it!)
I personally think that showing only one link is OK, and there is no big difference where to drop others (I mean whether to return all links from
get_docs_utlsor to return the only one that should be shown).Let's wait for Sebastian to take a look and decide