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
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