Describe the bug
my assumed usecase is shown in figure.
in this use-case, the same definition name('Target' in this report) appears in lots of places within multiple jsonschema files, but it is normal condition.
I have three jsonschema,
3def.json is the input to datamodel-code-generator.
1def.json, 2def.json are refered from above 3def.json
To Reproduce
Example schema:
3def.json(input to datamodel-code-generator)
{
"definitions": {
"Target": {
"allOf": [
{
"anyOf": [
{
"$ref": "1def.json#/definitions/Target"
},
{
"$ref": "2def.json#/definitions/Target"
}
]
},
{
"properties": {
"final_model_to_be_used": {
"type": "string"
}
},
"required": [
"final_model_to_be_used"
]
}
]
}
}
}
1def.json (refered from 3def.json)
{
"definitions": {
"First": {
"properties": {
"first": {
"type": "string"
}
},
"required": [
"first"
]
},
"Target": {
"allOf": [
{
"$ref": "#/definitions/First"
},
{
"properties": {
"attrOrigin": {
"type": "integer"
}
},
"required": [
"attrOrigin"
]
}
]
}
}
}
2def.json(refered from 3def.json):
{
"definitions": {
"Target": {
"allOf": [
{
"$ref": "1def.json#/definitions/First"
},
{
"properties": {
"attr_changed_in_2def": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": [
"attr_changed_in_2def"
]
}
]
}
}
}
produced classes at current:
# generated by datamodel-codegen:
# filename: 3def.json
from typing import Any, List, Union
from pydantic import BaseModel
class Target2(BaseModel):
final_model_to_be_used: str
class First(BaseModel):
first: str
class Target(First): # the name 'Target' is used by other place than expected.
attr_changed_in_2def: List[float]
class Target4(Target, Target2):
pass
class TargetModel(First):
attrOrigin: int
class Target3(TargetModel, Target2):
pass
class Target1(BaseModel): # this class should have the name 'Target' to keep the same as input jsonschema(3def.json)
__root__: Union[Target3, Target4]
Used commandline:
$ ls # make sure all schema exists in the local machine.
1def.json 2def.json 3def.json
$ datamodel-codegen --input-file-type jsonschema --input 3def.json
Expected behavior
The below classes expected to be genrated:
:
class Target2(BaseModel):
final_model_to_be_used: str
class First(BaseModel):
first: str
class TargetX(First): # the class generated by refering has suffix in its name.
attr_changed_in_2def: List[float]
class Target4(TargetX, Target2):
pass
class TargetModel(First):
attrOrigin: int
class Target3(TargetModel, Target2):
pass
class Target(BaseModel): # generated class keeps the same name as input jsonschema(3def.json)
__root__: Union[Target3, Target4]
Version:
Additional context
none.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too