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

Change max occurs override logic #88

Conversation

veewee
Copy link
Contributor

@veewee veewee commented Jan 3, 2025

This PR changes the max occurs override logic for sequences:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="complexType">
        <xs:sequence maxOccurs="5" >
            <xs:element name="el1" maxOccurs="3" type="xs:string"></xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

This actually means the element can have a maximum occurence of 15 instead of the returned 5 for el1.

It even becomes more complex if you add additional elements to the sequence:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="complexType">
        <xs:sequence maxOccurs="5" >
            <xs:element name="el1" maxOccurs="3" type="xs:string"></xs:element>
            <xs:element name="el2" maxOccurs="3" type="xs:string"></xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

Now the availability (or not) of el2 has in impact on the maximum amount of el1's that can be set:

// Sequence1:
<el1>foo</el1>
<el1>foo</el1>
<el2>foo</el1>

// Sequence2:
<el1>foo</el1>
<el2>foo</el1>

Since it obeys the order of elements:

  • For sequence 1, the maximum for el1 is now at 2.
  • For sequence 2, the maximum for el1 is now at 1.
  • ...

It becomes even more complex once nexted choices get introduced:
(this was not supported yet, but got introduced in this PR as well)

<xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="complexType">
        <xs:sequence maxOccurs="2" >
            <xs:choice maxOccurs="2">
                <xs:element name="el1" maxOccurs="3" type="xs:string"></xs:element>
                <xs:element name="el2" maxOccurs="3" type="xs:string"></xs:element>
            </xs:choice>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

Now both the sequence count, choice count and element occurence count have an impact on the maximum amount of elements.

Since this is all becoming way too complex and unreliable, I suggest to set the maximum occurences to -1 instead (which means you can have many elements).
For code generation, this should result in an array anyways.

More context:
phpro/soap-client#540

@veewee veewee force-pushed the mac-occurence-override-for-sequence-choices branch from 650714c to baf78af Compare January 3, 2025 11:55
@veewee veewee changed the title Change mac occurs override logic Change max occurs override logic Jan 5, 2025
@goetas goetas merged commit 7f748d3 into goetas-webservices:master Jan 6, 2025
@goetas
Copy link
Member

goetas commented Jan 6, 2025

Makes sense, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants