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 } }