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

11 statements  

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

1from fastapi import FastAPI 1abcdef

2from fastapi.routing import APIRoute 1abcdef

3 

4app = FastAPI() 1abcdef

5 

6 

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

8async def read_items(): 1abcdef

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

10 

11 

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

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

20 if isinstance(route, APIRoute): 1abcdef

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

22 

23 

24use_route_names_as_operation_ids(app) 1abcdef