Coverage for docs_src / custom_docs_ui / tutorial002_py310.py: 100%
17 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from fastapi import FastAPI 1abc
2from fastapi.openapi.docs import ( 1abc
3 get_redoc_html,
4 get_swagger_ui_html,
5 get_swagger_ui_oauth2_redirect_html,
6)
7from fastapi.staticfiles import StaticFiles 1abc
9app = FastAPI(docs_url=None, redoc_url=None) 1abc
11app.mount("/static", StaticFiles(directory="static"), name="static") 1abc
14@app.get("/docs", include_in_schema=False) 1abc
15async def custom_swagger_ui_html(): 1abc
16 return get_swagger_ui_html( 1def
17 openapi_url=app.openapi_url,
18 title=app.title + " - Swagger UI",
19 oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
20 swagger_js_url="/static/swagger-ui-bundle.js",
21 swagger_css_url="/static/swagger-ui.css",
22 )
25@app.get(app.swagger_ui_oauth2_redirect_url, include_in_schema=False) 1abc
26async def swagger_ui_redirect(): 1abc
27 return get_swagger_ui_oauth2_redirect_html() 1ghi
30@app.get("/redoc", include_in_schema=False) 1abc
31async def redoc_html(): 1abc
32 return get_redoc_html( 1jkl
33 openapi_url=app.openapi_url,
34 title=app.title + " - ReDoc",
35 redoc_js_url="/static/redoc.standalone.js",
36 )
39@app.get("/users/{username}") 1abc
40async def read_user(username: str): 1abc
41 return {"message": f"Hello {username}"} 1mno