from pydantic import BaseModel, Field, validator from typing import Optional, Union class MealBase(BaseModel): name: str = Field(..., description="Name of the meal") description: Optional[str] = Field(None, description="Description of the meal") price: float = Field(..., gt=0, description="Price of the meal") is_available: bool = Field(True, description="Availability status of the meal") category: Optional[str] = Field(None, description="Category of the meal") cuisine: Optional[str] = Field(None, description="Cuisine of the meal") dietary_restrictions: Optional[dict] = Field(None, description="Dietary restrictions for the meal") class Config: schema_extra = { "example": { "name": "Margherita Pizza", "description": "Classic Italian pizza with tomato sauce, mozzarella cheese, and fresh basil", "price": 12.99, "is_available": True, "category": "Pizza", "cuisine": "Italian", "dietary_restrictions": {"vegetarian": True, "nut_free": True} } } class MealCreate(MealBase): pass class MealResponse(MealBase): id: int = Field(..., description="Unique identifier for the meal") class Config: orm_mode = True