Describe the bug
The library doesn't override fields with the same name from different objects in allOf
To Reproduce
Example schema:
{
"allOf": [
{
"type": "object",
"properties": {
"id": {
"type": "string",
"title": "first"
}
},
"required": [
"id"
]
},
{
"type": "object",
"properties": {
"id": {
"type": "string",
"title": "second",
"const": "second"
}
},
"required": [
"id"
]
}
]
}
Pydantic model:
from __future__ import annotations
from pydantic import BaseModel, Field
class Model(BaseModel):
id: str = Field(..., title='first')
Used command line:
$ datamodel-codegen --input file.json --output file.json
Expected behavior
I don't think it should be like thisΡ
I think it would be better if the user can use some parameter to overwrite or not
Possible solution
class DataModel(TemplateBase, Nullable, ABC):
def _validate_fields(
self,
fields: List[DataModelFieldBase]
) -> List[DataModelFieldBase]:
unique_fields: Dict[str, DataModelFieldBase] = {}
for field in fields:
if field.name:
if field.name in unique_fields:
warning(f'Field name `{field.name}` has been overwritten'
f'in the object {self.name}')
unique_fields[field.name] = field
return list(unique_fields.values())
Version:
Additional context
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