Add Lake schema
This commit is contained in:
parent
6d84741c09
commit
c0c8f47569
35
schemas/lake.py
Normal file
35
schemas/lake.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
from pydantic import BaseModel, Field, validator
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
class BaseLake(BaseModel):
|
||||||
|
name: str = Field(..., index=True, description="Name of the lake")
|
||||||
|
area: float = Field(..., gt=0, description="Area of the lake in square kilometers")
|
||||||
|
depth: float = Field(..., gt=0, description="Maximum depth of the lake in meters")
|
||||||
|
location: str = Field(..., description="Location or address of the lake")
|
||||||
|
|
||||||
|
@validator('name')
|
||||||
|
def name_must_be_capitalized(cls, value):
|
||||||
|
if not value.istitle():
|
||||||
|
raise ValueError('Lake name must be capitalized')
|
||||||
|
return value
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"name": "Lake Superior",
|
||||||
|
"area": 82100.0,
|
||||||
|
"depth": 406.0,
|
||||||
|
"location": "North America"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class LakeCreate(BaseLake):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class LakeResponse(BaseLake):
|
||||||
|
id: int
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
orm_mode = True
|
Loading…
x
Reference in New Issue
Block a user