Add Flower schema
This commit is contained in:
parent
e19b53537b
commit
249e6cef1a
35
schemas/flower.py
Normal file
35
schemas/flower.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
# Base schema
|
||||||
|
class FlowerBase(BaseModel):
|
||||||
|
name: str = Field(..., description="Name of the flower")
|
||||||
|
description: str | None = Field(None, description="Description of the flower")
|
||||||
|
color: str | None = Field(None, description="Color of the flower")
|
||||||
|
price: int = Field(..., description="Price of the flower")
|
||||||
|
|
||||||
|
# Schema for creating a new Flower
|
||||||
|
class FlowerCreate(FlowerBase):
|
||||||
|
class Config:
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"name": "Rose",
|
||||||
|
"description": "A beautiful red flower",
|
||||||
|
"color": "red",
|
||||||
|
"price": 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Schema for Flower responses
|
||||||
|
class Flower(FlowerBase):
|
||||||
|
id: int
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"id": 1,
|
||||||
|
"name": "Rose",
|
||||||
|
"description": "A beautiful red flower",
|
||||||
|
"color": "red",
|
||||||
|
"price": 10
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user