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

Issue while generating bindings #659

Closed
lucabotti opened this issue Mar 7, 2022 · 8 comments · Fixed by #660 or #662
Closed

Issue while generating bindings #659

lucabotti opened this issue Mar 7, 2022 · 8 comments · Fixed by #660 or #662
Labels
bug Something isn't working

Comments

@lucabotti
Copy link

While generating bindings with the following command:

xsdata generate -r xsd --package generali.service-models

I receive the following error

xsdata.exceptions.CodeGenerationError: Enumeration class with a complex extension.

JAXB (Java API) manages the xsd , and I submitted the same to w3c org validator. Any way to get more details about the error?

@tefra
Copy link
Owner

tefra commented Mar 7, 2022

Hey @lucabotti can you provide the schema please or a sample?
The error refers to a case I thought it was impossible to occur.

@lucabotti
Copy link
Author

Attaching the whole tree.
xsd.zip

@tefra
Copy link
Owner

tefra commented Mar 7, 2022

Here is the issue

	<xsd:complexType name="GenderCodeType">
		<xsd:simpleContent>
			<xsd:restriction base="cdt:CodeType">
				<xsd:enumeration value="Male" />
				<xsd:enumeration value="Female" />
				<xsd:enumeration value="Neutral" />
				<xsd:enumeration value="Other" />
			</xsd:restriction>
		</xsd:simpleContent>
	</xsd:complexType>

	<xsd:complexType name="CodeType">
		<xsd:simpleContent>
			<xsd:extension base="xsd:token">
				<xsd:attribute
					name="listID"
					type="xsd:token"
					use="optional">

				</xsd:attribute>
				<xsd:attribute
					name="listAgencyID"
					type="xsd:token"
					use="optional">

				</xsd:attribute>
				<xsd:attribute
					name="listAgencyName"
					type="xsd:string"
					use="optional">

					</xsd:annotation>
				</xsd:attribute>
...
...
...
			</xsd:extension>
		</xsd:simpleContent>
	</xsd:complexType>

The gender code type is clearly an enumeration and the base class is not. Jaxb translates that to

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "GenderCodeType")
public class GenderCodeType
    extends CodeType
{


}

Which practically eliminates the enumeration, I am not so sure if this is the correct way, do you have any xml samples that go with that suite?

@tefra
Copy link
Owner

tefra commented Mar 7, 2022

I thought this scenario was not allowed or something, since none of my 25k samples have it. The easiest approach would be to mimick xjc but I am not so sure that's correct either, that's why I would like some xml samples to see if there is a better alternative.

@lucabotti
Copy link
Author

Hi,

Pyxbgen (old, I know) managed the enumeration with the attached file. I have same examples of Agreement I attach.

service_model.zip
GIP_XMLs.zip

@tefra tefra closed this as completed in #660 Mar 7, 2022
@tefra tefra reopened this Mar 7, 2022
@tefra tefra added the bug Something isn't working label Mar 7, 2022
tefra added a commit that referenced this issue Mar 7, 2022
Notes:
Ideally we would create a new enumeration
with the target members, copy the value node
from the base class and set the type to this
new enumeration.

Unfortunately mypy don't like that. This
fixes #659 for now but I want to experiment
some on this one, with literals.
tefra added a commit that referenced this issue Mar 7, 2022
Notes:
Ideally we would create a new enumeration
with the target members, copy the value node
from the base class and set the type to this
new enumeration.

Unfortunately mypy don't like that. This
fixes #659 for now but I want to experiment
some on this one, with literals.
@tefra tefra closed this as completed in #662 Mar 7, 2022
@tefra
Copy link
Owner

tefra commented Mar 7, 2022

Hey @lucabotti thanks for reporting this issue, interesting suite, I added it in the samples.

A fix is on master, it's not really what I wanted but it follows jaxb practise. The issue is about restricting complex/simple content types with specific enumeration values. Ideally I wanted to be able to something like this, but mypy doesn't allow for that.

class Foo:
    value: str

class Bar(Foo):
    value : SomeEnumeration
   

class SomeEnumeration(Enum):
    A = 1
    B = 2

So for now the end result will be like this, I will try to find a solution to somehow keep the enumeration values either as python Literals or try to make enumerations to play nicely with mypy but that will require some more time.

class Foo:
    value: str

class Bar(Foo):
     pass

@tefra
Copy link
Owner

tefra commented Mar 7, 2022

I opened a new issue to follow up with a proper, if possible, solution in the future #663

@lucabotti
Copy link
Author

HI Tefra,

thanks. Will check everything.

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
2 participants