fastapi-cli icon indicating copy to clipboard operation
fastapi-cli copied to clipboard

add support to dynamic url docs based on the FastAPI docs_url param

Open pedroimpulcetto opened this issue 3 months ago • 6 comments

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

pedroimpulcetto avatar Oct 02 '25 14:10 pedroimpulcetto

hey @svlandeg, as we are stuck with the other PR, I just made the changes to fix #162

pedroimpulcetto avatar Oct 02 '25 18:10 pedroimpulcetto

hey @tiangolo I would love to have it merged and fix #162 issue 🙏 let me know your thoughts

pedroimpulcetto avatar Oct 06 '25 19:10 pedroimpulcetto

Just enountered this bug, it would be great to merge this fix 🙌🏻

marrrcin avatar Nov 03 '25 09:11 marrrcin

This pull request has a merge conflict that needs to be resolved.

github-actions[bot] avatar Nov 10 '25 15:11 github-actions[bot]

hey @patrick91 @tiangolo, what are your thoughts about it? we would love to get it in

pedroimpulcetto avatar Nov 11 '25 16:11 pedroimpulcetto

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:

  1. Default behavior (docs_url="/docs")
  2. Custom docs URL (e.g., docs_url="/api-docs")
  3. Disabled docs (docs_url=None)
  4. Combination with root_path
  5. Both fastapi dev and fastapi run commands

I'll share detailed findings and any edge cases I discover. Great work on this implementation! 🚀

themojtabajaveed avatar Nov 19 '25 07:11 themojtabajaveed