40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
|
|
class ProductBase(BaseModel):
|
|
name: str = Field(..., min_length=1, description="Product name")
|
|
description: Optional[str] = Field(None, description="Product description")
|
|
price: float = Field(..., gt=0, description="Product price")
|
|
stock: int = Field(default=0, ge=0, description="Product stock quantity")
|
|
sku: str = Field(..., min_length=1, description="Product SKU")
|
|
is_active: bool = Field(default=True, description="Product status")
|
|
|
|
class ProductCreate(ProductBase):
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "Sample Product",
|
|
"description": "A detailed product description",
|
|
"price": 29.99,
|
|
"stock": 100,
|
|
"sku": "PROD-001",
|
|
"is_active": True
|
|
}
|
|
}
|
|
|
|
class Product(ProductBase):
|
|
id: int = Field(..., description="Product ID")
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": 1,
|
|
"name": "Sample Product",
|
|
"description": "A detailed product description",
|
|
"price": 29.99,
|
|
"stock": 100,
|
|
"sku": "PROD-001",
|
|
"is_active": True
|
|
}
|
|
} |