mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-04 13:44:20 -04:00
* Make compatible with pydantic v1 * Remove unused import * Remove unused ignores * Update pydantic version * Fix minor formatting issue * ⏪ Revert removing iterate_in_threadpool * ✨ Add backwards compatibility with Pydantic 0.32.2 with deprecation warnings * ✅ Update tests to not break when using Pydantic < 1.0.0 * 📝 Update docs for Pydantic version 1.0.0 * 📌 Update Pydantic range version to support from 0.32.2 * 🎨 Format test imports * ✨ Add support for Pydantic < 1.2 for populate_validators * ✨ Add backwards compatibility for Pydantic < 1.2.0 with required fields * 📌 Relax requirement for Pydantic to < 2.0.0 🎉 🚀 * 💚 Update pragma coverage for older Pydantic versions
18 lines
500 B
Python
18 lines
500 B
Python
from fastapi import Body, FastAPI
|
|
from pydantic import BaseModel, Field
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class Item(BaseModel):
|
|
name: str
|
|
description: str = Field(None, title="The description of the item", max_length=300)
|
|
price: float = Field(..., gt=0, description="The price must be greater than zero")
|
|
tax: float = 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
|