gowsdl icon indicating copy to clipboard operation
gowsdl copied to clipboard

Can generate structs with unexported fields

Open ieure opened this issue 3 years ago • 2 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)

ieure avatar Mar 26 '21 22:03 ieure

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".

MKITConsulting avatar Apr 12 '21 10:04 MKITConsulting

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.

ieure avatar Apr 12 '21 15:04 ieure