GoComply / xsd2go

Automatically generate golang xml parser based on XSD
http://isimluk.com/posts/2020/05/xsd2go-automatically-generate-golang-xml-parsers/
The Unlicense
71 stars 42 forks source link

Element of complex type is duplicated #134

Open nettnikl opened 2 weeks ago

nettnikl commented 2 weeks ago

For this

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:ak="http://example.com/schemas" targetNamespace="http://example.com/schemas"
            elementFormDefault="qualified" attributeFormDefault="qualified"
            version="1.0">
    <xsd:element name="AAA" type="ak:BBB"/>

    <xsd:complexType name="BBB">
        <xsd:sequence>
            <xsd:element name="CCC">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string"/>
                </xsd:simpleType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

I get:

// Code generated by https://github.com/gocomply/xsd2go; DO NOT EDIT.
// Models for http://example.com/schemas
package ak

import (
    "encoding/xml"
)

// Element
type Aaa struct {
    XMLName xml.Name `xml:"AAA"`

    Ccc string `xml:",any"`
}

// XSD ComplexType declarations

type Bbb struct {
    XMLName xml.Name

    Ccc string `xml:",any"`
}

// XSD SimpleType declarations

While I expect:

// Code generated by https://github.com/gocomply/xsd2go; DO NOT EDIT.
// Models for http://example.com/schemas
package ak

import (
    "encoding/xml"
)

// Element
type Aaa Bbb

// XSD ComplexType declarations

type Bbb struct {
    XMLName xml.Name

    Ccc string `xml:",any"`
}

// XSD SimpleType declarations
nettnikl commented 2 weeks ago

I think this would lead to other compilation errors, only some deduplication done somewhere internally prevents the type from coming up two times (as element and complex type).

On a side node: This however also leads to an issue, when i have a documentation string for a complexType, it is overwritten by the (potentially empty) documentation string for the element bearing the same name.