Skip to content

Commit

Permalink
馃帹 [pre-commit.ci] Auto format from pre-commit.com hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Nov 18, 2023
1 parent 5439cb0 commit 3a31862
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion 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,
)

Expand Down Expand Up @@ -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(
Expand All @@ -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}"}
3 changes: 2 additions & 1 deletion 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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion fastapi/applications.py
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions fastapi/openapi/docs.py
Expand Up @@ -157,6 +157,7 @@ def get_swagger_ui_html(
"""
return HTMLResponse(html)


def get_scalar_html(
*,
openapi_url: Annotated[
Expand Down Expand Up @@ -247,6 +248,7 @@ def get_scalar_html(
"""
return HTMLResponse(html)


def get_redoc_html(
*,
openapi_url: Annotated[
Expand Down
2 changes: 2 additions & 0 deletions tests/test_application.py
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test_tutorial/test_custom_docs_ui/test_tutorial001.py
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 3a31862

Please sign in to comment.