27 lines
721 B
Python
27 lines
721 B
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
|
|
class DogBase(BaseModel):
|
|
name: str = Field(..., description="Dog's name")
|
|
breed: str = Field(..., description="Dog's breed")
|
|
age: int = Field(..., gt=0, description="Dog's age in years")
|
|
owner_id: Optional[str] = Field(None, description="ID of the dog's owner")
|
|
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "Buddy",
|
|
"breed": "Labrador",
|
|
"age": 5,
|
|
"owner_id": "123e4567-e89b-12d3-a456-426614174000"
|
|
}
|
|
}
|
|
|
|
class DogCreate(DogBase):
|
|
pass
|
|
|
|
class DogResponse(DogBase):
|
|
id: int
|
|
|
|
class Config:
|
|
orm_mode = True |