| 1 |
from fastapi import Body, FastAPI |
| 2 |
from pydantic import BaseModel, Field |
| 3 |
|
| 4 |
app = FastAPI() |
| 5 |
|
| 6 |
|
| 7 |
class Item(BaseModel): |
| 8 |
name: str |
| 9 |
description: str | None = Field( |
| 10 |
default=None, title="The description of the item", max_length=300 |
| 11 |
) |
| 12 |
price: float = Field(gt=0, description="The price must be greater than zero") |
| 13 |
tax: float | None = None |
| 14 |
|
| 15 |
|
| 16 |
@app.put("/items/{item_id}") |
| 17 |
async def update_item(item_id: int, item: Item = Body(embed=True)): |
| 18 |
results = {"item_id": item_id, "item": item} |
| 19 |
return results |