2025-03-27 03:19:16 -05:00

27 lines
759 B
Python

from pydantic import BaseModel, Field
# Base schema
class BirdBase(BaseModel):
name: str = Field(..., description="Name of the bird")
species: str = Field(..., description="Species of the bird")
description: str | None = Field(None, description="Description of the bird")
age: int | None = Field(None, description="Age of the bird")
class Config:
schema_extra = {
"example": {
"name": "Tweety",
"species": "Canary",
"description": "A cheerful little bird",
"age": 2
}
}
# Schema for creating a new bird
class BirdCreate(BirdBase):
pass
# Schema for bird responses
class Bird(BirdBase):
class Config:
orm_mode = True