Feature Request: Add option to infer wrapped lists when generating python code from XSD
Wrapped lists are really useful for simplifying python data structures. Looking through the documentation, I don't see any way to make this work with xsdata generate <xsd file>.
It would be really useful to have an option to infer wrapped lists where one data class will contain another dataclass, itself only containing a list. This may be something that can be post-processed between schema transformation and python code writer.
I don't see any documentation on the "Pluggable code writer for custom output formats". So this customisation isn't something that can be easily bolted on from the side.
I certainly don't want to manually modify python code after parsing a sizeable XSD where the XSD is subject to change.
It could be optional which name is kept for the python name, but I'd recommend it default to the wrapper name, not the element name for these reasons:
- XML schema don't commonly mix and match between wrapped lists and unwrapped lists. If they have wrapper elements at all then all lists are likely to be wrapped lists.
- Wrappers are most commonly name the list, inner elements name the type of thing in the list.
Eg:
<person><children><child>Bob</child><children></person>
most naturally converts to
Person(children=["Bob"])
It makes much less sense to convert this to Person(child=["bob"])
It should be part of the code generator, I agree.
If I was to look at the possible code for this would it be better to process this in the transform step (which would need a wrapper attribute adding somewhere to the model), or would it be better to add as a feature of the output writer?
I've not forgotten this. Just ran out of free time. I'll be back ;-)
This is on my immediate todo list @couling
@couling are you working with a specific schema?
I am. But sadly it's proprietary and I don't have authorisation to share it.
I added a new cli config option --wrapper-fields
This is what it does on the w3c-test suite. https://github.com/tefra/xsdata-w3c-tests/commit/65c03423c6679393c9bf7a142e80ac5c03f109ff
Give it a try and let me know how it works for your use case @couling