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

Inlined complex types with same name result in duplicate struct definitions #129

Open
nettnikl opened this issue Aug 23, 2024 · 2 comments

Comments

@nettnikl
Copy link

Hi!

The tool is installed via

go install github.com/gocomply/xsd2go/cli/gocomply_xsd2go

Consider the following:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ak="http://www.bafa.de/ausfuhrkontrolle/schemas" targetNamespace="http://www.bafa.de/ausfuhrkontrolle/schemas" elementFormDefault="qualified" attributeFormDefault="qualified" version="1.0">
	<xsd:annotation/>
	<xsd:complexType name="AAA">
		<xsd:annotation/>
		<xsd:sequence>
		<xsd:element name="List" minOccurs="0">
			<xsd:annotation/>
			<xsd:complexType>
				<xsd:sequence>
					<xsd:element name="CCC" type="xsd:string" minOccurs="1" maxOccurs="unbounded"/>
				</xsd:sequence>
			</xsd:complexType>
		</xsd:element>
		</xsd:sequence>
	</xsd:complexType>
	<xsd:complexType name="BBB">
		<xsd:annotation/>
		<xsd:sequence>
			<xsd:element name="List" minOccurs="0">
				<xsd:annotation/>
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="DDD" type="xsd:int" minOccurs="1" maxOccurs="unbounded"/>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
		</xsd:sequence>
	</xsd:complexType>
</xsd:schema>

This results in:

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

	Ccc []string `xml:",any"`
}

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

	Ddd []int `xml:",any"`
}
[...]

While i would expect this to be prefixed, or solved via anonymous structs, like e.g.:

// Element
type AaaList struct {
	XMLName xml.Name `xml:"List"`

	Ccc []string `xml:",any"`
}

// Element
type BbbList struct {
	XMLName xml.Name `xml:"List"`

	Ddd []int `xml:",any"`
}
[...]

or

// XSD ComplexType declarations

type Aaa struct {
	XMLName xml.Name

	List *struct {
		XMLName xml.Name `xml:"List"`

		Ccc []string `xml:",any"`
	} `xml:",any"`
}

type Bbb struct {
	XMLName xml.Name

	List *struct {
		XMLName xml.Name `xml:"List"`
	
		Ddd []int `xml:",any"`
	} `xml:",any"`
}
[...]

Thanks for consideration!

@nettnikl
Copy link
Author

One way would be to set nameOverride for the dupe elements so no duplicates are returned by GoName().

nettnikl pushed a commit to nettnikl/xsd2go that referenced this issue Aug 23, 2024
@nettnikl
Copy link
Author

Tested this change locally, seems to work. Can it be merged? Unit test is included.

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