Replies: 1 comment
-
|
This is the intended behavior: the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
After looking deeper into the code while providing an alias mapping dictionary like so:
{ 'model_field_name': 'field_alias_name' }I do not get the correct model outputs, It will only add the alias property to the model if the
model_field_nameand thefield_alias_namevalues match.I found this function that seems to handle the field_name and alias parameters while parsing the json objects:
Function Class:
FieldNameResolverFunction file path: Line 271 -> #https://github.com/koxudaxi/datamodel-code-generator/blob/main/datamodel_code_generator/reference.py
It first checks to see if the
field_nameis a key in the objectsaliasesvariable, and if so returns a tuple like so:return self.aliases[field_name], field_nameThis implies that the tuple contains the alias from the mapping alias dictionary, and the field_name checked in the function.
So when the above function is called here:
File Path: Line 896 -> #https://github.com/koxudaxi/datamodel-code-generator/blob/main/datamodel_code_generator/parser/jsonschema.py
The values seem to be set in reverse, The alias is set to the field_name and the field_name is what the alias should be.
So with the context above, Am I using the library incorrectly when attempting to add the alias mapping dictionary?
I have tried reversing the key and value when providing the mapping data and in that case or the generation errors out and tries to make the alias the field name in the generated Pydantic model class.
Beta Was this translation helpful? Give feedback.
All reactions