35 lines
982 B
Python
35 lines
982 B
Python
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 |