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

Enums not generated properly in certain circumstances #59

Open
brianpursley opened this issue Jul 20, 2022 · 1 comment
Open

Enums not generated properly in certain circumstances #59

brianpursley opened this issue Jul 20, 2022 · 1 comment

Comments

@brianpursley
Copy link
Contributor

brianpursley commented Jul 20, 2022

Description
Sometimes, depending on the schema, enums are not generated correctly, or are not generated at all.

Steps to reproduce the issue:
Schema:

<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:here="http://example.org/" targetNamespace="http://example.org/">

    <element name="TopLevel">
        <complexType>
            <choice minOccurs="1" maxOccurs="unbounded">
                <element name="TShirt" type="here:SizeType" minOccurs="0" />
                <element name="Style" minOccurs="0">
                    <simpleType>
                        <restriction base="string">
                            <enumeration value="Value1" />
                            <enumeration value="Value2" />
                        </restriction>
                    </simpleType>
                </element>
            </choice>
        </complexType>
    </element>

    <simpleType name="SizeType">
        <restriction base="string">
            <enumeration value="Small" />
            <enumeration value="Medium" />
            <enumeration value="Large" />
        </restriction>
    </simpleType>

    <simpleType name="HasNoElements">
        <restriction base="string">
        </restriction>
    </simpleType>

</schema>

Command:

xgen -l TypeScript -i example.xsd

Describe the results you received:

// Code generated by xgen. DO NOT EDIT.

// TopLevel ...
export class TopLevel {
	TShirt: Array<SizeType>;
	Style: string;
}

// Style ...
export type Style = string;

// HasNoElements ...
export enum HasNoElements {
	Value1 = 'Value1',
	Value2 = 'Value2',
	Small = 'Small',
	Medium = 'Medium',
	Large = 'Large',
}

Describe the results you expected:

// Code generated by xgen. DO NOT EDIT.

// TopLevel ...
export class TopLevel {
	TShirt: Array<SizeType>;
	Style: string;
}

// Style ...
export type Style = string;

// SizeType ...
export enum SizeType {
	Small = 'Small',
	Medium = 'Medium',
	Large = 'Large',
}

// HasNoElements ...
export type HasNoElements = string;

Output of go version:

go version go1.18.1 linux/amd64

xgen version or commit ID:

98e2a901798bddb93c5e532c98afc1f5f139d47e

Environment details (OS, physical, etc.):

$ uname -a
Linux cinlogic-xps13 5.15.0-41-generic #44~20.04.1-Ubuntu SMP Fri Jun 24 13:27:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Other Information:
If I omit the HasNoElements enum from the schema, the generated code also omits the SizeType enum for some reason:

<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:here="http://example.org/" targetNamespace="http://example.org/">

    <element name="TopLevel">
        <complexType>
            <choice minOccurs="1" maxOccurs="unbounded">
                <element name="TShirt" type="here:SizeType" minOccurs="0" />
                <element name="Style" minOccurs="0">
                    <simpleType>
                        <restriction base="string">
                            <enumeration value="Value1" />
                            <enumeration value="Value2" />
                        </restriction>
                    </simpleType>
                </element>
            </choice>
        </complexType>
    </element>

    <simpleType name="SizeType">
        <restriction base="string">
            <enumeration value="Small" />
            <enumeration value="Medium" />
            <enumeration value="Large" />
        </restriction>
    </simpleType>

</schema>
// Code generated by xgen. DO NOT EDIT.

// TopLevel ...
export class TopLevel {
	TShirt: Array<SizeType>;
	Style: string;
}

// Style ...
export type Style = string;

Also...

If I omit the Style element from the top level element, then it works fine:

<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:here="http://example.org/" targetNamespace="http://example.org/">

    <element name="TopLevel">
        <complexType>
            <choice minOccurs="1" maxOccurs="unbounded">
                <element name="TShirt" type="here:SizeType" minOccurs="0" />
            </choice>
        </complexType>
    </element>

    <simpleType name="SizeType">
        <restriction base="string">
            <enumeration value="Small" />
            <enumeration value="Medium" />
            <enumeration value="Large" />
        </restriction>
    </simpleType>

</schema>

Output:

// Code generated by xgen. DO NOT EDIT.

// TopLevel ...
export class TopLevel {
	TShirt: string;
}

// SizeType ...
export enum SizeType {
	Small = 'Small',
	Medium = 'Medium',
	Large = 'Large',
}

So there is some interaction involving the top level element I think. Also, I think the order of the elements in the schema seems to have some effect too. There seem to be a lot of factors involved in reproducing this.

@ivanjaros
Copy link

More like never.

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

2 participants