diff --git a/schemas/lake.py b/schemas/lake.py new file mode 100644 index 0000000..efa8b98 --- /dev/null +++ b/schemas/lake.py @@ -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 \ No newline at end of file