Add Pen schema
This commit is contained in:
parent
09b8b47c6d
commit
b2f0ecc293
31
schemas/pen.py
Normal file
31
schemas/pen.py
Normal file
@ -0,0 +1,31 @@
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
# Base schema
|
||||
class PenBase(BaseModel):
|
||||
name: str = Field(..., description="Name of the pen")
|
||||
color: str = Field(..., description="Color of the pen")
|
||||
brand: str = Field(..., description="Brand of the pen")
|
||||
price: int = Field(..., gt=0, description="Price of the pen")
|
||||
stock: int = Field(..., ge=0, description="Stock quantity of the pen")
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"name": "Classic Pen",
|
||||
"color": "Blue",
|
||||
"brand": "PenBrand",
|
||||
"price": 5,
|
||||
"stock": 100
|
||||
}
|
||||
}
|
||||
|
||||
# Schema for creating a new Pen
|
||||
class PenCreate(PenBase):
|
||||
pass
|
||||
|
||||
# Schema for Pen responses
|
||||
class Pen(PenBase):
|
||||
id: int = Field(..., description="Unique identifier for the pen")
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
Loading…
x
Reference in New Issue
Block a user