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

'generate' using xsd no longer treats type derived from xsd:decimal as Decimal #720

Closed
bkcsfi opened this issue Nov 10, 2022 · 2 comments · Fixed by #727
Closed

'generate' using xsd no longer treats type derived from xsd:decimal as Decimal #720

bkcsfi opened this issue Nov 10, 2022 · 2 comments · Fixed by #727

Comments

@bkcsfi
Copy link

bkcsfi commented Nov 10, 2022

after upgrading from xsdata version 20.11 to 22.11 I have discovered a problem converting an xsd to dataclass defintions

given for example this subset of the xsd file

  <xs:complexType name="chargeType">
    <xs:all>
      <xs:element name="amount" type="monetaryType" minOccurs="1" maxOccurs="1">
        <xs:annotation>
          <xs:documentation>
             The amount of the charge (currently in USD)
          </xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:all>
  </xs:complexType>
  <xs:simpleType name="monetaryType">
    <xs:annotation>
      <xs:documentation>Cost</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:decimal">
      <xs:pattern value="\d+\.\d{2}"/>
    </xs:restriction>
  </xs:simpleType>

the python type declaration under 20.11 changed from decimal.Decimal

    amount: Optional[decimal.Decimal] = field(
        default=None,
        metadata={
            "type": "Element",
            "namespace": "",
            "required": True,
            "pattern": r"\d+\.\d{2}",
        }
    )

to str under 22.11

    amount: Optional[str] = field(
        default=None,
        metadata={
            "type": "Element",
            "namespace": "",
            "required": True,
            "pattern": r"\d+\.\d{2}",
        }
    )

Is this an expected change?

thanks

@tefra
Copy link
Owner

tefra commented Nov 20, 2022

Yeah xsdata can't handle patterns yet, so whenever a pattern is present it resets the type to str,

The pattern is added in the metadata for future reference but it's not used yet, maybe I could add an option to ignore patterns completely?

@tefra
Copy link
Owner

tefra commented Dec 11, 2022

HI @bkcsfi I added a new option to ignore-patterns,

xsdata schema.xsd --ignore-patterns

https://xsdata.readthedocs.io/en/latest/codegen.html

At some point I really want to do this properly but it's not very easy to translate xsd regex to python

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