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