Add Dog schema
This commit is contained in:
parent
b1b9df2987
commit
9c7ee7157b
28
schemas/dog.py
Normal file
28
schemas/dog.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user