2025-03-26 17:07:19 +00:00

49 lines
1.7 KiB
Python

from pydantic import BaseModel, Field
from typing import Optional
class UserBase(BaseModel):
name: str = Field(..., index=True, description="Product name")
brand: str = Field(..., description="Product brand")
category: str = Field(..., description="Product category")
size: str = Field(..., description="Product size")
color: str = Field(..., description="Product color")
price: float = Field(..., gt=0, description="Product price")
description: Optional[str] = Field(None, description="Product description")
stock_quantity: int = Field(default=0, ge=0, description="Available stock quantity")
is_available: bool = Field(default=True, description="Product availability status")
class UserCreate(UserBase):
class Config:
schema_extra = {
"example": {
"name": "Classic T-Shirt",
"brand": "BrandName",
"category": "Clothing",
"size": "M",
"color": "Blue",
"price": 29.99,
"description": "Comfortable cotton t-shirt",
"stock_quantity": 100,
"is_available": True
}
}
class User(UserBase):
id: int = Field(..., description="Product ID")
class Config:
orm_mode = True
schema_extra = {
"example": {
"id": 1,
"name": "Classic T-Shirt",
"brand": "BrandName",
"category": "Clothing",
"size": "M",
"color": "Blue",
"price": 29.99,
"description": "Comfortable cotton t-shirt",
"stock_quantity": 100,
"is_available": True
}
}