From 3a31862881dfb3143331fd36c73c4ce0a67867dc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 18 Nov 2023 07:34:46 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20format?= =?UTF-8?q?=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs_src/custom_docs_ui/tutorial001.py | 4 +++- docs_src/custom_docs_ui/tutorial002.py | 3 ++- fastapi/applications.py | 2 +- fastapi/openapi/docs.py | 2 ++ tests/test_application.py | 2 ++ tests/test_tutorial/test_custom_docs_ui/test_tutorial001.py | 2 ++ tests/test_tutorial/test_custom_docs_ui/test_tutorial002.py | 1 + 7 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs_src/custom_docs_ui/tutorial001.py b/docs_src/custom_docs_ui/tutorial001.py index 0af2c67607ccb..4e9b211d69001 100644 --- a/docs_src/custom_docs_ui/tutorial001.py +++ b/docs_src/custom_docs_ui/tutorial001.py @@ -1,8 +1,8 @@ from fastapi import FastAPI from fastapi.openapi.docs import ( get_redoc_html, - get_swagger_ui_html, get_scalar_html, + get_swagger_ui_html, get_swagger_ui_oauth2_redirect_html, ) @@ -33,6 +33,7 @@ async def redoc_html(): redoc_js_url="https://unpkg.com/redoc@next/bundles/redoc.standalone.js", ) + @app.get("/scalar", include_in_schema=False) async def scalar_html(): return get_scalar_html( @@ -41,6 +42,7 @@ async def scalar_html(): scalar_js_url="https://cdn.jsdelivr.net/npm/@scalar/api-reference", ) + @app.get("/users/{username}") async def read_user(username: str): return {"message": f"Hello {username}"} diff --git a/docs_src/custom_docs_ui/tutorial002.py b/docs_src/custom_docs_ui/tutorial002.py index 94f05dd35b2d7..fe937f6b54cb0 100644 --- a/docs_src/custom_docs_ui/tutorial002.py +++ b/docs_src/custom_docs_ui/tutorial002.py @@ -1,8 +1,8 @@ from fastapi import FastAPI from fastapi.openapi.docs import ( get_redoc_html, - get_swagger_ui_html, get_scalar_html, + get_swagger_ui_html, get_swagger_ui_oauth2_redirect_html, ) from fastapi.staticfiles import StaticFiles @@ -36,6 +36,7 @@ async def redoc_html(): redoc_js_url="/static/redoc.standalone.js", ) + @app.get("/scalar", include_in_schema=False) async def scalar_html(): return get_scalar_html( diff --git a/fastapi/applications.py b/fastapi/applications.py index 8c23d02cca280..829fc90fb1296 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -1125,7 +1125,7 @@ async def redoc_html(req: Request) -> HTMLResponse: ) self.add_route(self.redoc_url, redoc_html, include_in_schema=False) - + if self.openapi_url and self.scalar_url: async def scalar_html(req: Request) -> HTMLResponse: diff --git a/fastapi/openapi/docs.py b/fastapi/openapi/docs.py index c5f1454db260e..38193caf384cc 100644 --- a/fastapi/openapi/docs.py +++ b/fastapi/openapi/docs.py @@ -157,6 +157,7 @@ def get_swagger_ui_html( """ return HTMLResponse(html) + def get_scalar_html( *, openapi_url: Annotated[ @@ -247,6 +248,7 @@ def get_scalar_html( """ return HTMLResponse(html) + def get_redoc_html( *, openapi_url: Annotated[ diff --git a/tests/test_application.py b/tests/test_application.py index cbb45fb31fbaa..73cbe3a00e7d6 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -45,12 +45,14 @@ def test_redoc(): assert response.headers["content-type"] == "text/html; charset=utf-8" assert "redoc@next" in response.text + def test_scalar(): response = client.get("/scalar") assert response.status_code == 200, response.text assert response.headers["content-type"] == "text/html; charset=utf-8" assert "@scalar/api-reference" in response.text + def test_enum_status_code_response(): response = client.get("/enum-status-code") assert response.status_code == 201, response.text diff --git a/tests/test_tutorial/test_custom_docs_ui/test_tutorial001.py b/tests/test_tutorial/test_custom_docs_ui/test_tutorial001.py index 6242a6efcd7f5..b0043f8ac129b 100644 --- a/tests/test_tutorial/test_custom_docs_ui/test_tutorial001.py +++ b/tests/test_tutorial/test_custom_docs_ui/test_tutorial001.py @@ -37,11 +37,13 @@ def test_redoc_html(client: TestClient): assert response.status_code == 200, response.text assert "https://unpkg.com/redoc@next/bundles/redoc.standalone.js" in response.text + def test_scalar_html(client: TestClient): response = client.get("/scalar") assert response.status_code == 200, response.text assert "https://cdn.jsdelivr.net/npm/@scalar/api-reference" in response.text + def test_api(client: TestClient): response = client.get("/users/john") assert response.status_code == 200, response.text diff --git a/tests/test_tutorial/test_custom_docs_ui/test_tutorial002.py b/tests/test_tutorial/test_custom_docs_ui/test_tutorial002.py index 90ea1004a44e4..2d5bf86284579 100644 --- a/tests/test_tutorial/test_custom_docs_ui/test_tutorial002.py +++ b/tests/test_tutorial/test_custom_docs_ui/test_tutorial002.py @@ -35,6 +35,7 @@ def test_redoc_html(client: TestClient): assert response.status_code == 200, response.text assert "/static/redoc.standalone.js" in response.text + def test_scalar_html(client: TestClient): response = client.get("/scalar") assert response.status_code == 200, response.text