add support to dynamic url docs based on the FastAPI docs_url param
This PR adds support for dynamically displaying the correct documentation URL in the CLI output based on the FastAPI application's docs_url parameter configuration.
Fixes #162 issue Improve and adapt PR #24
Changes
• Dynamic docs URL detection: The CLI now inspects the FastAPI application's docs_url parameter to determine the correct documentation URL
• ⚠️ Conditional docs display: When docs_url is set to None, the documentation URL is not displayed in the CLI output
Implementation Details
• Added _get_url_docs() function to extract the docs_url from the FastAPI application instance • Modified the server startup output to conditionally display documentation URL based on the docs_url parameter • Updated both dev and run commands to support dynamic URL detection
Testing
Added comprehensive test coverage for:
• Applications with custom docs_url paths • Applications with docs_url=None (disabled docs) • Applications with both custom docs_url and root_path • Both dev and run command modes • Various host and port configurations
hey @svlandeg, as we are stuck with the other PR, I just made the changes to fix #162
hey @tiangolo I would love to have it merged and fix #162 issue 🙏 let me know your thoughts
Just enountered this bug, it would be great to merge this fix 🙌🏻
This pull request has a merge conflict that needs to be resolved.
hey @patrick91 @tiangolo, what are your thoughts about it? we would love to get it in
Hi @pedroimpulcetto! 👋
I'm testing and reviewing this PR as part of my contribution to resolving #162.
Initial Review:
- ✅ All 17 checks passing
- ✅ No merge conflicts
- ✅ Clean implementation with the
_get_url_docs()function - ✅ Comprehensive test coverage added
Testing Plan: I'll be thoroughly testing:
- Default behavior (
docs_url="/docs") - Custom docs URL (e.g.,
docs_url="/api-docs") - Disabled docs (
docs_url=None) - Combination with
root_path - Both
fastapi devandfastapi runcommands
I'll share detailed findings and any edge cases I discover. Great work on this implementation! 🚀