Debian Codegraph @

docs_src/custom_docs_ui/tutorial001_py310.py

raw
1 from fastapi import FastAPI
2 from fastapi.openapi.docs import (
3 get_redoc_html,
4 get_swagger_ui_html,
5 get_swagger_ui_oauth2_redirect_html,
6 )
7
8 app = FastAPI(docs_url=None, redoc_url=None)
9
10
11 @app.get("/docs", include_in_schema=False)
12 async def custom_swagger_ui_html():
13 return get_swagger_ui_html(
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 )
20
21
22 @app.get(app.swagger_ui_oauth2_redirect_url, include_in_schema=False)
23 async def swagger_ui_redirect():
24 return get_swagger_ui_oauth2_redirect_html()
25
26
27 @app.get("/redoc", include_in_schema=False)
28 async def redoc_html():
29 return get_redoc_html(
30 openapi_url=app.openapi_url,
31 title=app.title + " - ReDoc",
32 redoc_js_url="https://unpkg.com/redoc@2/bundles/redoc.standalone.js",
33 )
34
35
36 @app.get("/users/{username}")
37 async def read_user(username: str):
38 return {"message": f"Hello {username}"}