Coverage for docs_src/path_operation_advanced_configuration/tutorial004.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
1from typing import Set, Union 1abcdefg
3from fastapi import FastAPI 1abcdefg
4from pydantic import BaseModel 1abcdefg
6app = FastAPI() 1abcdefg
9class Item(BaseModel): 1abcdefg
10 name: str 1abcdefg
11 description: Union[str, None] = None 1abcdefg
12 price: float 1abcdefg
13 tax: Union[float, None] = None 1abcdefg
14 tags: Set[str] = set() 1abcdefg
17@app.post("/items/", response_model=Item, summary="Create an item") 1abcdefg
18async def create_item(item: Item): 1abcdefg
19 """
20 Create an item with all the information:
22 - **name**: each item must have a name
23 - **description**: a long description
24 - **price**: required
25 - **tax**: if the item doesn't have tax, you can omit this
26 - **tags**: a set of unique tag strings for this item
27 \f
28 :param item: User input.
29 """
30 return item 1hijklmn