Skip to content

🐛 Fix hardcoded docs URL#386

Open
YuriiMotov wants to merge 11 commits intomainfrom
fix-docs-urls
Open

🐛 Fix hardcoded docs URL#386
YuriiMotov wants to merge 11 commits intomainfrom
fix-docs-urls

Conversation

@YuriiMotov
Copy link
Copy Markdown
Member

@YuriiMotov YuriiMotov commented Apr 28, 2026

Closes: #162

FastAPI allows configuring the docs URLs, but fastapi-cli currently doesn't respect it:

from fastapi import FastAPI

app = FastAPI(docs_url="/swagger_docs", root_path="/api")

@app.get("/")
async def root():
    return {"message": "Hello World"}

(docs URL should be http://0.0.0.0:8000/api/swagger_docs)

$ fastapi run

   FastAPI   Starting production server 🚀

  ...
 
    server   Server started at http://0.0.0.0:8000
    server   Documentation at http://0.0.0.0:8000/docs

This PR fixes this.

Use cases:

  • disable API docs by setting openapi_url=None
  • disable Swagger docs by setting docs_url=None, Redoc docs URL will be shown
  • Custom docs URLs for Swagger docs and for Redoc
  • root_path specified as an option to fastapi run\dev command or as a parameter to FastAPI

With this fix:

$ fastapi run

   FastAPI   Starting production server 🚀
 
  ...
 
    server   Server started at http://0.0.0.0:8000/api
    server   Documentation at http://0.0.0.0:8000/api/swagger_docs

See also #381 that solves the issue with docs being unreachable via links due to 0.0.0.0 in host address


This PR is based on #119, credits to @FlavienRx

@YuriiMotov YuriiMotov added the bug Something isn't working label Apr 28, 2026
@YuriiMotov YuriiMotov marked this pull request as ready for review April 28, 2026 09:57
Comment thread src/fastapi_cli/discover.py
Comment thread src/fastapi_cli/cli.py
]
if docs_links:
toolkit.print(
f"Documentation at {docs_links[0]}",
Copy link
Copy Markdown
Contributor

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 ?

Copy link
Copy Markdown
Member Author

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_utls or to return the only one that should be shown).
Let's wait for Sebastian to take a look and decide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hard-coded documentation endpoint

3 participants