Coverage for docs_src / body_multiple_params / tutorial004_py310.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1from fastapi import Body, FastAPI 1abefcd

2from pydantic import BaseModel 1abefcd

3 

4app = FastAPI() 1abefcd

5 

6 

7class Item(BaseModel): 1abefcd

8 name: str 1abcd

9 description: str | None = None 1abefcd

10 price: float 1abcd

11 tax: float | None = None 1abefcd

12 

13 

14class User(BaseModel): 1abefcd

15 username: str 1abcd

16 full_name: str | None = None 1abefcd

17 

18 

19@app.put("/items/{item_id}") 1abefcd

20async def update_item( 1abefcd

21 *, 

22 item_id: int, 

23 item: Item, 

24 user: User, 

25 importance: int = Body(gt=0), 

26 q: str | None = None, 

27): 

28 results = {"item_id": item_id, "item": item, "user": user, "importance": importance} 1gkhiljm

29 if q: 1gkhiljm

30 results.update({"q": q}) 1ghij

31 return results 1gkhiljm