Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign sequential fields #438

Closed
tefra opened this issue Mar 27, 2021 · 2 comments
Closed

Redesign sequential fields #438

tefra opened this issue Mar 27, 2021 · 2 comments

Comments

@tefra
Copy link
Owner

tefra commented Mar 27, 2021

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="first">
    <xs:annotation>
      <xs:documentation>
        Sequence is not repeating, fields are declared in the same order: do nothing
        <a />
        <b />
        <b />
        <c />
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="a" type="xs:string" />
        <xs:element name="b" type="xs:string" maxOccurs="2" />
        <xs:element name="c" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="second">
    <xs:annotation>
      <xs:documentation>
        Repeatable sequence of non list elements: current sequential
        <a />
        <b />
        <c />
        <a />
        <b />
        <c />
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence maxOccurs="2">
        <xs:element name="a" type="xs:string" />
        <xs:element name="b" type="xs:string" />
        <xs:element name="c" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="third">
    <xs:annotation>
      <xs:documentation>
        Repeatable sequence of both list and non list elements: we rely on compound fields to get it working
        <a />
        <a />
        <b />
        <c />
        <c />
        <a />
        <a />
        <b />
        <c />
        <c />
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence maxOccurs="2">
        <xs:element name="a" type="xs:string" maxOccurs="2" />
        <xs:element name="b" type="xs:string" />
        <xs:element name="c" type="xs:string" maxOccurs="2" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="fourth">
    <xs:annotation>
      <xs:documentation>
        Whatever....Why...
        <a />
        <b />
        <c />
        <c />
        <a />
        <b />
        <b />
        <a />
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:element name="a" type="xs:string" />
        <xs:element name="b" type="xs:string" />
        <xs:element name="c" type="xs:string" maxOccurs="2" />
        <xs:sequence maxOccurs="2">
          <xs:element name="a" type="xs:string" />
          <xs:element name="b" type="xs:string" minOccurs="0" maxOccurs="2" />
        </xs:sequence>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

To get the 3-4 cases working xsdata relies on effective choices feature #433 and compound fields.

Currently the sequential metadata property is boolean and the xs:sequence min/max occurs is merged into the element's normal min/max occurs. Things get more complicated when extending types and the class analyzer tries to merge inherited restrictions.

I want to try to decouple sequence min/max occurs from the child elements min/max occurs during class analyzer, and use the sanitizer in the end to set the fields real min/max occurs values and the sequential break number.

The fourth case is all over the place and I am not sure it can even be done with dataclasses without the compound fields. Maybe turn the sequential property into a list of break points?

I was kind of excited until I reached writing down case no4, worth the effort?? I am not so sure but it still bothers me the fact that the sequence and elements min/max occurs are tight coupled.

@skinkie
Copy link
Contributor

skinkie commented Jun 17, 2021

The following xsd structure...

  <xs:group name="SMIL.timecontainer.content">
    <xs:choice>
      <xs:element ref="SMIL.timecontainer.class"/>
      <xs:element ref="SMIL.media-object"/>
      <xs:group ref="SMIL.animation.elements"/>
      <xs:element ref="SMIL.content-control"/>
      <xs:element ref="SMIL.a-control"/>
      <xs:element ref="SMIL.state.elements"/>
    </xs:choice>
  </xs:group>

...causes the parsed code to have lists of a specific type. For example:

Par(excl=[], smil_excl_time_containers_class=[], seq=[], par=[], smil_basic_time_containers_class=[], smil_timecontainer_class=[], smil_text=[] ...)

The main problem with this is that the order of the elements cannot be guaranteed. In the above case this is not problematic because business wise all the elements should be executed parallel. But in the case below, where elements should be executed by the order of the list, that would only work for the same type.

Seq(excl=[], smil_excl_time_containers_class=[], seq=[], par=[])

So how to get the original order?

@tefra
Copy link
Owner Author

tefra commented Jun 18, 2021

Switch to compound fields @skinkie

https://xsdata.readthedocs.io/en/latest/codegen.html
https://xsdata.readthedocs.io/en/latest/models.html#type-elements

@tefra tefra closed this as completed Jul 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants