xuri / xgen

XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator
BSD 3-Clause "New" or "Revised" License
318 stars 75 forks source link

Structs missing in generated go code #80

Open nettnikl opened 3 weeks ago

nettnikl commented 3 weeks ago

Description

Some simple types are not generated under given circumstances. The original XSD is not created by me, but is i understand, is old and widely used.

I have no clue of XML, but i managed to dumb the issue down to this short code.

Steps to reproduce the issue:

  1. See reproducible minimal example code below.
  2. xgen -l Go -p internal -i resources/xsd/ -o internal/model/
  3. Check the output.

Describe the results you received: AAA has a struct in go code created.

Describe the results you expected: GGG and DDD has types in go code created as well.

Output of go version:

go version go1.22.5 linux/amd64

xgen version or commit ID:

xgen version: 0.1.0
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://example.com/schemas"
        xmlns:ak="http://example.com/schemas"
        elementFormDefault="qualified">

    <xsd:complexType name="AAA">
        <xsd:annotation><xsd:documentation>BBB</xsd:documentation></xsd:annotation>
        <xsd:sequence>
            <xsd:element name="CCC">
                <xsd:simpleType>
                    <xsd:restriction base="ak:GGG">
                        <!-- This seems to be the issue, CCC is not generated with this restriction enabled -->
                        <xsd:minLength value = "4" fixed = "true" />
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:simpleType name="DDD">
        <xsd:annotation><xsd:documentation>EEE</xsd:documentation></xsd:annotation>
        <xsd:restriction base="ak:GGG">
            <!-- While CCC is ok, this is okay as well. While CCC has the invalid restriction: if any of the following it commented in, DDD is not generated anymore as well. -->
<!--            <xsd:whiteSpace value="collapse" />
<!--            <xsd:minLength value="1" />-->
<!--            <xsd:maxLength value="43" />-->
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="GGG">
        <xsd:annotation><xsd:documentation>FFF</xsd:documentation></xsd:annotation>
        <xsd:restriction base="xsd:string"/>
    </xsd:simpleType>

</xsd:schema>

Environment details (OS, physical, etc.):

nettnikl commented 2 weeks ago

Is this the same issue?

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

    <xsd:simpleType name="CCC">
        <xsd:restriction base="ak:GGG">
            <xsd:minLength value = "4" fixed = "true" />
        </xsd:restriction>
    </xsd:simpleType>
    <!-- This seems wrong, it should be GGG, not string -->
    <!--    // CCC ...-->
    <!--    type CCC string-->

    <xsd:simpleType name="GGG">
        <xsd:annotation><xsd:documentation>FFF</xsd:documentation></xsd:annotation>
        <xsd:restriction base="xsd:string"/>
    </xsd:simpleType>
    <!--    // GGG is FFF-->
    <!--    type GGG string-->

</xsd:schema>

Or this?

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

    <xsd:element name="CCC">
        <xsd:simpleType>
            <xsd:restriction base="ak:GGG">
            </xsd:restriction>
        </xsd:simpleType>
        <!-- This seems wrong, it should be GGG, not string -->
        <!--        // AkGGG ...-->
        <!--        type AkGGG string-->
    </xsd:element>
    <!-- This seems very wrong, it should be a struct -->
    <!--    // CCC is FFF-->
    <!--    type CCC *CCC-->

    <xsd:simpleType name="GGG">
        <xsd:annotation><xsd:documentation>FFF</xsd:documentation></xsd:annotation>
        <xsd:restriction base="xsd:string"/>
    </xsd:simpleType>
    <!--    // GGG ...-->
    <!--    type GGG string-->

</xsd:schema>