Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Enums of type string with length 1 are not converted #294

Closed
nilapalin opened this issue Nov 18, 2021 · 3 comments
Closed

Enums of type string with length 1 are not converted #294

nilapalin opened this issue Nov 18, 2021 · 3 comments

Comments

@nilapalin
Copy link

nilapalin commented Nov 18, 2021

When the following xsd is converted, the TestRestrictionLength1 element is converted to type string and no enumerations are created.

However, TestNoRestriction is converted with enumerations. Difference is the length restriction which is set to 1 for TestRestrictionLength1.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://me.me" xmlns:my="http://me.me" elementFormDefault="unqualified">
	<xs:element name="Test">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="TestRestrictionLength1" minOccurs="0">
					<xs:simpleType>
						<xs:restriction base="xs:string">
							<xs:length value="1"/>
							<xs:enumeration value="A"/>
							<xs:enumeration value="B"/>
						</xs:restriction>
					</xs:simpleType>
				</xs:element>
				<xs:element name="TestNoRestriction" minOccurs="0">
					<xs:simpleType>
						<xs:restriction base="xs:string">
							<xs:enumeration value="enum1"/>
							<xs:enumeration value="enum2"/>
						</xs:restriction>
					</xs:simpleType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>

Tested on latest Version 2.0.594.

Version 2.0.424 is converting both elements to include enumerations.
Version 2.0.434 is not converting TestRestrictionLength1 anymore (Version 2.0.425 not tested).

Was there a reason to change that behaviour?

@mganss
Copy link
Owner

mganss commented Nov 19, 2021

This was introduced in the change to resolve #205. I'll try to relax the requirements for generating enums.

@mganss
Copy link
Owner

mganss commented Nov 21, 2021

I probably won't be able to do this until the 29th as I'm not near a computer until then. If you would like to make a PR to resolve this, please go ahead. Thanks.

@mganss mganss closed this as completed in 9c6f1dc Nov 29, 2021
@mganss
Copy link
Owner

mganss commented Nov 29, 2021

This wasn't as easy as I had hoped. The problem is unions where (at least) one of the constituents doesn't have an enum restriction. These can't be mapped to enums because they might for example represent a large range of numbers (one arm of the union w/o enum restriction) plus several specific numbers outside that range (a different arm of the union with enum restrictions).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants