remove useless classes in the generated models + use booleans instead of True False enum.
I have 2 things that I need to improve to simplify the generated classes from my xsd file. A sample to illustrate the issue:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Parent">
<xs:complexType>
<xs:sequence>
<xs:element ref="Child1" />
<xs:element ref="Child2" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Child1">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="id" type="xs:string" use="required" />
<xs:attribute name="isTrue" type="xs:boolean" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="Child2">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" ref="Name" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required" />
<xs:attribute name="isTrue" use="required">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="Yes" />
<xs:enumeration value="No" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="Name" type="xs:string" />
</xs:schema>
Child1 is the ideal schema representation that will result in the needed output, but Child2 is the one that I have.
Problems:
-
The xsd file represents some strings attributes as a sequence of elements that refers to another element. Ex:
NameinChild2element. This will results in an unnecessaryNameclass and I will need to remove it manually. -
Some attributes are represented as a "Yes" and "No" enum, is there a way to convert such an attribute to boolean? and then parse it from the XML file as True if the value is Yes, and False if the value is No?
The name type is an root level element, by definition those are global types and can appear as standalone
<?xml version="1.0" encoding="UTF-8"?>
<name>foo<name>
Maybe I could add a config option to remove types with no dependencies that are not used anywhere could do the trick here.
For the second on the enumeration extend the xs:NMTOKEN, there is no way to determine that these are actually boolean.
Actually for the first one, I generated the output 2 weeks ago with xsdata-22.5 and xsdata-attrs-21.11 using the default config with the following command
xsdata file.xsd --package result.models --output attrs
and it removes the Name class from the generated output with the following warning
warning:: Reset absent type: Name
I tried again yesterday but I couldn't reproduce the same result, I have no idea about the reason.
would appreciate if you could add it as a config option.
The warning:: Reset absent type: Name, refers to when a type reference can't be found, maybe your xsd changed?
Never mind, maybe I've commented out some elements.
Is there a plan to add this as a config option?
Yeap, it's planned
Hi @amal-meer
I added a new config option to specify the filter strategy
Give it a try
xsdata schema.xsd --filter-strategy referredGlobals
Hello, I don't see this option anymore in v24.3, did I miss something on this topic? Thank you!
Since v24.3 the generator avoids flattening all root elements and global types, which also removed the filtering strategies.
Thanks for the quick answer, does this new behavior correspond to one of the filter strategies that were available or the current behavior is completely new?
There is no filter strategies anymore, all root elements and complex types are going to be generated.