- Sort Score
- Num 10 results
- Language All
Results 1 - 2 of 2 for OtherItem (0.41 seconds)
-
tests/test_union_body.py
from fastapi.testclient import TestClient from pydantic import BaseModel app = FastAPI() class Item(BaseModel): name: Optional[str] = None class OtherItem(BaseModel): price: int @app.post("/items/") def save_union_body(item: Union[OtherItem, Item]): return {"item": item} client = TestClient(app) def test_post_other_item(): response = client.post("/items/", json={"price": 100})
Created: Sun Dec 28 07:19:09 GMT 2025 - Last Modified: Sat Dec 27 18:19:10 GMT 2025 - 4.3K bytes - Click Count (0) -
tests/test_union_body_discriminator.py
app = FastAPI() class FirstItem(BaseModel): value: Literal["first"] price: int class OtherItem(BaseModel): value: Literal["other"] price: float Item = Annotated[ Union[Annotated[FirstItem, Tag("first")], Annotated[OtherItem, Tag("other")]], Field(discriminator="value"), ] @app.post("/items/") def save_union_body_discriminator(Created: Sun Dec 28 07:19:09 GMT 2025 - Last Modified: Sat Dec 27 18:19:10 GMT 2025 - 7.1K bytes - Click Count (0)