Add Person schema
This commit is contained in:
parent
68daa197ac
commit
e649c2cdfd
40
schemas/person.py
Normal file
40
schemas/person.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
from pydantic import BaseModel, Field, EmailStr
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
class PersonBase(BaseModel):
|
||||||
|
first_name: str = Field(..., min_length=1, description="Person's first name")
|
||||||
|
last_name: str = Field(..., min_length=1, description="Person's last name")
|
||||||
|
age: int = Field(..., gt=0, description="Person's age")
|
||||||
|
email: EmailStr = Field(..., description="Person's email address")
|
||||||
|
phone: Optional[str] = Field(None, description="Person's phone number")
|
||||||
|
is_active: bool = Field(default=True, description="Active status")
|
||||||
|
|
||||||
|
class PersonCreate(PersonBase):
|
||||||
|
class Config:
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"first_name": "John",
|
||||||
|
"last_name": "Doe",
|
||||||
|
"age": 30,
|
||||||
|
"email": "john.doe@example.com",
|
||||||
|
"phone": "+1234567890",
|
||||||
|
"is_active": True
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Person(PersonBase):
|
||||||
|
id: int = Field(..., description="Person's unique identifier")
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"id": 1,
|
||||||
|
"first_name": "John",
|
||||||
|
"last_name": "Doe",
|
||||||
|
"age": 30,
|
||||||
|
"email": "john.doe@example.com",
|
||||||
|
"phone": "+1234567890",
|
||||||
|
"is_active": True
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user