Coverage for docs_src / custom_docs_ui / tutorial002_py310.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1from fastapi import FastAPI 1abcd

2from fastapi.openapi.docs import ( 1abcd

3 get_redoc_html, 

4 get_swagger_ui_html, 

5 get_swagger_ui_oauth2_redirect_html, 

6) 

7from fastapi.staticfiles import StaticFiles 1abcd

8 

9app = FastAPI(docs_url=None, redoc_url=None) 1abcd

10 

11app.mount("/static", StaticFiles(directory="static"), name="static") 1abcd

12 

13 

14@app.get("/docs", include_in_schema=False) 1abcd

15async def custom_swagger_ui_html(): 1abcd

16 return get_swagger_ui_html( 1efgh

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 ) 

23 

24 

25@app.get(app.swagger_ui_oauth2_redirect_url, include_in_schema=False) 1abcd

26async def swagger_ui_redirect(): 1abcd

27 return get_swagger_ui_oauth2_redirect_html() 1ijkl

28 

29 

30@app.get("/redoc", include_in_schema=False) 1abcd

31async def redoc_html(): 1abcd

32 return get_redoc_html( 1mnop

33 openapi_url=app.openapi_url, 

34 title=app.title + " - ReDoc", 

35 redoc_js_url="/static/redoc.standalone.js", 

36 ) 

37 

38 

39@app.get("/users/{username}") 1abcd

40async def read_user(username: str): 1abcd

41 return {"message": f"Hello {username}"} 1qrst