You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, we have support for configuring an element_name_generator and attribute_name_generator function in models metadata or in XmlContext.
This is fantastic for reducing boilerplate when generating element names based on field names of a class.
In the following examples, I'm using PEP8 style field names (snake_case) and PEP8 style class names (PascalCase), and generating XML which uses PascalCase for element names.
Since element_name_generator is also used for generating the local_name of a class when none is explicitly provided, that causes some interesting behavior:
In this case, the (already pascal case) class name is being run through the pascal_caseelement_name_generator, which is clobbering the case of the class from IPAddress to Ipaddress:
<Ipaddress>
<Val>192.168.1.1</Val>
</Ipaddress>
I'm aware that this can be solved by specifying explicit names in either the field metadata or the class metadata, but I think it would be nice to have a way to specify a class_name_generator in the XmlContext to avoid this issue.
Currently, we have support for configuring an
element_name_generator
andattribute_name_generator
function in models metadata or inXmlContext
.This is fantastic for reducing boilerplate when generating element names based on field names of a class.
In the following examples, I'm using PEP8 style field names (snake_case) and PEP8 style class names (PascalCase), and generating XML which uses PascalCase for element names.
This generates the expected XML:
Since
element_name_generator
is also used for generating thelocal_name
of a class when none is explicitly provided, that causes some interesting behavior:In this case, the (already pascal case) class name is being run through the
pascal_case
element_name_generator
, which is clobbering the case of the class fromIPAddress
toIpaddress
:I'm aware that this can be solved by specifying explicit names in either the field metadata or the class metadata, but I think it would be nice to have a way to specify a
class_name_generator
in theXmlContext
to avoid this issue.For example:
Under the hood we could have
class_name_generator
default toelement_name_generator
if not explicitly provided, to maintain the current behavior.Let me know what you think, and I can try to whip up a PR if you're interested in supporting this.
The text was updated successfully, but these errors were encountered: