Is your feature request related to a problem? Please describe.
imagine the following json structure
{
"a": {
"a": [0,1,2],
"b": 1,
"c": 2,
}
}
which has a terrible field naming scheme, but it can't be changed
using aliases, I can set up that "a"
shoud be translated to "additional_data"
, but that will affect both $.a
and $.a.a
, and I have no way to control the alias for that inner "a"
field without affecting the outer one
Describe the solution you'd like
I'd like to be able to define aliases at both levels independently, with fallback to the current state if not used, something like
{
"a": {
"name": "additional_data",
"mapping": {
"a": "archived",
}
},
}
which would then generate
class AdditionalData(BaseModel):
class Config:
extra = Extra.forbid
archived: int = Field(..., alias='a')
class MyDataModel(BaseModel):
additional_data: AdditionalData = Field(..., alias='a')
I don't really care about the format, I'd also be ok with specifying aliases for "a" and "a.a" if that's easier to implement, but I was just thinking that the aliases could be a map from string to string|object and if it's just a string then do the logic as it's currently implemented, otherwise use object.name for the field itself, and object.mapping for nesting fields
Describe alternatives you've considered
I can't really rely on manually updating the file after generation, and I wanted to see if there would be interest on having this officially supported before jumping into using sed or other tools to modify the output after the code generator has run
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