Add Product schema
This commit is contained in:
parent
5126073f24
commit
621db14717
40
schemas/product.py
Normal file
40
schemas/product.py
Normal file
@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user