Open lynnsh opened 5 years ago
Hi @lynnsh, this is a great catch and I think the long-term fix to this would be incredibly valuable. As discussed in #16, the best way forward would probably be to fix this at the Swagger codegen level. What do you think?
Problem
Server and client json renderers do not match. Client code (defined in
client-go
) expects json keys in snake_case, and the server code (defined ingrafeas/grafeas
) sends json keys in camelCase. Thus, server response values are ignored by the client marshaller.Example
Field definitions: client-go:
ShortDescription string 'json:"short_description,omitempty"'
grafeas:ShortDescription string 'protobuf:"bytes,2,opt,name=short_description,json=shortDescription,proto3" json:"short_description,omitempty"'
What the client receives before the values are unmarshalled:
"name":"projects/grafeasclienttest/notes/grafeasattestation","shortDescription":"short","longDescription":"long","kind":"ATTESTATION","relatedUrl":[],"expirationTime":"0001-01-01T00:00:00Z","createTime":"2019-11-12T14:12:44.705616Z","updateTime":"2019-11-12T14:12:44.705616Z","relatedNoteNames":[],"attestationAuthority":{"hint":{"humanReadableName":"projects/grafeasclienttest/notes/grafeasattestation"}}
The final unmarshalled object:
Name:projects/grafeasclienttest/notes/grafeasattestation ShortDescription: LongDescription: Kind:0xc00041b0e0 RelatedUrl:[] ExpirationTime:0001-01-01 00:00:00 +0000 UTC CreateTime:0001-01-01 00:00:00 +0000 UTC UpdateTime:0001-01-01 00:00:00 +0000 UTC RelatedNoteNames:[] Vulnerability:<nil><HIGHLIGHT:END>
Potential Solution
Rename json keys in client-go models to use the camelCase, e.g. (from
model_v1beta1_note.go
):