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

When an element does not specify type, it loses minOccurs #822

Closed
skinkie opened this issue Jul 15, 2023 · 1 comment · Fixed by #828
Closed

When an element does not specify type, it loses minOccurs #822

skinkie opened this issue Jul 15, 2023 · 1 comment · Fixed by #828

Comments

@skinkie
Copy link
Contributor

skinkie commented Jul 15, 2023

The method should_reset_required resets minOccurs to zero for situations where a type on an element is not defined. What is the rationale for this behavior?

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xsdtesting" xmlns:x="http://xsdtesting" xmlns:imp="http://importedXSD">
        <xsd:element name="foo" final="#all"/>
        <xsd:complexType name="B">
                <xsd:sequence>
                        <xsd:choice minOccurs="1" maxOccurs="1">
                                <xsd:element ref="x:foo"/>
                                <xsd:element name="c2" minOccurs="1" maxOccurs="1"/>
                        </xsd:choice>
                        <xsd:choice minOccurs="1" maxOccurs="1">
                                <xsd:element name="d1" minOccurs="1" maxOccurs="1" block="#all"/>
                                <xsd:element name="d2" minOccurs="1" maxOccurs="1" block="#all"/>
                        </xsd:choice>
                </xsd:sequence>
        </xsd:complexType>
        <xsd:complexType name="R">
                <xsd:complexContent>
                        <xsd:restriction base="x:B">
                                <xsd:sequence>
                                        <xsd:element ref="x:foo"/>
                                        <xsd:element name="d1" minOccurs="1" maxOccurs="1" block="#all"/>
                                </xsd:sequence>
                        </xsd:restriction>
                </xsd:complexContent>
        </xsd:complexType>
        <xsd:element name="doc">
                <xsd:complexType>
                        <xsd:choice>
                                <xsd:element name="elem" type="x:R"/>
                        </xsd:choice>
                </xsd:complexType>
        </xsd:element>
</xsd:schema>
    @classmethod
    def should_reset_required(cls, attr: Attr) -> bool:
        """
        Return whether the min occurrences for the attr needs to be reset.

        @Todo figure out if wildcards are supposed to be optional!
        """
        return (
            not attr.is_attribute
            and attr.default is None
            and object in attr.native_types
            and not attr.is_list
        )
@tefra
Copy link
Owner

tefra commented Jul 16, 2023

A fix on #820 and a further improvement on #828 should take care of this case.

The issue in not with that reset required, that's about wildcards (hint the todo). This issue is about how and when xsdata is calculating the min occurs for choice elements.

It used to be too soon, now I 've moved it later in the flow and made sure if the choice has only one element the min occur restriction doesn't change

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 a pull request may close this issue.

2 participants