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

simpleType causing issues in the generated code #88

Open
GiovanePS opened this issue Mar 7, 2025 · 0 comments
Open

simpleType causing issues in the generated code #88

GiovanePS opened this issue Mar 7, 2025 · 0 comments

Comments

@GiovanePS
Copy link

Description
Basically the title.

I've created the minimal XSD to get the issue:

<schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://example.com/myschema"
    xmlns:xs="http://example.com/myschema"
    elementFormDefault="qualified">

    <complexType name="SomeComplexType">
        <sequence>
            <!-- First element appears with no issues -->
            <element name="FirstElement" type="int" />
            <element name="ElementWithSimpleType">
                <simpleType>
                    <restriction base="string" />
                </simpleType>
            </element>
            <!-- After the first SimpleType in ComplexType, the elements don't appear properly in
            the final struct -->
            <element name="OtherElementWithSimpleType">
                <simpleType>
                    <restriction base="string" />
                </simpleType>
            </element>
            <!-- Even the elements without SimpleType don't appear properly -->
            <element name="ElementWithoutSimpleType" type="int" />
        </sequence>
    </complexType>
</schema>

Might be related to #63 and #80. They use the simpleType in their XSD in the problematic chunk of code.

Steps to reproduce the issue:

  1. Copy the above XSD to a blank file (minimal.xsd)
  2. Run xgen -l Go -i minimal.xsd

Describe the results you received:

// Code generated by xgen. DO NOT EDIT.

package schema

// SomeComplexType ...
type SomeComplexType struct {
	FirstElement          int                    `xml:"FirstElement"`
	ElementWithSimpleType *ElementWithSimpleType `xml:"ElementWithSimpleType"`
}

// ElementWithSimpleType ...
type ElementWithSimpleType *ElementWithSimpleType

// String ...
type String string

// OtherElementWithSimpleType ...
type OtherElementWithSimpleType *OtherElementWithSimpleType

// ElementWithoutSimpleType ...
type ElementWithoutSimpleType int

Describe the results you expected:

// Code generated by xgen. DO NOT EDIT.

package schema

// SomeComplexType ...
type SomeComplexType struct {
	FirstElement               int    `xml:"FirstElement"`
	ElementWithSimpleType      string `xml:"ElementWithSimpleType"`
	OtherElementWithSimpleType string `xml:"OtherElementWithSimpleType"`
	ElementWithoutSimpleType   int    `xml:"ElementWithoutSimpleType"`
}

Output of go version:

go version go1.24.0 linux/amd64

xgen version or commit ID:

xgen version: 0.1.0
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