如何使我的其他类在PYDANC2.0中成为可选的?当我有数据时,我不会得到一个错误,但是,当我发送一个空值时,我得到一个ValidationError字段Required type=Missing Error.
例如,我可以做100,这是可行的,但它与使用class (Profile)的意义不符
from typing import Optional, Dict
class User(BaseModel):
id: str
username: str
password: str
connections: Optional[Connections] <---- not working returning ValdiationError if null value sent
profile: Optional[Profile] <---- not working returning ValdiationError if null value sent
class Profile(BaseModel):
id: str
profile_id: str
details: str
class Connections(BaseModel):
connection_id: str
connection_count: int
connection_names: Dict[str, str]
我刚接触PYDNATIC的更新,所以如果有任何帮助,我将不胜感激!