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

15 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) 

7 

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

9 

10 

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

12async def custom_swagger_ui_html(): 1abcd

13 return get_swagger_ui_html( 1efgh

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) 1abcd

23async def swagger_ui_redirect(): 1abcd

24 return get_swagger_ui_oauth2_redirect_html() 1ijkl

25 

26 

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

28async def redoc_html(): 1abcd

29 return get_redoc_html( 1mnop

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}") 1abcd

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

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