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

xs:decimal maps to str if xs:pattern restriction is present #869

Closed
leo-b opened this issue Nov 29, 2023 · 1 comment
Closed

xs:decimal maps to str if xs:pattern restriction is present #869

leo-b opened this issue Nov 29, 2023 · 1 comment

Comments

@leo-b
Copy link
Contributor

leo-b commented Nov 29, 2023

Hi!

I have an external provided XSD-schema that contains a type definition like that:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://wu.ac.at/myns" targetNamespace="http://wu.ac.at/myns" elementFormDefault="qualified" version="1.0">
	<xs:simpleType name="myType">
		<xs:restriction base="xs:decimal">
			<xs:whiteSpace value="collapse"/>
			<xs:fractionDigits value="1"/>
			<xs:totalDigits value="3"/>
			<xs:pattern value="^[0-9]{1,3}(|[,.][0-9]{1})$"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:element name="myelem" type="myType"/>
</xs:schema>

Unfortunately the generated dataclass contains a value field of type str, not Decimal:

@dataclass
class Myelem:
    class Meta:
        name = "myelem"
        namespace = "http://wu.ac.at/myns"

    value: str = field(
        default="",
        metadata={
            "required": True,
            "total_digits": 3,
            "fraction_digits": 1,
            "white_space": "collapse",
            "pattern": r"^[0-9]{1,3}(|[,.][0-9]{1})$",
        }
    )

If I comment out the xs:pattern restriction, the field is generated as expected: as type Decimal.

I am not an xsd expert but for me it looks like xs:pattern should be allowed in this context:
https://www.oreilly.com/library/view/xml-schema/0596002521/re62.html

Cheers,
--leo

@leo-b
Copy link
Contributor Author

leo-b commented Nov 29, 2023

I just found a related issue #720

--ignore-patterns solves my problem.

Sorry for the noise.
Cheers,
--leo

@leo-b leo-b closed this as completed Nov 29, 2023
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

No branches or pull requests

1 participant