- Sort Score
- Result 10 results
- Languages All
Results 1 - 2 of 2 for OtherItem (0.11 sec)
-
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})
Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Dec 27 18:19:10 UTC 2025 - 4.3K bytes - Viewed (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(Registered: Sun Dec 28 07:19:09 UTC 2025 - Last Modified: Sat Dec 27 18:19:10 UTC 2025 - 7.1K bytes - Viewed (0)