Skip to content

Commit

Permalink
feat: add warning about fastapi params
Browse files Browse the repository at this point in the history
  • Loading branch information
dantetemplar committed Aug 12, 2024
1 parent e6f71e7 commit babb09c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions fastapi_swagger/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from importlib import resources
from typing import Optional, Dict, Any

Expand Down Expand Up @@ -34,6 +35,18 @@ def patch_fastapi(
:param init_oauth: OAuth2 configuration
:param oauth2_redirect_url: OAuth2 redirect URL
"""
# docs_url=None, swagger_ui_oauth2_redirect_url=None should be set in FastAPI app definition
if getattr(app, "docs_url", None) is not None:
warnings.warn(
"`docs_url` is set in FastAPI app definition, please, set it to None",
UserWarning,
)
if getattr(app, "swagger_ui_oauth2_redirect_url", None) is not None:
warnings.warn(
"`swagger_ui_oauth2_redirect_url` is set in FastAPI app definition, please, set it to None",
UserWarning,
)

if redirect_from_root_to_docs:

@app.get("/", include_in_schema=False)
Expand Down
2 changes: 1 addition & 1 deletion test/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def test_app():
app = FastAPI(title="Test App")
app = FastAPI(title="Test App", docs_url=None, swagger_ui_oauth2_redirect_url=None)
patch_fastapi(app, title="Test App")
client = TestClient(app)
response = client.get("/docs")
Expand Down

0 comments on commit babb09c

Please sign in to comment.