Coverage for docs_src/custom_docs_ui/tutorial001.py: 100%
15 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from fastapi import FastAPI 1abcde
2from fastapi.openapi.docs import ( 1abcde
3 get_redoc_html,
4 get_swagger_ui_html,
5 get_swagger_ui_oauth2_redirect_html,
6)
8app = FastAPI(docs_url=None, redoc_url=None) 1abcde
11@app.get("/docs", include_in_schema=False) 1abcde
12async def custom_swagger_ui_html(): 1abcde
13 return get_swagger_ui_html( 1abcde
14 openapi_url=app.openapi_url,
15 title=app.title + " - Swagger UI",
16 oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
17 swagger_js_url="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js",
18 swagger_css_url="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css",
19 )
22@app.get(app.swagger_ui_oauth2_redirect_url, include_in_schema=False) 1abcde
23async def swagger_ui_redirect(): 1abcde
24 return get_swagger_ui_oauth2_redirect_html() 1abcde
27@app.get("/redoc", include_in_schema=False) 1abcde
28async def redoc_html(): 1abcde
29 return get_redoc_html( 1abcde
30 openapi_url=app.openapi_url,
31 title=app.title + " - ReDoc",
32 redoc_js_url="https://unpkg.com/redoc@next/bundles/redoc.standalone.js",
33 )
36@app.get("/users/{username}") 1abcde
37async def read_user(username: str): 1abcde
38 return {"message": f"Hello {username}"} 1abcde