35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from uuid import UUID
|
|
|
|
class FruitBase(BaseModel):
|
|
name: str = Field(..., min_length=1, description="Name of the fruit")
|
|
color: str = Field(..., min_length=1, description="Color of the fruit")
|
|
shape: str = Field(..., min_length=1, description="Shape of the fruit")
|
|
|
|
class FruitCreate(FruitBase):
|
|
pass
|
|
|
|
class FruitUpdate(BaseModel):
|
|
name: Optional[str] = Field(None, min_length=1, description="Name of the fruit")
|
|
color: Optional[str] = Field(None, min_length=1, description="Color of the fruit")
|
|
shape: Optional[str] = Field(None, min_length=1, description="Shape of the fruit")
|
|
|
|
class FruitSchema(FruitBase):
|
|
id: UUID
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
|
|
"name": "Apple",
|
|
"color": "Red",
|
|
"shape": "Round",
|
|
"created_at": "2023-01-01T12:00:00",
|
|
"updated_at": "2023-01-01T12:00:00"
|
|
}
|
|
} |