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

17 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1from typing import Annotated, Union 1abcd

2 

3from fastapi import FastAPI, Path 1abcd

4from pydantic import BaseModel 1abcd

5 

6app = FastAPI() 1abcd

7 

8 

9class Item(BaseModel): 1abcd

10 name: str 1abcd

11 description: Union[str, None] = None 1abcd

12 price: float 1abcd

13 tax: Union[float, None] = None 1abcd

14 

15 

16@app.put("/items/{item_id}") 1abcd

17async def update_item( 1abcd

18 item_id: Annotated[int, Path(title="The ID of the item to get", ge=0, le=1000)], 

19 q: Union[str, None] = None, 

20 item: Union[Item, None] = None, 

21): 

22 results = {"item_id": item_id} 1abcd

23 if q: 1abcd

24 results.update({"q": q}) 1abcd

25 if item: 1abcd

26 results.update({"item": item}) 1abcd

27 return results 1abcd