atviriduomenys / spinta

Spinta is a framework to describe, extract and publish data (a DEP Framework).
MIT License
10 stars 4 forks source link

In situations when we have a ref element with one child ref element which is an array (`maxOccurs=unbound`), we skip this model and add it's child model as `backref`, and add the `ref` property to that child element. But this works not in all cases. #613

Open karina-klinkeviciute opened 1 month ago

karina-klinkeviciute commented 1 month ago

In situations when we have a ref element with one child ref element which is an array (maxOccurs=unbound), we skip this model and add it's child model as backref, and add the ref property to that child element.

For example, in this case we have XSD element REGISTRAS which has child element ADRESAI which has a reference to ADRESAS which is unbounded.

<xs:element name="REGISTRAS">
    <xs:complexType mixed="true">
        <xs:choice maxOccurs="unbounded">
            <xs:element ref="ID" minOccurs="0" maxOccurs="1"/>
            <xs:element ref="ATRIBUTAI" minOccurs="0" maxOccurs="1"/>
            <xs:element ref="ADRESAI" minOccurs="0" maxOccurs="1"/>
       </xs:choice>
    </xs:complexType>
<xs/element>

<xs:element name="ADRESAI">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="ADRESAS" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="ADRESAS">
    <xs:complexType mixed="false">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="ADM_ID" type="xs:long" minOccurs="0" maxOccurs="1"></xs:element>
            <xs:element name="GYV_ID" type="xs:long" minOccurs="0" maxOccurs="1"></xs:element>
        </xs:choice>
    </xs:complexType>
</xs:element>

In this case, DSA should look like this:

Registras /REGISTRAS id integer ID atributai backref Registras adresai[] backref Adresas

Adresas /REGISTRAS/ADRESAI/ADRESAS registras ref Registas

This already works in the most generic cases, for example where the XSD structure is like this:

<complexType><sequence><element></element></sequence></complexType>

But it might not work in cases where we have, let's say, all instead of sequence.