34 lines
944 B
Python
34 lines
944 B
Python
from pydantic import BaseModel, Field, EmailStr
|
|
from typing import Optional
|
|
|
|
class UserBase(BaseModel):
|
|
username: str = Field(..., min_length=3, max_length=50)
|
|
email: EmailStr = Field(...)
|
|
full_name: str = Field(..., min_length=1, max_length=100)
|
|
|
|
class UserCreate(UserBase):
|
|
password: str = Field(..., min_length=8, max_length=100)
|
|
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"username": "johndoe",
|
|
"email": "john@example.com",
|
|
"full_name": "John Doe",
|
|
"password": "securepass123"
|
|
}
|
|
}
|
|
|
|
class UserResponse(UserBase):
|
|
is_active: bool = True
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"username": "johndoe",
|
|
"email": "john@example.com",
|
|
"full_name": "John Doe",
|
|
"is_active": True
|
|
}
|
|
} |