28 lines
756 B
Python
28 lines
756 B
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
|
|
class ColorBase(BaseModel):
|
|
name: str = Field(..., min_length=1, max_length=50, description="Color name")
|
|
hex_code: str = Field(..., min_length=7, max_length=7, pattern="^#[0-9A-Fa-f]{6}$", description="Color hex code")
|
|
|
|
class ColorCreate(ColorBase):
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "Forest Green",
|
|
"hex_code": "#228B22"
|
|
}
|
|
}
|
|
|
|
class Color(ColorBase):
|
|
id: int
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": 1,
|
|
"name": "Forest Green",
|
|
"hex_code": "#228B22"
|
|
}
|
|
} |