28 lines
761 B
Python
28 lines
761 B
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
|
|
# Base schema
|
|
class DogBase(BaseModel):
|
|
name: str = Field(..., description="Name of the dog")
|
|
breed: str = Field(..., description="Breed of the dog")
|
|
age: int = Field(..., gt=0, description="Age of the dog in years")
|
|
owner_id: Optional[str] = Field(None, description="ID of the owner (foreign key)")
|
|
|
|
# Schema for creating a new Dog
|
|
class DogCreate(DogBase):
|
|
pass
|
|
|
|
# Schema for Dog responses
|
|
class Dog(DogBase):
|
|
id: int
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "Buddy",
|
|
"breed": "Labrador",
|
|
"age": 5,
|
|
"owner_id": "user123"
|
|
}
|
|
} |