37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
from pydantic import BaseModel, Field, EmailStr
|
|
from typing import Optional
|
|
|
|
class PersonBase(BaseModel):
|
|
first_name: str = Field(..., min_length=1, max_length=50)
|
|
last_name: str = Field(..., min_length=1, max_length=50)
|
|
email: EmailStr = Field(..., description="Person's email address")
|
|
phone_number: Optional[str] = Field(None, max_length=20)
|
|
address: Optional[str] = Field(None, max_length=200)
|
|
|
|
class PersonCreate(PersonBase):
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"first_name": "John",
|
|
"last_name": "Doe",
|
|
"email": "john.doe@example.com",
|
|
"phone_number": "+1234567890",
|
|
"address": "123 Main St, City, Country"
|
|
}
|
|
}
|
|
|
|
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",
|
|
"email": "john.doe@example.com",
|
|
"phone_number": "+1234567890",
|
|
"address": "123 Main St, City, Country"
|
|
}
|
|
} |