diff --git a/.travis.yml b/.travis.yml index cf746666d5f..ff613dc76e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ before_install: - go get github.com/go-resty/resty - go get golang.org/x/oauth2 - go get golang.org/x/net/context +- go get github.com/go-test/deep install: - go get github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway - go get github.com/grpc-ecosystem/grpc-gateway/runtime diff --git a/examples/client_test.go b/examples/client_test.go index b580fb7f7be..cd7ec5e8c02 100644 --- a/examples/client_test.go +++ b/examples/client_test.go @@ -1,9 +1,9 @@ package main import ( - "reflect" "testing" + "github.com/go-test/deep" "golang.org/x/net/context" "github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe" @@ -64,7 +64,7 @@ func TestAbitOfEverythingClient(t *testing.T) { } func testABEClientCreate(t *testing.T, cl *abe.APIClient) { - want := &abe.ExamplepbABitOfEverything{ + want := abe.ExamplepbABitOfEverything{ FloatValue: 1.5, DoubleValue: 2.5, Int64Value: "4294967296", @@ -106,15 +106,12 @@ func testABEClientCreate(t *testing.T, cl *abe.APIClient) { t.Errorf("resp.Uuid is empty; want not empty") } resp.Uuid = "" - if got := resp; !reflect.DeepEqual(got, want) { - t.Errorf("resp = %#v; want %#v", got, want) + if diff := deep.Equal(resp, want); diff != nil { + t.Error(diff) } } func testABEClientCreateBody(t *testing.T, cl *abe.APIClient) { - t.Log("TODO: support enum") - return - want := abe.ExamplepbABitOfEverything{ FloatValue: 1.5, DoubleValue: 2.5, @@ -144,9 +141,9 @@ func testABEClientCreateBody(t *testing.T, cl *abe.APIClient) { }, RepeatedStringValue: []string{"a", "b", "c"}, OneofString: "x", - MapValue: map[string]abe.ExamplepbNumericEnum{ - // "a": abe.ExamplepbNumericEnum_ONE, - // "b": abe.ExamplepbNumericEnum_ZERO, + MapValue: map[string]abe.ExamplepbNumericEnum{ + "a": abe.ONE, + "b": abe.ZERO, }, MappedStringValue: map[string]string{ "a": "x", @@ -165,7 +162,7 @@ func testABEClientCreateBody(t *testing.T, cl *abe.APIClient) { t.Errorf("resp.Uuid is empty; want not empty") } resp.Uuid = "" - if got := resp; !reflect.DeepEqual(got, want) { - t.Errorf("resp = %#v; want %#v", got, want) + if diff := deep.Equal(resp, want); diff != nil { + t.Error(diff) } } diff --git a/protoc-gen-swagger/genswagger/template.go b/protoc-gen-swagger/genswagger/template.go index c838a5808d7..3c3e50eb56c 100644 --- a/protoc-gen-swagger/genswagger/template.go +++ b/protoc-gen-swagger/genswagger/template.go @@ -241,7 +241,7 @@ func renderMessagesAsDefinition(messages messageMap, d swaggerDefinitionsObject, panic(err) } - schema.Properties = append(schema.Properties, keyVal{f.GetName(), fieldValue}) + schema.Properties = append(schema.Properties, keyVal{f.GetJsonName(), fieldValue}) } d[fullyQualifiedNameToSwaggerName(msg.FQMN(), reg)] = schema } diff --git a/runtime/marshaler_registry.go b/runtime/marshaler_registry.go index 928f0733214..f7a64eecd11 100644 --- a/runtime/marshaler_registry.go +++ b/runtime/marshaler_registry.go @@ -13,7 +13,11 @@ var ( acceptHeader = http.CanonicalHeaderKey("Accept") contentTypeHeader = http.CanonicalHeaderKey("Content-Type") - defaultMarshaler = &JSONPb{OrigName: true} + defaultMarshaler = &JSONPb{ + // Rewrite the field names to the proto3 json spec. + OrigName: false, + EmitDefaults: true, + } ) // MarshalerForRequest returns the inbound/outbound marshalers for this request.