erasmus-without-paper / ewp-specs-api-omobility-las

Learning Agreements
MIT License
1 stars 2 forks source link

Streamline `<xs:sequence><xs:element ref="component" ...` #17

Closed j-be closed 3 years ago

j-be commented 3 years ago

The following hunk of code:

                <xs:complexType>
                    <xs:sequence>
                        <xs:element ref="component" minOccurs="0" maxOccurs="unbounded"/>
                    </xs:sequence>
                </xs:complexType>

appears 5 times get-response.xsd. This causes Java's XJC (I guess code generators of other type-safe languages would behave similarly) to create 5 different classes, as all of them are technically different anonymous inner types. Though, all of them only contain a List<Component>.

Having those 5 different types makes handling them in code needlessly cumbersome and error prone, as each code written to be applied on all of them needs to be written 5 times.

I would hence suggest to introduce

    <xs:complexType name="ComponentList">
        <xs:sequence>
            <xs:element ref="component" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

and use it as e.g. <xs:element name="components-studied" type="ComponentList" minOccurs="0" maxOccurs="1">

As far as I can tell this would NEITHER change the XML's syntax, NOR its semantic.