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

11 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-04 08:29 +0000

1from fastapi import FastAPI 1abcdefg

2from fastapi.routing import APIRoute 1abcdefg

3 

4app = FastAPI() 1abcdefg

5 

6 

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

8async def read_items(): 1abcdefg

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

10 

11 

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

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: 1abcdefg

20 if isinstance(route, APIRoute): 1abcdefg

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

22 

23 

24use_route_names_as_operation_ids(app) 1abcdefg