Add Bird schema
This commit is contained in:
parent
d652ee0add
commit
c2515c776b
27
schemas/bird.py
Normal file
27
schemas/bird.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
# Base schema
|
||||||
|
class BirdBase(BaseModel):
|
||||||
|
name: str = Field(..., description="Name of the bird")
|
||||||
|
species: str = Field(..., description="Species of the bird")
|
||||||
|
description: str | None = Field(None, description="Description of the bird")
|
||||||
|
age: int | None = Field(None, description="Age of the bird")
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"name": "Tweety",
|
||||||
|
"species": "Canary",
|
||||||
|
"description": "A cheerful little bird",
|
||||||
|
"age": 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Schema for creating a new bird
|
||||||
|
class BirdCreate(BirdBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Schema for bird responses
|
||||||
|
class Bird(BirdBase):
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
Loading…
x
Reference in New Issue
Block a user