54 lines
1.9 KiB
Python

from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime
from uuid import UUID
class FruitName(BaseModel):
name: str = Field(..., min_length=1, description="Fruit name")
class FruitBase(BaseModel):
name: str = Field(..., min_length=1, max_length=255, description="Fruit name")
description: Optional[str] = Field(None, description="Fruit description")
color: Optional[str] = Field(None, max_length=50, description="Fruit color")
is_active: bool = Field(True, description="Whether the fruit is active")
is_ripe: bool = Field(False, description="Whether the fruit is ripe")
class FruitCreate(FruitBase):
pass
class FruitUpdate(BaseModel):
name: Optional[str] = Field(None, min_length=1, max_length=255, description="Fruit name")
description: Optional[str] = Field(None, description="Fruit description")
color: Optional[str] = Field(None, max_length=50, description="Fruit color")
is_active: Optional[bool] = Field(None, description="Whether the fruit is active")
is_ripe: Optional[bool] = Field(None, description="Whether the fruit is ripe")
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",
"description": "A sweet, edible fruit produced by an apple tree",
"color": "Red",
"is_active": True,
"is_ripe": False,
"created_at": "2023-01-01T12:00:00",
"updated_at": "2023-01-01T12:00:00"
}
}
class FruitNameList(BaseModel):
fruits: List[str]
class Config:
schema_extra = {
"example": {
"fruits": ["Apple", "Banana", "Orange"]
}
}