46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
|
|
class DogBase(BaseModel):
|
|
name: str = Field(..., min_length=1, max_length=50, description="Dog's name")
|
|
breed: str = Field(..., min_length=1, max_length=50, description="Dog's breed")
|
|
age: Optional[int] = Field(None, ge=0, le=30, description="Dog's age in years")
|
|
color: Optional[str] = Field(None, max_length=30, description="Dog's color")
|
|
weight: Optional[int] = Field(None, ge=0, le=200, description="Dog's weight in pounds")
|
|
is_vaccinated: bool = Field(default=False, description="Vaccination status")
|
|
owner_name: Optional[str] = Field(None, max_length=100, description="Owner's full name")
|
|
owner_contact: Optional[str] = Field(None, max_length=100, description="Owner's contact information")
|
|
|
|
class DogCreate(DogBase):
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "Max",
|
|
"breed": "Golden Retriever",
|
|
"age": 3,
|
|
"color": "Golden",
|
|
"weight": 70,
|
|
"is_vaccinated": True,
|
|
"owner_name": "John Doe",
|
|
"owner_contact": "+1-555-0123"
|
|
}
|
|
}
|
|
|
|
class Dog(DogBase):
|
|
id: int = Field(..., description="The unique identifier for the dog")
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": 1,
|
|
"name": "Max",
|
|
"breed": "Golden Retriever",
|
|
"age": 3,
|
|
"color": "Golden",
|
|
"weight": 70,
|
|
"is_vaccinated": True,
|
|
"owner_name": "John Doe",
|
|
"owner_contact": "+1-555-0123"
|
|
}
|
|
} |