from pydantic import BaseModel, Field from typing import Optional class PenBase(BaseModel): name: str = Field(..., min_length=1, max_length=100, description="Name of the pen") brand: str = Field(..., min_length=1, max_length=50, description="Brand of the pen") color: str = Field(..., min_length=1, max_length=30, description="Color of the pen") price: int = Field(..., gt=0, description="Price of the pen in cents") in_stock: bool = Field(default=True, description="Whether the pen is in stock") description: Optional[str] = Field(None, max_length=500, description="Optional description of the pen") class PenCreate(PenBase): class Config: schema_extra = { "example": { "name": "Ballpoint Pen", "brand": "Parker", "color": "Blue", "price": 499, "in_stock": True, "description": "Smooth writing ballpoint pen with medium tip" } } class Pen(PenBase): id: int = Field(..., description="Unique identifier for the pen") class Config: orm_mode = True schema_extra = { "example": { "id": 1, "name": "Ballpoint Pen", "brand": "Parker", "color": "Blue", "price": 499, "in_stock": True, "description": "Smooth writing ballpoint pen with medium tip" } }