hooklift / gowsdl

WSDL2Go code generation as well as its SOAP proxy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can generate structs with unexported fields

ieure opened this issue · comments

I have a WSDL with this element:

<xsd:element name="_24_Hour_Shift" type="xsd:boolean" minOccurs="0" maxOccurs="1">

gowsdl produces this struct field:

_24_Hour_Shift bool `xml:"_24_Hour_Shift,omitempty" json:"_24_Hour_Shift,omitempty"`

Since the first char isn't capitalized, the field isn't exported, and can't be used.

This gets flagged by my Bazel nogo rules as well:

compilepkg: nogo: errors found by nogo during build-time code analysis:
lib/…/client.go:17767:2: struct field _24_Hour_Shift has json tag but is not exported (structtag)

Just rename the variable in your case to "Hour_Shift_24" but keep the xml and json tag description. Then the struct field will be exported (as is capitalized) as desired but mapped back to "_24_Hour_Shift".

Just rename the variable in your case to "Hour_Shift_24" but keep the xml and json tag description. Then the struct field will be exported (as is capitalized) as desired but mapped back to "_24_Hour_Shift".

Yes, as a purely pragmatic matter, I have already built a thing into our codegen process that automatically edits the file, even though the literal first line says "DO NOT EDIT." Since otherwise, the next time someone ran codegen, the change would be reverted.

The problem isn't "how can I fix the output," it's that gowsdl generates broken output in the first place. This is a bug report, not a StackOverflow question.