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

11 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from fastapi import FastAPI 1abcde

2from fastapi.routing import APIRoute 1abcde

3 

4app = FastAPI() 1abcde

5 

6 

7@app.get("/items/") 1abcde

8async def read_items(): 1abcde

9 return [{"item_id": "Foo"}] 1abcde

10 

11 

12def use_route_names_as_operation_ids(app: FastAPI) -> None: 1abcde

13 """ 

14 Simplify operation IDs so that generated API clients have simpler function 

15 names. 

16 

17 Should be called only after all routes have been added. 

18 """ 

19 for route in app.routes: 1abcde

20 if isinstance(route, APIRoute): 1abcde

21 route.operation_id = route.name # in this case, 'read_items' 1abcde

22 

23 

24use_route_names_as_operation_ids(app) 1abcde