40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from pydantic import BaseModel, Field, constr
|
|
from typing import Optional
|
|
|
|
class CountryBase(BaseModel):
|
|
name: str = Field(..., min_length=1, max_length=100, description="Country name")
|
|
code: constr(min_length=2, max_length=2) = Field(..., description="Two-letter country code")
|
|
capital: str = Field(..., min_length=1, description="Capital city")
|
|
region: str = Field(..., min_length=1, description="Geographic region")
|
|
currency: str = Field(..., min_length=1, description="Official currency")
|
|
language: str = Field(..., min_length=1, description="Official language")
|
|
|
|
class CountryCreate(CountryBase):
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "France",
|
|
"code": "FR",
|
|
"capital": "Paris",
|
|
"region": "Europe",
|
|
"currency": "EUR",
|
|
"language": "French"
|
|
}
|
|
}
|
|
|
|
class Country(CountryBase):
|
|
id: int
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": 1,
|
|
"name": "France",
|
|
"code": "FR",
|
|
"capital": "Paris",
|
|
"region": "Europe",
|
|
"currency": "EUR",
|
|
"language": "French"
|
|
}
|
|
} |