Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion genGo.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ func (gen *CodeGenerator) GoAttributeGroup(v *AttributeGroup) {

// GoElement generates code for element XML schema in Go language syntax.
func (gen *CodeGenerator) GoElement(v *Element) {
if _, ok := gen.StructAST[v.Name]; !ok {
// If v.Name == v.Type generating a type alias will reference itself
// and result in a duplicate type definition error from the go compiler
if _, ok := gen.StructAST[v.Name]; !ok && v.Name != v.Type {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need add this check for other languages generator?

var plural string
if v.Plural {
plural = "[]"
Expand Down
30 changes: 17 additions & 13 deletions test/xsd/base64.xsd
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:here="http://example.org/" targetNamespace="http://example.org/">
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:here="http://example.org/"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update expected generation code of this xsd for other supported languages to fix unit tests build break.

targetNamespace="http://example.org/">
<element name="MyType7" type="here:MyType7"></element>

<simpleType name="myType1">
<restriction base="base64Binary">
<length value="10" />
Expand All @@ -8,47 +11,47 @@
<complexType name="myType2">
<simpleContent>
<extension base="base64Binary">
<attribute name="length" type="int"/>
<attribute name="length" type="int" />
</extension>
</simpleContent>
</complexType>

<complexType name="myType3">
<simpleContent>
<extension base="date">
<attribute name="length" type="int"/>
<attribute name="length" type="int" />
</extension>
</simpleContent>
</complexType>

<complexType name="myType4">
<sequence>
<element name="title" type="string"/>
<element name="blob" type="base64Binary"/>
<element name="timestamp" type="dateTime"/>
<element name="title" type="string" />
<element name="blob" type="base64Binary" />
<element name="timestamp" type="dateTime" />
</sequence>
</complexType>

<simpleType name="myType5">
<restriction base="gDay"/>
<restriction base="gDay" />
</simpleType>

<complexType name="MyType6">
<attribute name="code">
<simpleType>
<restriction base="string">
<enumeration value="value1"/>
<enumeration value="value2"/>
<enumeration value="value1" />
<enumeration value="value2" />
</restriction>
</simpleType>
</attribute>
<attribute name="identifier" type="int"/>
<attribute name="identifier" type="int" />
</complexType>

<complexType name="MyType7">
<simpleContent>
<extension base="string">
<attribute type="string" name="origin" use="required"/>
<attribute type="string" name="origin" use="required" />
</extension>
</simpleContent>
</complexType>
Expand All @@ -64,10 +67,11 @@
<element name="myType2" type="here:myType2" />
</choice>
</sequence>
<attribute name="cost" type="double"/>
<attribute name="LastUpdated" type="dateTime"/>
<attribute name="cost" type="double" />
<attribute name="LastUpdated" type="dateTime" />
</extension>
</complexContent>
</complexType>
</element>

</schema>
Loading