Describe the bug
If you generate code from similar schema definitions with nested structures, some schema definitions may be ignored.
To Reproduce
Example schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"ObjectA": {
"properties": {
"data": {
"items": {
"properties": {
"keyA": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
},
"ObjectB": {
"properties": {
"data": {
"items": {
"properties": {
"keyB": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
}
}
Used commandline:
$ datamodel-codegen --input schema.json
Expected behavior
For an object with keyA and keyB, we expect two objects to be created.
However, only the Datum with keyB was generated.
class Model(BaseModel):
__root__: Any
class Datum(BaseModel):
keyA: Optional[str] = None
class Datum1(BaseModel):
keyB: Optional[str] = None
class ObjectA(BaseModel):
data: Optional[List[Datum]] = None
class ObjectB(BaseModel):
data: Optional[List[Datum1]] = None
Actual behavior
class Model(BaseModel):
__root__: Any
class Datum(BaseModel):
keyB: Optional[str] = None
class ObjectA(BaseModel):
data: Optional[List[Datum]] = None
class ObjectB(BaseModel):
data: Optional[List[Datum]] = None
Version:
@yacchi
Thank you for creating this issue.
I fixed it. I have released a new version as 0.6.19
@koxudaxi
Thank you for fixed and released.
I tried the new version and confirm that it works as expected.
Most helpful comment
@koxudaxi
Thank you for fixed and released.
I tried the new version and confirm that it works as expected.