Skip to content

simpleType causing issues in the generated code #88

@GiovanePS

Description

@GiovanePS

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions