mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-24 06:39:31 -05:00
Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com> Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
20 lines
517 B
Python
20 lines
517 B
Python
from typing import Union
|
|
|
|
from fastapi import FastAPI
|
|
from pydantic import BaseModel, Field
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class Item(BaseModel):
|
|
name: str = Field(examples=["Foo"])
|
|
description: Union[str, None] = Field(default=None, examples=["A very nice Item"])
|
|
price: float = Field(examples=[35.4])
|
|
tax: Union[float, None] = Field(default=None, examples=[3.2])
|
|
|
|
|
|
@app.put("/items/{item_id}")
|
|
async def update_item(item_id: int, item: Item):
|
|
results = {"item_id": item_id, "item": item}
|
|
return results
|