@@ -25,23 +25,23 @@ async def list_items(
25
25
skip : int = Query (0 , description = "Number of items to skip" ),
26
26
limit : int = Query (10 , description = "Max number of items to return" ),
27
27
sort_by : Optional [str ] = Query (None , description = "Field to sort by" ),
28
- ):
28
+ ) -> List [ Item ] :
29
29
"""List all items with pagination and sorting options."""
30
30
return items [skip : skip + limit ]
31
31
32
32
@app .get ("/items/{item_id}" , response_model = Item , tags = ["items" ], operation_id = "get_item" )
33
33
async def read_item (
34
34
item_id : int = Path (..., description = "The ID of the item to retrieve" ),
35
35
include_details : bool = Query (False , description = "Include additional details" ),
36
- ):
36
+ ) -> Item :
37
37
"""Get a specific item by its ID with optional details."""
38
38
found_item = next ((item for item in items if item .id == item_id ), None )
39
39
if found_item is None :
40
40
raise HTTPException (status_code = 404 , detail = "Item not found" )
41
41
return found_item
42
42
43
43
@app .post ("/items/" , response_model = Item , tags = ["items" ], operation_id = "create_item" )
44
- async def create_item (item : Item = Body (..., description = "The item to create" )):
44
+ async def create_item (item : Item = Body (..., description = "The item to create" )) -> Item :
45
45
"""Create a new item in the database."""
46
46
items .append (item )
47
47
return item
@@ -50,18 +50,18 @@ async def create_item(item: Item = Body(..., description="The item to create")):
50
50
async def update_item (
51
51
item_id : int = Path (..., description = "The ID of the item to update" ),
52
52
item : Item = Body (..., description = "The updated item data" ),
53
- ):
53
+ ) -> Item :
54
54
"""Update an existing item."""
55
55
item .id = item_id
56
56
return item
57
57
58
58
@app .delete ("/items/{item_id}" , status_code = 204 , tags = ["items" ], operation_id = "delete_item" )
59
- async def delete_item (item_id : int = Path (..., description = "The ID of the item to delete" )):
59
+ async def delete_item (item_id : int = Path (..., description = "The ID of the item to delete" )) -> None :
60
60
"""Delete an item from the database."""
61
61
return None
62
62
63
- @app .get ("/error" , status_code = 200 , tags = ["error" ], operation_id = "raise_error" )
64
- async def raise_error ():
63
+ @app .get ("/error" , tags = ["error" ], operation_id = "raise_error" )
64
+ async def raise_error () -> None :
65
65
"""Fail on purpose and cause a 500 error."""
66
66
raise Exception ("This is a test error" )
67
67
0 commit comments