hooklift / gowsdl

WSDL2Go code generation as well as its SOAP proxy
Mozilla Public License 2.0
1.14k stars 390 forks source link

XML name field tag conflicts with struct's XMLName field #224

Closed w65536 closed 2 years ago

w65536 commented 2 years ago

If multiple elements with different names are of the same complexType, their XML name tag conflicts with the XMLName field of the struct defined for that complexType:

Example for <xs:complexType name="typeUnderTest">:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                  xmlns:xs="http://www.w3.org/2001/XMLSchema"
                  targetNamespace="Namespace">
  <wsdl:types>
    <xs:schema targetNamespace="Namespace">
      <!-- base for complexContent -->
      <xs:complexType name="baseType" abstract="true">
        <xs:sequence>
          <xs:element name="someElement" type="xs:string"/>
        </xs:sequence>
      </xs:complexType>
      <!-- complexType with complexContent -->
      <xs:complexType name="someComplexType1">
        <xs:complexContent>
          <xs:extension base="baseType">
            <xs:sequence>
              <xs:element name="elmComplexContent" type="typeUnderTest" minOccurs="0"/>
              <xs:element ref="anotherTopLevelElement" minOccurs="0"/>
            </xs:sequence>
          </xs:extension>
        </xs:complexContent>
      </xs:complexType>
      <!-- complexType -->
      <xs:complexType name="someComplexType2">
        <xs:sequence>
          <xs:element name="elmComplexType" type="typeUnderTest"/>
          <xs:element ref="topLevelElement" minOccurs="0"/>
        </xs:sequence>
      </xs:complexType>
      <!-- typeUnderTest -->
      <xs:complexType name="typeUnderTest">
        <xs:sequence>
          <xs:element name="someOtherElement" type="xs:string"/>
        </xs:sequence>
      </xs:complexType>
      <!-- topLevelElement -->
      <xs:element name="topLevelElement" type="typeUnderTest"/>
      <!-- anotherTopLevelElement -->
      <xs:element name="anotherTopLevelElement" type="typeUnderTest"/>
    </xs:schema>
  </wsdl:types>
</wsdl:definitions>

generates this Go code (header info omitted):

type TopLevelElement TypeUnderTest

type AnotherTopLevelElement TypeUnderTest

type BaseType struct {
    XMLName xml.Name `xml:"Namespace baseType"`

    SomeElement string `xml:"someElement,omitempty" json:"someElement,omitempty"`
}

type SomeComplexType1 struct {
    XMLName xml.Name `xml:"Namespace someComplexType1"`

    *BaseType

    ElmComplexContent *TypeUnderTest `xml:"elmComplexContent,omitempty" json:"elmComplexContent,omitempty"`

    AnotherTopLevelElement *AnotherTopLevelElement `xml:"anotherTopLevelElement,omitempty" json:"anotherTopLevelElement,omitempty"`
}

type SomeComplexType2 struct {
    XMLName xml.Name `xml:"Namespace someComplexType2"`

    ElmComplexType *TypeUnderTest `xml:"elmComplexType,omitempty" json:"elmComplexType,omitempty"`

    TopLevelElement *TopLevelElement `xml:"topLevelElement,omitempty" json:"topLevelElement,omitempty"`
}

type TypeUnderTest struct {
    XMLName xml.Name `xml:"Namespace topLevelElement"`

    SomeOtherElement string `xml:"someOtherElement,omitempty" json:"someOtherElement,omitempty"`
}

Now anotherTopLevelElement, elmComplexContent and elmComplexType all conflict with topLevelElement which was selected as the XMLName field tag of type TypeUnderTest struct.

This issue was first addressed with PR #109 (issue #73) in commit, but without addressing the scenario described here.