2022-05-13 18:38:22 -05:00
|
|
|
from typing import Union
|
2020-06-28 20:13:30 +02:00
|
|
|
|
2018-12-18 21:59:06 +04:00
|
|
|
from fastapi import Body, FastAPI
|
2019-11-27 11:32:02 -08:00
|
|
|
from pydantic import BaseModel, Field
|
2018-12-18 21:59:06 +04:00
|
|
|
|
2018-12-14 19:42:46 +04:00
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
name: str
|
2022-05-13 18:38:22 -05:00
|
|
|
description: Union[str, None] = Field(
|
|
|
|
|
default=None, title="The description of the item", max_length=300
|
2020-06-28 20:13:30 +02:00
|
|
|
)
|
2022-05-13 18:38:22 -05:00
|
|
|
price: float = Field(gt=0, description="The price must be greater than zero")
|
|
|
|
|
tax: Union[float, None] = None
|
2018-12-14 19:42:46 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.put("/items/{item_id}")
|
2022-05-13 18:38:22 -05:00
|
|
|
async def update_item(item_id: int, item: Item = Body(embed=True)):
|
2018-12-14 19:42:46 +04:00
|
|
|
results = {"item_id": item_id, "item": item}
|
|
|
|
|
return results
|