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

Enum naming conflict #1119

Open
sashkent3 opened this issue Feb 26, 2025 · 3 comments
Open

Enum naming conflict #1119

sashkent3 opened this issue Feb 26, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@sashkent3
Copy link

sashkent3 commented Feb 26, 2025

Consider the following simple schema
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="UniqueName1">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Value">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="Status">
                    <xs:simpleType>
                      <xs:restriction base="xs:string">
                        <xs:enumeration value="Rejected"/>
                        <xs:enumeration value="Completed"/>
                      </xs:restriction>
                    </xs:simpleType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="UniqueName2">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Value">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="Status">
                    <xs:simpleType>
                      <xs:restriction base="xs:string">
                        <xs:enumeration value="Pending"/>
                        <xs:enumeration value="Approved"/>
                      </xs:restriction>
                    </xs:simpleType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>
And an example XML
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <UniqueName1>
    <Value>
    	<Status>Completed</Status>
    </Value>
  </UniqueName1>
  <UniqueName2>
    <Value>
    	<Status>Pending</Status>
    </Value>
  </UniqueName2>
</Root>

According to tools like https://www.liquid-technologies.com/online-xsd-validator, the pair is valid. However, there's a problem with the output of xsdata. It generates a single:

class ValueStatus(Enum):
    REJECTED = "Rejected"
    COMPLETED = "Completed"

...and uses it for both Root.UniqueName1 and Root.UniqueName2. This is incorrect, as a distinct Status enum should be generated for the Root.UniqueName2.

@sashkent3 sashkent3 changed the title Namespace conflict Enum naming conflict Feb 26, 2025
@sashkent3
Copy link
Author

This seems similar to #375

@sashkent3
Copy link
Author

Setting UnnestClasses to true seems to help.

@tefra
Copy link
Owner

tefra commented Mar 1, 2025

Confirmed, thanks for reporting @sashkent3

@tefra tefra added the bug Something isn't working label Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants