| 1 |
from typing import Annotated |
| 2 |
|
| 3 |
from fastapi import FastAPI, Path |
| 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: Annotated[int, Path(title="The ID of the item to get", ge=0, le=1000)], |
| 19 |
q: str | None = None, |
| 20 |
item: Item | None = None, |
| 21 |
): |
| 22 |
results = {"item_id": item_id} |
| 23 |
if q: |
| 24 |
results.update({"q": q}) |
| 25 |
if item: |
| 26 |
results.update({"item": item}) |
| 27 |
return results |