Skip to content

Commit

Permalink
fix regressions in how json is returned from the http path
Browse files Browse the repository at this point in the history
after bringing in some recent changes to use jsonpb, we introduced an accidental regression where the protobuf names stopped being returned as defined in the proto. Truss had changed in place to set the json tags to the correct value, but jsonpb doesnt seem to use those and goes by the protobuf mappings themselves. Additionally we accidentally broken the omitempty behavior, by mistaking the polarity of the EmitDefaults value (oops)
  • Loading branch information
zaquestion committed Jul 27, 2019
1 parent 26c294f commit 50393ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 15 additions & 1 deletion gengokit/httptransport/httptransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"reflect"
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/metaverse/truss/gengokit/gentesthelper"
"github.com/metaverse/truss/svcdef"
"github.com/davecgh/go-spew/spew"
)

var (
Expand All @@ -33,6 +33,7 @@ func TestNewMethod(t *testing.T) {
message SumRequest {
int64 a = 1;
int64 b = 2;
int64 orig_name = 3;
}
message SumReply {
Expand Down Expand Up @@ -84,6 +85,19 @@ func TestNewMethod(t *testing.T) {
TypeConversion: "BSum",
IsBaseType: true,
},
&Field{
Name: "OrigName",
QueryParamName: "orig_name",
CamelName: "OrigName",
LowCamelName: "origName",
LocalName: "OrigNameSum",
Location: "query",
GoType: "int64",
ConvertFunc: "OrigNameSum, err := strconv.ParseInt(OrigNameSumStr, 10, 64)",
ConvertFuncNeedsErrorCheck: true,
TypeConversion: "OrigNameSum",
IsBaseType: true,
},
},
}
meth := &Method{
Expand Down
3 changes: 2 additions & 1 deletion gengokit/httptransport/templates/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ func (h httpError) Headers() http.Header {
func EncodeHTTPGenericResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
marshaller := jsonpb.Marshaler{
EnumsAsInts: true,
EmitDefaults: true,
EmitDefaults: false,
OrigName: true,
}
return marshaller.Marshal(w, response.(proto.Message))
Expand Down

0 comments on commit 50393ef

Please sign in to comment.