1

What is the meaning of these warnings and how to fix them? What kind of issues it can create?

UserWarning:

  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(

To reproduce:

pets.json

{
    "pets": [
      {
        "name": "dog",
        "age": 2
      },
      {
        "name": "cat",
        "age": 1
      },
      {
        "name": "snake",
        "age": 3,
        "nickname": "python"
      }
    ],
    "status": 200
  }

Command:

datamodel-codegen  --input pets.json --input-file-type json --output model.py

Versions:

python - 3.11.4
pydantic==2.1.1
datamodel-code-generator==0.21.4
genson==1.2.2
gregsdennis
  • 7,218
  • 3
  • 38
  • 71
shaik moeed
  • 5,300
  • 1
  • 18
  • 54

0 Answers0