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

JSON difference in the key format between the client and the server #17

Open
lynnsh opened this issue Nov 26, 2019 · 1 comment
Open

Comments

@lynnsh
Copy link

lynnsh commented Nov 26, 2019

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 in grafeas/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):

// A one sentence description of this note.
ShortDescription string `json:"shortDescription,omitempty"`
@aysylu
Copy link
Contributor

aysylu commented Feb 13, 2020

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?

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

No branches or pull requests

2 participants