🧑💻 Add conditional printing API docs URLs in panel#119
🧑💻 Add conditional printing API docs URLs in panel#119FlavienRx wants to merge 4 commits intofastapi:mainfrom
Conversation
|
hi |
|
Hi @sehraramiz You right, I started to refactor my code but I run out of time to finish and push my code 😄 |
f45dccf to
9f95bd6
Compare
|
I did the job, let me know what do you think. @tiangolo, what do you think about this feature ? |
|
A new label has to be added:
|
|
This resolves #162 |
|
Would this work if I disable the URLs entirely? app = FastAPI(
lifespan=lifespan,
docs_url="/docs" if DEV_MODE else None,
redoc_url="/redoc" if DEV_MODE else None,
openapi_url="/openapi.json" if DEV_MODE else None
) |
|
@eden881 Yep, I had some tests to test this case. |
|
This pull request has a merge conflict that needs to be resolved. |
f377897 to
83c7c7b
Compare
83c7c7b to
5e6e428
Compare
|
I rebased my branch again. Do you have any feedback @tiangolo @Kludex @YuriiMotov @svlandeg ? Or can you label this PR ? |
|
This pull request has a merge conflict that needs to be resolved. |
YuriiMotov
left a comment
There was a problem hiding this comment.
@FlavienRx, thanks for working on this!
It doesn't seem correct to put docs_url into the ImportData object. I think we should either refactor logic to change name. Or, maybe better to split import discovery and docs url discovery into two steps?
What do you think?
Also, this implementation doesn't handle root_path. It can be set via root_path parameter to FastAPI or via --root-path option to fastapi run.
Would you like to continue working on it?
| openapi_url: Union[str, None] = None | ||
| docs_url: Union[str, None] = None | ||
| redoc_url: Union[str, None] = None |
There was a problem hiding this comment.
I don't really like that these docs urls are put into ImportData. These URLs are not "Import data"..
Description:
This PR refactors the FastAPI server start-up logic to improve the display of the application’s documentation URLs in the console. It introduces a conditional check for app.openapi_url, ensuring that only defined documentation URLs are printed. The updated logic adds more flexibility to display either docs_url, redoc_url, or both, enhancing visibility for users when serving the API.
Changes:
This adjustment improves user experience by making API documentation links visible and accessible only when they are set.
Examples:


