from pydantic import BaseModel, Field from typing import Optional class CountryBase(BaseModel): name: str = Field(..., description="Country name") code: str = Field(..., description="Country code", min_length=2, max_length=3) capital: Optional[str] = Field(None, description="Capital city") region: Optional[str] = Field(None, description="Geographic region") subregion: Optional[str] = Field(None, description="Geographic subregion") population: Optional[str] = Field(None, description="Country population") flag: Optional[str] = Field(None, description="Country flag URL") class CountryCreate(CountryBase): class Config: schema_extra = { "example": { "name": "United States", "code": "US", "capital": "Washington, D.C.", "region": "Americas", "subregion": "North America", "population": "331,002,651", "flag": "https://example.com/us-flag.png" } } class Country(CountryBase): id: int = Field(..., description="Unique identifier for the country") class Config: orm_mode = True schema_extra = { "example": { "id": 1, "name": "United States", "code": "US", "capital": "Washington, D.C.", "region": "Americas", "subregion": "North America", "population": "331,002,651", "flag": "https://example.com/us-flag.png" } }