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

17 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-05-05 00:03 +0000

1from fastapi import FastAPI 1abcdef

2from fastapi.openapi.docs import ( 1abcdef

3 get_redoc_html, 

4 get_swagger_ui_html, 

5 get_swagger_ui_oauth2_redirect_html, 

6) 

7from fastapi.staticfiles import StaticFiles 1abcdef

8 

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

10 

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

12 

13 

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

15async def custom_swagger_ui_html(): 1abcdef

16 return get_swagger_ui_html( 1ghijkl

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

26async def swagger_ui_redirect(): 1abcdef

27 return get_swagger_ui_oauth2_redirect_html() 1mnopqr

28 

29 

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

31async def redoc_html(): 1abcdef

32 return get_redoc_html( 1stuvwx

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

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

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