mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-31 02:00:34 -05:00
Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com> Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
22 lines
561 B
Python
22 lines
561 B
Python
from typing import Union
|
|
|
|
from fastapi import Body, FastAPI
|
|
from pydantic import BaseModel, Field
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class Item(BaseModel):
|
|
name: str
|
|
description: Union[str, None] = Field(
|
|
default=None, title="The description of the item", max_length=300
|
|
)
|
|
price: float = Field(gt=0, description="The price must be greater than zero")
|
|
tax: Union[float, None] = None
|
|
|
|
|
|
@app.put("/items/{item_id}")
|
|
async def update_item(item_id: int, item: Item = Body(embed=True)):
|
|
results = {"item_id": item_id, "item": item}
|
|
return results
|