2025-03-25 15:50:09 -05:00

25 lines
590 B
Python

from pydantic import BaseModel, Field
# Base schema
class CarBase(BaseModel):
make: str = Field(..., description="Car make")
model: str = Field(..., description="Car model")
year: int = Field(..., gt=0, description="Car year")
# Schema for creating a new Car
class CarCreate(CarBase):
class Config:
schema_extra = {
"example": {
"make": "Toyota",
"model": "Camry",
"year": 2022
}
}
# Schema for Car responses
class Car(CarBase):
id: int
class Config:
orm_mode = True