encoding/xml error when field metadata doesn't match XMLName
ieure opened this issue · 0 comments
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
:
Line 145 in 9e1cc9a
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:
Lines 151 to 153 in 9e1cc9a
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?