Describe the bug
When inferring a model from a sample JSON, the union of an array ([..., ... ...]) and null is inferred to be Union[Any, List[...]] instead of Optional[List[...]]
To Reproduce
Example JSON:
{
"items": [
{
"oofield": null
},
{
"oofield": [1,2,3]
}
]
}
Used commandline:
$ datamodel-codegen --input sample.json --input-file-type json --output model.py
Expected behavior
Expected model:
class Item(BaseModel):
oofield: Optional[List[int]]
class Model(BaseModel):
items: List[Item]
Actually generated model:
class Item(BaseModel):
oofield: Union[Any, List[int]]
class Model(BaseModel):
items: List[Item]
Version:
Additional context
None
@Gowee
Thank you for creating this issue.
OK, I will implement it.
@Gowee
I have released a new version as 0.6.13
The version is fixed the bug.
@koxudaxi
I have tried that. It works pretty well. Thanks!
Now I am closing this issue.
Most helpful comment
@koxudaxi
I have tried that. It works pretty well. Thanks!
Now I am closing this issue.