mirror of https://github.com/tiangolo/fastapi.git
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
This commit is contained in:
parent
a1f31ea018
commit
67f3f58dbc
|
|
@ -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}"}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -1073,7 +1073,7 @@ class FastAPI(Starlette):
|
|||
)
|
||||
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -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[
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue