这是我的架构文件
from pydantic import BaseModel
from typing import Optional
class HolidaySchema(BaseModel):
year: int
month: int
country: str
language: str
class HolidayDateSchema(BaseModel):
name: str
date: str
holidays: HolidaySchema | None = None
class Config:
orm_mode = True
这就是我的路由
@router.get("/holidays/",response_model = List[HolidayDateSchema])
我想得到的回答是
[
{
"date": "2021-08-14",
"name": "Independence Day",
"holidays": { "year": 2022, "month":5, "country":"pk", "language":"en"},
"id": 13
},
]
现在它不支持带有响应模型的简单模式,我不知道为什么,它给出了错误 pydantic.error_wrappers.ValidationError: 2 validation errors for HolidayDateSchema
和value is not a valid dict
如果任何人都能用RESPONSE_MODEL指定获得深度嵌套的JSON对象的最佳方案,那就太好了.