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

XML schema-derived Enumerator and Pattern have prohibited "fixed" attribute #781

Closed
sanzoghenzo opened this issue Apr 21, 2023 · 1 comment · Fixed by #790
Closed

XML schema-derived Enumerator and Pattern have prohibited "fixed" attribute #781

sanzoghenzo opened this issue Apr 21, 2023 · 1 comment · Fixed by #790
Labels
bug Something isn't working

Comments

@sanzoghenzo
Copy link

Hi! I'm successfully using this great library to generate code from some BIM related XSD files, namely BCF XML and IDS XML specifications.

I've stumbled upon a problem with the latter: XML files created using the generated classes are invalid, because the xs:enumeration and xs:pattern elements have a fixed="false" attribute that is not allowed.

To generate the classes, I used the command

xsdata generate -p ids.model -ds Google --kw-only --slots ./ids.xsd

At the beginning of the file there are some namespace imports:

<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/>
<xs:import namespace="http://www.w3.org/2001/XMLSchema" schemaLocation="https://www.w3.org/2001/XMLSchema.xsd"/>
<xs:import namespace="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://www.w3.org/2001/XMLSchema-instance"/>

So xsdata generates the three modules: ids.xml. xmlschema.py and xml.py.

The enumeration element has noFixedFacet type

<xs:element name="enumeration" id="enumeration" type="xs:noFixedFacet">
  <xs:annotation>
    <xs:documentation source="http://www.w3.org/TR/xmlschema-2/#element-enumeration"/>
  </xs:annotation>
</xs:element>

and is translated as

@dataclass(slots=True, kw_only=True)
class Enumeration(NoFixedFacet):
    class Meta:
        name = "enumeration"
        namespace = "http://www.w3.org/2001/XMLSchema"

noFixedFaced is based on facet, but prohibits the use of the fixed attribute defined in the facet:

<xs:complexType name="facet">
  <xs:complexContent>
    <xs:extension base="xs:annotated">
      <xs:attribute name="value" use="required"/>
      <xs:attribute name="fixed" type="xs:boolean" use="optional" default="false"/>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>
<xs:complexType name="noFixedFacet">
  <xs:complexContent>
    <xs:restriction base="xs:facet">
      <xs:sequence>
        <xs:element ref="xs:annotation" minOccurs="0"/>
      </xs:sequence>
      <xs:attribute name="fixed" use="prohibited"/>
      <xs:anyAttribute namespace="##other" processContents="lax"/>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

But this results in an empty NoFixedFacet dataclass that inherits from the Facet class, and it doesn't remove the fixed attibute:

@dataclass(slots=True, kw_only=True)
class Facet(Annotated):
    class Meta:
        name = "facet"

    value: str = field(
        metadata={
            "type": "Attribute",
            "required": True,
        }
    )
    fixed: bool = field(
        default=False,
        metadata={
            "type": "Attribute",
        }
    )


@dataclass(slots=True, kw_only=True)
class NoFixedFacet(Facet):
    class Meta:
        name = "noFixedFacet"

I can fix this by manually editing the NoFixedFaced without inheriting form Facet, but is there a way to tell xsdata to handle the prohibited use of the fixed attribute (so that I don't have to worry about schema updates in the future)?

@tefra tefra added the bug Something isn't working label Apr 23, 2023
@tefra
Copy link
Owner

tefra commented May 21, 2023

The fix is on master and I think I am gonna release today!

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

Successfully merging a pull request may close this issue.

2 participants