Coverage for docs_src / path_operation_advanced_configuration / tutorial002_py310.py: 100%
11 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1from fastapi import FastAPI 1abcd
2from fastapi.routing import APIRoute 1abcd
4app = FastAPI() 1abcd
7@app.get("/items/") 1abcd
8async def read_items(): 1abcd
9 return [{"item_id": "Foo"}] 1efg
12def use_route_names_as_operation_ids(app: FastAPI) -> None: 1abcd
13 """
14 Simplify operation IDs so that generated API clients have simpler function
15 names.
17 Should be called only after all routes have been added.
18 """
19 for route in app.routes: 1abcd
20 if isinstance(route, APIRoute): 1abcd
21 route.operation_id = route.name # in this case, 'read_items' 1abcd
24use_route_names_as_operation_ids(app) 1abcd