Add Country schema
This commit is contained in:
parent
26ba9af602
commit
ac0ab2d61c
@ -2,42 +2,36 @@ from pydantic import BaseModel, Field
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
class CountryBase(BaseModel):
|
class CountryBase(BaseModel):
|
||||||
name: str = Field(..., description="Country name")
|
name: str = Field(..., index=True, min_length=1, description="Country name")
|
||||||
code: str = Field(..., description="Country code", min_length=2, max_length=3)
|
iso2: str = Field(..., min_length=2, max_length=2, description="ISO 3166-1 alpha-2 code")
|
||||||
capital: Optional[str] = Field(None, description="Capital city")
|
iso3: str = Field(..., min_length=3, max_length=3, description="ISO 3166-1 alpha-3 code")
|
||||||
region: Optional[str] = Field(None, description="Geographic region")
|
capital: str = Field(..., min_length=1, description="Capital city")
|
||||||
subregion: Optional[str] = Field(None, description="Geographic subregion")
|
region: str = Field(..., min_length=1, description="Geographic region")
|
||||||
population: Optional[str] = Field(None, description="Country population")
|
subregion: str = Field(..., min_length=1, description="Geographic subregion")
|
||||||
flag: Optional[str] = Field(None, description="Country flag URL")
|
population: str = Field(..., min_length=1, description="Population count")
|
||||||
|
latitude: str = Field(..., min_length=1, description="Latitude coordinates")
|
||||||
|
longitude: str = Field(..., min_length=1, description="Longitude coordinates")
|
||||||
|
flag: str = Field(..., min_length=1, description="Flag image URL")
|
||||||
|
|
||||||
class CountryCreate(CountryBase):
|
class CountryCreate(CountryBase):
|
||||||
class Config:
|
class Config:
|
||||||
schema_extra = {
|
schema_extra = {
|
||||||
"example": {
|
"example": {
|
||||||
"name": "United States",
|
"name": "United States",
|
||||||
"code": "USA",
|
"iso2": "US",
|
||||||
|
"iso3": "USA",
|
||||||
"capital": "Washington, D.C.",
|
"capital": "Washington, D.C.",
|
||||||
"region": "Americas",
|
"region": "Americas",
|
||||||
"subregion": "North America",
|
"subregion": "North America",
|
||||||
"population": "331,002,651",
|
"population": "331002651",
|
||||||
"flag": "https://example.com/usa-flag.png"
|
"latitude": "37.09024",
|
||||||
|
"longitude": "-95.712891",
|
||||||
|
"flag": "https://example.com/us-flag.png"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Country(CountryBase):
|
class Country(CountryBase):
|
||||||
id: int = Field(..., description="Unique identifier for the country")
|
id: int = Field(..., description="Unique identifier")
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
schema_extra = {
|
|
||||||
"example": {
|
|
||||||
"id": 1,
|
|
||||||
"name": "United States",
|
|
||||||
"code": "USA",
|
|
||||||
"capital": "Washington, D.C.",
|
|
||||||
"region": "Americas",
|
|
||||||
"subregion": "North America",
|
|
||||||
"population": "331,002,651",
|
|
||||||
"flag": "https://example.com/usa-flag.png"
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user