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

17 statements  

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

7from fastapi.staticfiles import StaticFiles 1abcde

8 

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

10 

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

12 

13 

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

15async def custom_swagger_ui_html(): 1abcde

16 return get_swagger_ui_html( 1abcde

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

26async def swagger_ui_redirect(): 1abcde

27 return get_swagger_ui_oauth2_redirect_html() 1abcde

28 

29 

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

31async def redoc_html(): 1abcde

32 return get_redoc_html( 1abcde

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

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

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