2022-05-14 06:59:59 -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
|
2018-12-18 22:36:04 +04:00
|
|
|
from pydantic import BaseModel
|
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-14 06:59:59 -05:00
|
|
|
description: Union[str, None] = None
|
2018-12-14 19:42:46 +04:00
|
|
|
price: float
|
2022-05-14 06:59:59 -05:00
|
|
|
tax: Union[float, None] = None
|
2018-12-14 19:42:46 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.put("/items/{item_id}")
|
|
|
|
|
async def update_item(
|
|
|
|
|
item_id: int,
|
|
|
|
|
item: Item = Body(
|
2023-06-30 20:25:16 +02:00
|
|
|
examples=[
|
|
|
|
|
{
|
|
|
|
|
"name": "Foo",
|
|
|
|
|
"description": "A very nice Item",
|
|
|
|
|
"price": 35.4,
|
|
|
|
|
"tax": 3.2,
|
|
|
|
|
}
|
|
|
|
|
],
|
2020-06-13 01:11:44 +05:30
|
|
|
),
|
2018-12-14 19:42:46 +04:00
|
|
|
):
|
|
|
|
|
results = {"item_id": item_id, "item": item}
|
|
|
|
|
return results
|