xuri / xgen

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

the generated go file contains a field in a struct that is not in the definition #63

Open sumia01 opened 1 year ago

sumia01 commented 1 year ago

Description

I'm trying to generate structs for go from the schema provided by Tableau (link below), but I'm getting bad results for this XSD version. For comparison, I'm using c# sourcecode generated with xsd (from mono).

The result structures are different than expected.

Steps to reproduce the issue:

  1. get xsd file from https://help.tableau.com/samples/en-us/rest_api/ts-api_3_17.xsd or use https://gist.github.com/sumia01/f15ee5589f4a020b63bd0e016ebaf5b6#file-ts-api_3_17-xsd

  2. generate output file(s)

    xgen -i ts-api_3_17.xsd -o 3.17/schema.go -l Go
  3. compare with reference generated with xsd from Mono (https://www.mono-project.com/docs/getting-started/install). I uploaded it here: https://gist.github.com/sumia01/f551985805e2e84c9a83cee1e9ef59f8

Describe the results you received: In the generated result, there is a Status string in the SiteType struct. https://gist.github.com/sumia01/f15ee5589f4a020b63bd0e016ebaf5b6#file-schema-go-L1511

But it shouldn't be there, see the c# reference: https://gist.github.com/sumia01/f551985805e2e84c9a83cee1e9ef59f8#file-tableau_3_17-cs-L2960

And here is the type definition part from the original xsd, I can't find any reference for status here: https://gist.github.com/sumia01/f15ee5589f4a020b63bd0e016ebaf5b6#file-ts-api_3_17-xsd-L1797

One more strange behaviour found here. If I comment the following part from xsd (https://gist.github.com/sumia01/f15ee5589f4a020b63bd0e016ebaf5b6#file-ts-api_3_17-xsd-L1418)

            <!-- <xs:element name="status" minOccurs="1" maxOccurs="1">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="Failed" />
                        <xs:enumeration value="Success" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element> -->

then it's not generated into the SiteType struct. But I don't understand the connection here.

Describe the results you expected:

I'd like to get the same result as in the c# file

Output of go version:

go version go1.19.3 darwin/arm64

xgen version or commit ID:

xgen version: 0.1.0
commit hash: 45dd37dc6afb5afb6ffd28b6e81b760ec6f7e038

Environment details (OS, physical, etc.):

Darwin Sumi-MacBook-Pro.local 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct  9 20:14:30 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8103 arm64