hooklift / gowsdl

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

Conflicting XML tags are generated, if a struct with field XMLName is used inside another struct #265

Closed jrcnn closed 6 months ago

jrcnn commented 6 months ago

If a WSDL element refers to another WSDL element, this problem will arise.

So this:

<s:element name="eDocGeteRecordDetailsResponse">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="eDocGeteRecordDetailsResult" type="tns:eRecord"/>
            <s:element minOccurs="0" maxOccurs="1" name="errorMsg" type="s:string"/>
        </s:sequence>
    </s:complexType>
</s:element>

refers to this:

<s:complexType name="eRecord">
    <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="Product" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="Version" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="eDocID" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="ScopeName" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="Type" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="ArtifactDCStatus" type="s:string"/>
    </s:sequence>
</s:complexType>

And it seems that gowsdl does not handle this edge case, as the generated Go code will be wrong. It creates a struct from ERecord as expected:

type ERecord struct {
    XMLName xml.Name xml:"http://tempuri.org/ eRecord"

    Product string xml:"Product,omitempty" json:"Product,omitempty"

    Version string xml:"Version,omitempty" json:"Version,omitempty"

    EDocID string xml:"eDocID,omitempty" json:"eDocID,omitempty"

    ScopeName string xml:"ScopeName,omitempty" json:"ScopeName,omitempty"

    Type string xml:"Type,omitempty" json:"Type,omitempty"

    ArtifactDCStatus string xml:"ArtifactDCStatus,omitempty" json:"ArtifactDCStatus,omitempty"
}

But it fails to account for the fact that an XML name for ERecord has already been created, and so inside struct EDocGeteRecordDetailsResponse this happened:

type EDocGeteRecordDetailsResponse struct {
    XMLName xml.Name xml:"http://tempuri.org/ eDocGeteRecordDetailsResponse"

    EDocGeteRecordDetailsResult *ERecord /*xml:"eDocGeteRecordDetailsResult,omitempty" json:"eDocGeteRecordDetailsResult,omitempty"*/ <- this xml name should not have been generated

    ErrorMsg string `xml:"errorMsg,omitempty" json:"errorMsg,omitempty"`
}

And so a conflict occurs.