Files
fastapi/docs_src/extra_models/tutorial003_py310.py
Sebastián Ramírez faee822574 🎨 Upgrade typing syntax for Python 3.10 (#14932)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tiangolo <1326112+tiangolo@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-17 09:59:14 +00:00

34 lines
612 B
Python

from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class BaseItem(BaseModel):
description: str
type: str
class CarItem(BaseItem):
type: str = "car"
class PlaneItem(BaseItem):
type: str = "plane"
size: int
items = {
"item1": {"description": "All my friends drive a low rider", "type": "car"},
"item2": {
"description": "Music is my aeroplane, it's my aeroplane",
"type": "plane",
"size": 5,
},
}
@app.get("/items/{item_id}", response_model=PlaneItem | CarItem)
async def read_item(item_id: str):
return items[item_id]