2022-05-14 06:59:59 -05:00
|
|
|
from typing import Union
|
2020-06-28 20:13:30 +02:00
|
|
|
|
2020-03-29 21:43:31 +02:00
|
|
|
from fastapi import FastAPI
|
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
2022-05-13 18:38:22 -05:00
|
|
|
name: str = Field(example="Foo")
|
2022-05-14 06:59:59 -05:00
|
|
|
description: Union[str, None] = Field(default=None, example="A very nice Item")
|
2022-05-13 18:38:22 -05:00
|
|
|
price: float = Field(example=35.4)
|
2022-05-14 06:59:59 -05:00
|
|
|
tax: Union[float, None] = Field(default=None, example=3.2)
|
2020-03-29 21:43:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.put("/items/{item_id}")
|
2020-06-13 01:11:44 +05:30
|
|
|
async def update_item(item_id: int, item: Item):
|
2020-03-29 21:43:31 +02:00
|
|
|
results = {"item_id": item_id, "item": item}
|
|
|
|
|
return results
|