这些警告的含义是什么以及如何解决它们?它会产生什么样的问题?
用户警告:
Expected `Union[list[definition-ref], definition-ref, bool]` but got `JsonSchemaObject` - serialized value may not be as expected
Expected `Union[definition-ref, bool]` but got `JsonSchemaObject` - serialized value may not be as expected
Expected `Union[definition-ref, bool]` but got `JsonSchemaObject` - serialized value may not be as expected
Expected `Union[definition-ref, bool]` but got `JsonSchemaObject` - serialized value may not be as expected
return self.__pydantic_serializer__.to_python(
重现:
pets.json
{
"pets": [
{
"name": "dog",
"age": 2
},
{
"name": "cat",
"age": 1
},
{
"name": "snake",
"age": 3,
"nickname": "python"
}
],
"status": 200
}
命令:
datamodel-codegen --input pets.json --input-file-type json --output model.py
版本:
python - 3.11.4
pydantic==2.1.1
datamodel-code-generator==0.21.4
genson==1.2.2
要知道到底出了什么问题,您应该提供解析该对象的 pydantic 模型。