Open foot opened 2 years ago
ofc we should be defensive about interpreting create-request
anyway as it could be quite old.
https://pkg.go.dev/github.com/golang/protobuf/jsonpb says its deprecated and we should use https://pkg.go.dev/google.golang.org/protobuf/encoding/protojson instead
The Google Guidelines on Protobufs https://developers.google.com/protocol-buffers/docs/style#message_and_field_names
Use CamelCase (with an initial capital) for message names – for example, SongServerRequest. Use underscore_separated_names for field names (including oneof field and extension names) – for example, song_name.
Do we know why we went against the Google guidelines?
Do we know why we went against the Google guidelines?
We follow the guidelines in WGE, but stopped following them in core so we could re-use the go types generated by the protobuf files in the resty cli client. https://github.com/weaveworks/weave-gitops/pull/2572 . Following the guidelines means you should always marshal with jsonpb which reads the protobuf tag instead of the json tag. If you break guidelines and use camelCase in your fieldsnames then the json
tag is also camelCased and you can use other marshalers like resty.
BUT! The main issue here is the http api that is generated for grpc-gateway is all camelCased, but we save the create-request
annotation using the std. json lib which results in snake_cased JSON. So we have to do a bit of transforming when reading it.
Its all a bit confusing, maybe we can come up with some guidelines here.
We could change the marshaling if we need to?
https://gist.github.com/bigkevmcd/3e467fada2c76ebf4025cba61509c5d6 shows how we can change the marshaling to get snake_case
snake_case
for field names, our tooling generates golang tags which look like this:Where (I think) data can be unmarshal'd using either camel or snake case (at least via the grpc-gateway), but marshaling uses snake_case..
Core has switched to using camelCase in field names, some recent discussion: https://github.com/weaveworks/weave-gitops/pull/2638#pullrequestreview-1085503496
The linked thread says we should always being using
jsonpb
for serializing protobuf stuff. Could we use that instead to generate thecreate-request
annotation?cc @bigkevmcd