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

encoding/xml error when field metadata doesn't match XMLName #219

Open
ieure opened this issue Sep 16, 2021 · 0 comments
Open

encoding/xml error when field metadata doesn't match XMLName #219

ieure opened this issue Sep 16, 2021 · 0 comments

Comments

@ieure
Copy link
Contributor

ieure commented Sep 16, 2021

I'm not sure what to do about this situation, so just opening up an issue in case someone has a good idea.

I generated client code from this WSDL, using a patched gowsdl 9e1cc9a with #214 and #218 applied. The generated code returns an error when unmarshaling:

xml: name "Off-cycle_Type_Reference" in tag of payroll.Payroll_ResultType.Offcycle_Type_Reference conflicts with name "Payroll_Off-cycle_TypeObjectType" in *payroll.Payroll_Offcycle_TypeObjectType.XMLName

The crux of the issue seems to be this poorly named complexType:

      <xsd:complexType name="Payroll_Off-cycle_TypeObjectType">
        <xsd:annotation wd:Is_Reference_ID="1"/>
        <xsd:sequence>
          <xsd:element name="ID" type="wd:Payroll_Off-cycle_TypeObjectIDType" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute name="Descriptor" type="xsd:string">
          <xsd:annotation>
            <xsd:documentation>Display information used to describe an instance of an object. This 'optional' information is for outbound descriptive purposes only and is not processed on inbound Workday Web Services requests.</xsd:documentation>
          </xsd:annotation>
        </xsd:attribute>
      </xsd:complexType>

Go symbols can't have dashes in their names, so the WSDL name gets mangled into Payroll_Offcycle_TypeObjectType:

{{$name := replaceReservedWords .Name | makePublic}}

Because the struct name is now different than the type name in the WSDL, this conditional evaluates to true, and adds an XMLName field to the struct:

gowsdl/types_tmpl.go

Lines 151 to 153 in 9e1cc9a

{{if ne $name $typ}}
XMLName xml.Name ` + "`xml:\"{{$targetNamespace}} {{$typ}}\"`" + `
{{end}}

But, the places where this is actually used specify a different tag name. ex the Payroll_ResultType specifies that it goes into an Off-cycle_Type_Reference tag:

          <xsd:element name="Off-cycle_Type_Reference" type="wd:Payroll_Off-cycle_TypeObjectType" minOccurs="0">
            <xsd:annotation>
              <xsd:documentation>Off-cycle Type Reference</xsd:documentation>
            </xsd:annotation>
          </xsd:element>

gowsdl generates correct output, with the field having the correct type and the metadata specifying the name from the xsd:element:

Offcycle_Type_Reference *Payroll_Offcycle_TypeObjectType `xml:"Off-cycle_Type_Reference,omitempty" json:"Off-cycle_Type_Reference,omitempty"`

…but encoding/xml then blows up because the tag name in Payroll_ResultType.Offcycle_Type_Reference's field metadata is different than the one in Payroll_Offcycle_TypeObjectType.XMLName.

I think the most correct fix here is for encoding/xml to prefer the tag name from the containing struct, if set. In the absence of that, I'm not sure what to do other than postprocess the generated code to remove the XMLName.

Suggestions?

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

Successfully merging a pull request may close this issue.

1 participant