Add Country schema
This commit is contained in:
parent
cdfb52f159
commit
693f7edbc6
@ -2,20 +2,34 @@ from pydantic import BaseModel, Field
|
||||
from typing import Optional
|
||||
|
||||
class CountryBase(BaseModel):
|
||||
name: str = Field(..., min_length=1, max_length=100)
|
||||
code: str = Field(..., min_length=2, max_length=2)
|
||||
name: str = Field(..., min_length=1, description="Country name")
|
||||
code: str = Field(..., min_length=2, max_length=3, description="Country code")
|
||||
flag: Optional[str] = Field(None, description="Country flag URL")
|
||||
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="Population count")
|
||||
languages: Optional[str] = Field(None, description="Official languages")
|
||||
currencies: Optional[str] = Field(None, description="Official currencies")
|
||||
|
||||
class CountryCreate(CountryBase):
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"name": "United States",
|
||||
"code": "US"
|
||||
"code": "USA",
|
||||
"flag": "https://example.com/us-flag.png",
|
||||
"capital": "Washington, D.C.",
|
||||
"region": "Americas",
|
||||
"subregion": "North America",
|
||||
"population": "331,002,651",
|
||||
"languages": "English",
|
||||
"currencies": "USD"
|
||||
}
|
||||
}
|
||||
|
||||
class Country(CountryBase):
|
||||
id: int
|
||||
id: int = Field(..., description="Unique identifier for the country")
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
@ -23,6 +37,13 @@ class Country(CountryBase):
|
||||
"example": {
|
||||
"id": 1,
|
||||
"name": "United States",
|
||||
"code": "US"
|
||||
"code": "USA",
|
||||
"flag": "https://example.com/us-flag.png",
|
||||
"capital": "Washington, D.C.",
|
||||
"region": "Americas",
|
||||
"subregion": "North America",
|
||||
"population": "331,002,651",
|
||||
"languages": "English",
|
||||
"currencies": "USD"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user