| 1 |
from typing import Annotated |
| 2 |
|
| 3 |
from fastapi import Body, FastAPI |
| 4 |
from pydantic import BaseModel |
| 5 |
|
| 6 |
app = FastAPI() |
| 7 |
|
| 8 |
|
| 9 |
class Item(BaseModel): |
| 10 |
name: str |
| 11 |
description: str | None = None |
| 12 |
price: float |
| 13 |
tax: float | None = None |
| 14 |
|
| 15 |
|
| 16 |
@app.put("/items/{item_id}") |
| 17 |
async def update_item( |
| 18 |
item_id: int, |
| 19 |
item: Annotated[ |
| 20 |
Item, |
| 21 |
Body( |
| 22 |
examples=[ |
| 23 |
{ |
| 24 |
"name": "Foo", |
| 25 |
"description": "A very nice Item", |
| 26 |
"price": 35.4, |
| 27 |
"tax": 3.2, |
| 28 |
} |
| 29 |
], |
| 30 |
), |
| 31 |
], |
| 32 |
): |
| 33 |
results = {"item_id": item_id, "item": item} |
| 34 |
return results |