34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
from pydantic import BaseModel, Field, EmailStr
|
|
from typing import Optional
|
|
|
|
class UserBase(BaseModel):
|
|
name: str = Field(..., min_length=1, max_length=100, description="User's full name")
|
|
address: str = Field(..., min_length=1, max_length=200, description="User's address")
|
|
phone: Optional[str] = Field(None, max_length=20, description="User's phone number")
|
|
email: EmailStr = Field(..., description="User's email address")
|
|
is_active: bool = Field(default=True, description="User's active status")
|
|
|
|
class UserCreate(UserBase):
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "John Doe",
|
|
"address": "123 Main St, City, Country",
|
|
"phone": "+1234567890",
|
|
"email": "john@example.com",
|
|
"is_active": True
|
|
}
|
|
}
|
|
|
|
class UserResponse(UserBase):
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "John Doe",
|
|
"address": "123 Main St, City, Country",
|
|
"phone": "+1234567890",
|
|
"email": "john@example.com",
|
|
"is_active": True
|
|
}
|
|
} |