Как сформировать модель Pydantic?
Есть вот такой простенький ответ от сервера:
{
"detail": [
{
"loc": [
"query",
"status"
],
"msg": "value is not a valid enumeration member; permitted: 'ACTIVE', 'BANKRUPT', 'CLOSED'",
"type": "type_error.enum",
"ctx": {
"enum_values": [
"ACTIVE",
"BANKRUPT",
"CLOSED"
]
}
}
]
}
На его основе создана JSON-схема (это я для постмана сделал. Нормально валидируется):
{
"type": "object",
"properties": {
"detail": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"loc": {
"type": "array",
"items": {"type": [ "string", "integer" ]}
},
"msg": {"type": "string"},
"type": {"type": "string"},
"ctx": {
"type": "object",
"properties": {
"enum_values": {
"type": "array",
"items": {"type": [ "string", "string", "string" ]}
}
},
"required": [
"enum_values"
]
}
},
"required": ["loc", "msg", "type", "ctx"]
}
]
}
},
"required": [
"detail"
]
}
Пытаюсь создать модель Pydantic, но пока никак:
from pydantic import BaseModel
from typing import List
class Data_from_detail(BaseModel):
loc: list[str, int]
msg: str
type: str
ctx: List[str] = ["ACTIVE", "BANKRUPT", "CLOSED"]
class Detail(BaseModel):
detail: list[Data_from_detail]