|
|
from pydantic import BaseModel, Field, field_validator |
|
|
from typing import List, Union |
|
|
|
|
|
|
|
|
class ContinentStats(BaseModel): |
|
|
continent: str = Field(..., title="Continent Name", example="Asia") |
|
|
Total_Countries: int = Field(..., title="Total Number of Countries", example=48) |
|
|
Total_Population: int = Field(..., title="Total Population", example=4600000000) |
|
|
Average_Population: float = Field(..., title="Average Population Per Country", example=96000000) |
|
|
Total_Area: int = Field(..., title="Total Land Area (sq km)", example=44679000) |
|
|
max_population: int = Field(..., title="Highest Country Population", example=1400000000) |
|
|
min_population: int = Field(..., title="Lowest Country Population", example=100000) |
|
|
Population_Density: float = Field(..., title="Population Density (people/sq km)", example=103) |
|
|
|
|
|
@field_validator("Total_Countries", "Total_Population", "Total_Area", "max_population", "min_population") |
|
|
@classmethod |
|
|
def must_be_positive(cls, value): |
|
|
if value < 0: |
|
|
raise ValueError("Value must be non-negative") |
|
|
return value |
|
|
|