diff --git a/examples/examplepb/a_bit_of_everything.pb.go b/examples/examplepb/a_bit_of_everything.pb.go index 18b174ac92f..452f6a8cdc0 100644 --- a/examples/examplepb/a_bit_of_everything.pb.go +++ b/examples/examplepb/a_bit_of_everything.pb.go @@ -78,13 +78,15 @@ type ABitOfEverything struct { BoolValue bool `protobuf:"varint,10,opt,name=bool_value,json=boolValue" json:"bool_value,omitempty"` StringValue string `protobuf:"bytes,11,opt,name=string_value,json=stringValue" json:"string_value,omitempty"` // TODO(yugui) add bytes_value - Uint32Value uint32 `protobuf:"varint,13,opt,name=uint32_value,json=uint32Value" json:"uint32_value,omitempty"` - EnumValue NumericEnum `protobuf:"varint,14,opt,name=enum_value,json=enumValue,enum=gengo.grpc.gateway.examples.examplepb.NumericEnum" json:"enum_value,omitempty"` - Sfixed32Value int32 `protobuf:"fixed32,15,opt,name=sfixed32_value,json=sfixed32Value" json:"sfixed32_value,omitempty"` - Sfixed64Value int64 `protobuf:"fixed64,16,opt,name=sfixed64_value,json=sfixed64Value" json:"sfixed64_value,omitempty"` - Sint32Value int32 `protobuf:"zigzag32,17,opt,name=sint32_value,json=sint32Value" json:"sint32_value,omitempty"` - Sint64Value int64 `protobuf:"zigzag64,18,opt,name=sint64_value,json=sint64Value" json:"sint64_value,omitempty"` - RepeatedStringValue []string `protobuf:"bytes,19,rep,name=repeated_string_value,json=repeatedStringValue" json:"repeated_string_value,omitempty"` + Uint32Value uint32 `protobuf:"varint,13,opt,name=uint32_value,json=uint32Value" json:"uint32_value,omitempty"` + EnumValue NumericEnum `protobuf:"varint,14,opt,name=enum_value,json=enumValue,enum=gengo.grpc.gateway.examples.examplepb.NumericEnum" json:"enum_value,omitempty"` + Sfixed32Value int32 `protobuf:"fixed32,15,opt,name=sfixed32_value,json=sfixed32Value" json:"sfixed32_value,omitempty"` + Sfixed64Value int64 `protobuf:"fixed64,16,opt,name=sfixed64_value,json=sfixed64Value" json:"sfixed64_value,omitempty"` + Sint32Value int32 `protobuf:"zigzag32,17,opt,name=sint32_value,json=sint32Value" json:"sint32_value,omitempty"` + Sint64Value int64 `protobuf:"zigzag64,18,opt,name=sint64_value,json=sint64Value" json:"sint64_value,omitempty"` + RepeatedStringValue []string `protobuf:"bytes,19,rep,name=repeated_string_value,json=repeatedStringValue" json:"repeated_string_value,omitempty"` + MappedStringValue map[string]string `protobuf:"bytes,20,rep,name=mapped_string_value,json=mappedStringValue" json:"mapped_string_value,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + MappedNestedValue map[string]*ABitOfEverything_Nested `protobuf:"bytes,21,rep,name=mapped_nested_value,json=mappedNestedValue" json:"mapped_nested_value,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` } func (m *ABitOfEverything) Reset() { *m = ABitOfEverything{} } @@ -99,6 +101,20 @@ func (m *ABitOfEverything) GetNested() []*ABitOfEverything_Nested { return nil } +func (m *ABitOfEverything) GetMappedStringValue() map[string]string { + if m != nil { + return m.MappedStringValue + } + return nil +} + +func (m *ABitOfEverything) GetMappedNestedValue() map[string]*ABitOfEverything_Nested { + if m != nil { + return m.MappedNestedValue + } + return nil +} + type ABitOfEverything_Nested struct { Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` Amount uint32 `protobuf:"varint,2,opt,name=amount" json:"amount,omitempty"` @@ -132,7 +148,7 @@ var _ grpc.ClientConn // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion1 +const _ = grpc.SupportPackageIsVersion2 // Client API for ABitOfEverythingService service @@ -325,28 +341,40 @@ func RegisterABitOfEverythingServiceServer(s *grpc.Server, srv ABitOfEverythingS s.RegisterService(&_ABitOfEverythingService_serviceDesc, srv) } -func _ABitOfEverythingService_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _ABitOfEverythingService_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ABitOfEverything) if err := dec(in); err != nil { return nil, err } - out, err := srv.(ABitOfEverythingServiceServer).Create(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).Create(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).Create(ctx, req.(*ABitOfEverything)) + } + return interceptor(ctx, in, info, handler) } -func _ABitOfEverythingService_CreateBody_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _ABitOfEverythingService_CreateBody_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ABitOfEverything) if err := dec(in); err != nil { return nil, err } - out, err := srv.(ABitOfEverythingServiceServer).CreateBody(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).CreateBody(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/CreateBody", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).CreateBody(ctx, req.(*ABitOfEverything)) + } + return interceptor(ctx, in, info, handler) } func _ABitOfEverythingService_BulkCreate_Handler(srv interface{}, stream grpc.ServerStream) error { @@ -375,16 +403,22 @@ func (x *aBitOfEverythingServiceBulkCreateServer) Recv() (*ABitOfEverything, err return m, nil } -func _ABitOfEverythingService_Lookup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _ABitOfEverythingService_Lookup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(sub2.IdMessage) if err := dec(in); err != nil { return nil, err } - out, err := srv.(ABitOfEverythingServiceServer).Lookup(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).Lookup(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Lookup", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).Lookup(ctx, req.(*sub2.IdMessage)) + } + return interceptor(ctx, in, info, handler) } func _ABitOfEverythingService_List_Handler(srv interface{}, stream grpc.ServerStream) error { @@ -408,40 +442,58 @@ func (x *aBitOfEverythingServiceListServer) Send(m *ABitOfEverything) error { return x.ServerStream.SendMsg(m) } -func _ABitOfEverythingService_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _ABitOfEverythingService_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ABitOfEverything) if err := dec(in); err != nil { return nil, err } - out, err := srv.(ABitOfEverythingServiceServer).Update(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).Update(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Update", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).Update(ctx, req.(*ABitOfEverything)) + } + return interceptor(ctx, in, info, handler) } -func _ABitOfEverythingService_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _ABitOfEverythingService_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(sub2.IdMessage) if err := dec(in); err != nil { return nil, err } - out, err := srv.(ABitOfEverythingServiceServer).Delete(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).Delete(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).Delete(ctx, req.(*sub2.IdMessage)) + } + return interceptor(ctx, in, info, handler) } -func _ABitOfEverythingService_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _ABitOfEverythingService_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(gengo_grpc_gateway_examples_sub.StringMessage) if err := dec(in); err != nil { return nil, err } - out, err := srv.(ABitOfEverythingServiceServer).Echo(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).Echo(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Echo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).Echo(ctx, req.(*gengo_grpc_gateway_examples_sub.StringMessage)) + } + return interceptor(ctx, in, info, handler) } func _ABitOfEverythingService_BulkEcho_Handler(srv interface{}, stream grpc.ServerStream) error { @@ -520,64 +572,70 @@ var _ABitOfEverythingService_serviceDesc = grpc.ServiceDesc{ } var fileDescriptor1 = []byte{ - // 932 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xc4, 0x56, 0xdd, 0x8e, 0xdb, 0x44, - 0x14, 0xc6, 0x49, 0xd6, 0x49, 0xc6, 0x9b, 0x6c, 0x3a, 0x15, 0xb0, 0x04, 0xd0, 0x6e, 0x4d, 0x0b, - 0x21, 0x54, 0x76, 0xeb, 0x20, 0x90, 0x2a, 0x81, 0xd4, 0xd0, 0x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0xed, 0x8d, 0x1e, 0x8e, 0x3f, 0x9e, 0x2b, 0xfc, 0x8b, 0x80, 0x2a, 0x27, - 0x76, 0x10, 0xe2, 0x5d, 0xaa, 0xde, 0x5d, 0xe6, 0x3b, 0x4c, 0xe6, 0x35, 0xbc, 0x69, 0xae, 0xb7, - 0x04, 0xfc, 0x1b, 0xb4, 0xe9, 0xbe, 0x67, 0x5e, 0xfe, 0x48, 0x6f, 0x33, 0x8d, 0xef, 0xb5, 0xb7, - 0x6c, 0x65, 0x6c, 0xc1, 0xef, 0x90, 0x78, 0x8f, 0x38, 0x04, 0xa4, 0x3e, 0x33, 0xd1, 0x9d, 0x24, - 0xa4, 0xd3, 0xec, 0x6e, 0x3b, 0xcd, 0x27, 0x30, 0xcd, 0xc1, 0xe4, 0x21, 0xc5, 0xca, 0x7f, 0x66, - 0x03, 0x69, 0x4a, 0xf2, 0xdd, 0xc9, 0xd4, 0xfd, 0x4f, 0xbc, 0x3c, 0x61, 0xc2, 0xbe, 0xc1, 0x37, - 0x37, 0x09, 0x23, 0xa0, 0x46, 0x5d, 0x26, 0xcf, 0xc9, 0xf0, 0x35, 0xb9, 0xa5, 0xce, 0xb5, 0x1c, - 0x1f, 0xc7, 0xee, 0xec, 0xb1, 0xd8, 0x10, 0xe3, 0x67, 0x42, 0xb1, 0x37, 0x6b, 0xf1, 0x85, 0xbe, - 0x94, 0x8a, 0xb6, 0xbe, 0xc0, 0x4c, 0x75, 0x7c, 0x81, 0x6f, 0x09, 0x7d, 0x69, 0x58, 0xcf, 0x27, - 0x37, 0x16, 0xd9, 0x1f, 0xd7, 0xde, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x17, 0x44, 0xcc, 0x34, - 0x66, 0x0b, 0x00, 0x00, + // 1026 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xc4, 0x57, 0xdd, 0x6e, 0x1b, 0x45, + 0x14, 0x66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 0xdb, 0xb5, 0xc3, 0xc3, 0x93, 0x56, 0x26, 0x8c, + 0x10, 0x28, 0x44, 0x91, 0xdd, 0x5b, 0x57, 0x36, 0x95, 0xad, 0xb2, 0xc9, 0xbf, 0xc9, 0x23, 0x28, + 0xba, 0x34, 0x08, 0x69, 0x6f, 0x3d, 0xb7, 0x99, 0xdf, 0xaa, 0x18, 0x9f, 0x68, 0x73, 0xe9, 0xd6, + 0xa6, 0xc9, 0xb5, 0x03, 0xce, 0x62, 0x26, 0x6c, 0x64, 0x03, 0x2a, 0x27, 0x03, 0x66, 0x85, 0xed, + 0xa1, 0x35, 0x88, 0xe8, 0x7a, 0x1e, 0x5d, 0xe6, 0x4c, 0xe0, 0xa6, 0x47, 0xb1, 0x85, 0xdc, 0x80, + 0xe5, 0x1e, 0x8b, 0x3a, 0x03, 0x9a, 0x20, 0x0a, 0x88, 0x50, 0xcc, 0x8a, 0xb0, 0x09, 0x08, 0x72, + 0xd8, 0x6e, 0xf8, 0xc1, 0xfb, 0x09, 0x62, 0x09, 0x11, 0x79, 0x13, 0xb8, 0x29, 0xe3, 0x88, 0x64, + 0x44, 0x11, 0x11, 0x05, 0xb3, 0x12, 0x49, 0x10, 0xc1, 0xb1, 0x6d, 0x24, 0x88, 0x2b, 0x88, 0x58, + 0xe2, 0x1c, 0xdb, 0x86, 0x00, 0xbc, 0x05, 0xd5, 0x13, 0xfb, 0x09, 0xed, 0x65, 0x24, 0x25, 0x84, + 0x14, 0xcd, 0xe5, 0xc4, 0x38, 0x09, 0xca, 0x78, 0xca, 0x08, 0xba, 0x92, 0x80, 0x52, 0xa6, 0x37, + 0x01, 0x3a, 0x8c, 0x0d, 0x12, 0x04, 0x20, 0xa2, 0x64, 0x96, 0x63, 0x4b, 0x26, 0x36, 0x08, 0x7d, + 0x4c, 0x55, 0x02, 0xa8, 0xf0, 0x2a, 0x54, 0x84, 0x6d, 0x22, 0x9e, 0xcc, 0x4b, 0x15, 0x21, 0x55, + 0x11, 0x4f, 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7c, 0x8e, 0xd5, 0x6c, 0x75, 0x1f, 0x33, 0xa2, 0xfd, 0xa3, 0x37, 0x94, 0xa6, + 0x89, 0xe7, 0x27, 0x55, 0xf7, 0x2f, 0xf1, 0x6a, 0x97, 0x0b, 0xfb, 0x9a, 0xdc, 0x9e, 0x25, 0x8c, + 0xa2, 0x1a, 0x7d, 0x2c, 0xae, 0x93, 0xe3, 0xd7, 0xd4, 0xba, 0x3e, 0x34, 0x32, 0x7c, 0xbc, 0xb7, + 0x23, 0x5e, 0x93, 0x63, 0x42, 0xce, 0x6d, 0xc5, 0xbd, 0x59, 0x8a, 0x07, 0xfa, 0xa5, 0x44, 0x34, + 0xf7, 0x00, 0x73, 0xd5, 0xf1, 0x00, 0xdf, 0x51, 0x76, 0x2b, 0xc7, 0xe5, 0xac, 0x72, 0x9d, 0x22, + 0xff, 0x17, 0xb2, 0xfd, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1b, 0x83, 0x65, 0x26, 0x33, 0x0d, + 0x00, 0x00, } diff --git a/examples/examplepb/a_bit_of_everything.proto b/examples/examplepb/a_bit_of_everything.proto index 406023ad010..162d8f3aec0 100644 --- a/examples/examplepb/a_bit_of_everything.proto +++ b/examples/examplepb/a_bit_of_everything.proto @@ -36,6 +36,8 @@ message ABitOfEverything { sint32 sint32_value = 17; sint64 sint64_value = 18; repeated string repeated_string_value = 19; + map mapped_string_value = 20; + map mapped_nested_value = 21; } message EmptyMessage { diff --git a/examples/examplepb/echo_service.pb.go b/examples/examplepb/echo_service.pb.go index 76cd1d1250c..4c78cacd2b6 100644 --- a/examples/examplepb/echo_service.pb.go +++ b/examples/examplepb/echo_service.pb.go @@ -60,7 +60,7 @@ var _ grpc.ClientConn // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion1 +const _ = grpc.SupportPackageIsVersion2 // Client API for EchoService service @@ -106,28 +106,40 @@ func RegisterEchoServiceServer(s *grpc.Server, srv EchoServiceServer) { s.RegisterService(&_EchoService_serviceDesc, srv) } -func _EchoService_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _EchoService_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(SimpleMessage) if err := dec(in); err != nil { return nil, err } - out, err := srv.(EchoServiceServer).Echo(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(EchoServiceServer).Echo(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.EchoService/Echo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EchoServiceServer).Echo(ctx, req.(*SimpleMessage)) + } + return interceptor(ctx, in, info, handler) } -func _EchoService_EchoBody_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _EchoService_EchoBody_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(SimpleMessage) if err := dec(in); err != nil { return nil, err } - out, err := srv.(EchoServiceServer).EchoBody(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(EchoServiceServer).EchoBody(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.EchoService/EchoBody", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EchoServiceServer).EchoBody(ctx, req.(*SimpleMessage)) + } + return interceptor(ctx, in, info, handler) } var _EchoService_serviceDesc = grpc.ServiceDesc{ diff --git a/examples/examplepb/flow_combination.pb.go b/examples/examplepb/flow_combination.pb.go index 40606b6eb0d..345f7ed5a8a 100644 --- a/examples/examplepb/flow_combination.pb.go +++ b/examples/examplepb/flow_combination.pb.go @@ -95,7 +95,7 @@ var _ grpc.ClientConn // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion1 +const _ = grpc.SupportPackageIsVersion2 // Client API for FlowCombination service @@ -368,16 +368,22 @@ func RegisterFlowCombinationServer(s *grpc.Server, srv FlowCombinationServer) { s.RegisterService(&_FlowCombination_serviceDesc, srv) } -func _FlowCombination_RpcEmptyRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _FlowCombination_RpcEmptyRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(EmptyProto) if err := dec(in); err != nil { return nil, err } - out, err := srv.(FlowCombinationServer).RpcEmptyRpc(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(FlowCombinationServer).RpcEmptyRpc(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.FlowCombination/RpcEmptyRpc", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FlowCombinationServer).RpcEmptyRpc(ctx, req.(*EmptyProto)) + } + return interceptor(ctx, in, info, handler) } func _FlowCombination_RpcEmptyStream_Handler(srv interface{}, stream grpc.ServerStream) error { @@ -453,40 +459,58 @@ func (x *flowCombinationStreamEmptyStreamServer) Recv() (*EmptyProto, error) { return m, nil } -func _FlowCombination_RpcBodyRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _FlowCombination_RpcBodyRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(NonEmptyProto) if err := dec(in); err != nil { return nil, err } - out, err := srv.(FlowCombinationServer).RpcBodyRpc(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(FlowCombinationServer).RpcBodyRpc(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.FlowCombination/RpcBodyRpc", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FlowCombinationServer).RpcBodyRpc(ctx, req.(*NonEmptyProto)) + } + return interceptor(ctx, in, info, handler) } -func _FlowCombination_RpcPathSingleNestedRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _FlowCombination_RpcPathSingleNestedRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(SingleNestedProto) if err := dec(in); err != nil { return nil, err } - out, err := srv.(FlowCombinationServer).RpcPathSingleNestedRpc(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(FlowCombinationServer).RpcPathSingleNestedRpc(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.FlowCombination/RpcPathSingleNestedRpc", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FlowCombinationServer).RpcPathSingleNestedRpc(ctx, req.(*SingleNestedProto)) + } + return interceptor(ctx, in, info, handler) } -func _FlowCombination_RpcPathNestedRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _FlowCombination_RpcPathNestedRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(NestedProto) if err := dec(in); err != nil { return nil, err } - out, err := srv.(FlowCombinationServer).RpcPathNestedRpc(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(FlowCombinationServer).RpcPathNestedRpc(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.FlowCombination/RpcPathNestedRpc", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FlowCombinationServer).RpcPathNestedRpc(ctx, req.(*NestedProto)) + } + return interceptor(ctx, in, info, handler) } func _FlowCombination_RpcBodyStream_Handler(srv interface{}, stream grpc.ServerStream) error { diff --git a/examples/examplepb/streamless_everything.proto b/examples/examplepb/streamless_everything.proto index a6d2145d8ab..6780a38f2ad 100644 --- a/examples/examplepb/streamless_everything.proto +++ b/examples/examplepb/streamless_everything.proto @@ -35,6 +35,8 @@ message ABitOfEverything { sint32 sint32_value = 17; sint64 sint64_value = 18; repeated string repeated_string_value = 19; + map mapped_string_value = 20; + map mapped_nested_value = 21; } message EmptyMessage { diff --git a/examples/examplepb/streamless_everything.swagger.json b/examples/examplepb/streamless_everything.swagger.json index 508508eb36e..4f24d9fd5a9 100644 --- a/examples/examplepb/streamless_everything.swagger.json +++ b/examples/examplepb/streamless_everything.swagger.json @@ -396,6 +396,19 @@ "type": "integer", "format": "int64" }, + "mapped_nested_value": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/ABitOfEverythingNested" + } + }, + "mapped_string_value": { + "type": "object", + "additionalProperties": { + "type": "string", + "format": "string" + } + }, "nested": { "type": "array", "items": { diff --git a/protoc-gen-swagger/genswagger/template.go b/protoc-gen-swagger/genswagger/template.go index 3793d0e5578..d163cabeee1 100644 --- a/protoc-gen-swagger/genswagger/template.go +++ b/protoc-gen-swagger/genswagger/template.go @@ -50,16 +50,28 @@ func findNestedMessagesAndEnumerations(message *descriptor.Message, reg *descrip func renderMessagesAsDefinition(messages messageMap, d swaggerDefinitionsObject, reg *descriptor.Registry) { for _, msg := range messages { + if opt := msg.GetOptions(); opt != nil && opt.MapEntry != nil && *opt.MapEntry { + continue + } object := swaggerSchemaObject{ - Type: "object", + Type: "object", Properties: map[string]swaggerSchemaObject{}, } for _, field := range msg.Fields { + fieldDescriptor := field.FieldDescriptorProto + mapEntry := false + if fieldMessage, err := reg.LookupMsg("", field.GetTypeName()); err == nil { + if opt := fieldMessage.GetOptions(); opt != nil && opt.MapEntry != nil && *opt.MapEntry { + fieldDescriptor = fieldMessage.GetField()[1] + mapEntry = true + } + } + var fieldType, fieldFormat string primitive := true // Field type and format from http://swagger.io/specification/ in the // "Data Types" table - switch field.FieldDescriptorProto.Type.String() { + switch fieldDescriptor.Type.String() { case "TYPE_DOUBLE": fieldType = "number" fieldFormat = "double" @@ -142,8 +154,17 @@ func renderMessagesAsDefinition(messages messageMap, d swaggerDefinitionsObject, } if primitive { - // If repeated render as an array of items. - if field.FieldDescriptorProto.GetLabel() == pbdescriptor.FieldDescriptorProto_LABEL_REPEATED { + switch { + case mapEntry: + object.Properties[field.GetName()] = swaggerSchemaObject{ + Type: "object", + AdditionalProperties: &swaggerSchemaObject{ + Type: fieldType, + Format: fieldFormat, + }, + } + case field.FieldDescriptorProto.GetLabel() == pbdescriptor.FieldDescriptorProto_LABEL_REPEATED: + // If repeated render as an array of items. object.Properties[field.GetName()] = swaggerSchemaObject{ Type: "array", Items: &swaggerItemsObject{ @@ -151,21 +172,29 @@ func renderMessagesAsDefinition(messages messageMap, d swaggerDefinitionsObject, Format: fieldFormat, }, } - } else { + default: object.Properties[field.GetName()] = swaggerSchemaObject{ Type: fieldType, Format: fieldFormat, } } } else { - if field.FieldDescriptorProto.GetLabel() == pbdescriptor.FieldDescriptorProto_LABEL_REPEATED { + switch { + case mapEntry: + object.Properties[field.GetName()] = swaggerSchemaObject{ + Type: "object", + AdditionalProperties: &swaggerSchemaObject{ + Ref: "#/definitions/" + fullyQualifiedNameToSwaggerName(fieldDescriptor.GetTypeName(), reg), + }, + } + case field.FieldDescriptorProto.GetLabel() == pbdescriptor.FieldDescriptorProto_LABEL_REPEATED: object.Properties[field.GetName()] = swaggerSchemaObject{ Type: "array", Items: &swaggerItemsObject{ Ref: "#/definitions/" + fullyQualifiedNameToSwaggerName(field.GetTypeName(), reg), }, } - } else { + default: object.Properties[field.GetName()] = swaggerSchemaObject{ Ref: "#/definitions/" + fullyQualifiedNameToSwaggerName(field.GetTypeName(), reg), } diff --git a/protoc-gen-swagger/genswagger/types.go b/protoc-gen-swagger/genswagger/types.go index fd441683b1b..4cc8b538d7a 100644 --- a/protoc-gen-swagger/genswagger/types.go +++ b/protoc-gen-swagger/genswagger/types.go @@ -91,8 +91,9 @@ type swaggerSchemaObject struct { Type string `json:"type,omitempty"` Format string `json:"format,omitempty"` // Properties can be recursively defined - Properties map[string]swaggerSchemaObject `json:"properties,omitempty"` - Items *swaggerItemsObject `json:"items,omitempty"` + Properties map[string]swaggerSchemaObject `json:"properties,omitempty"` + AdditionalProperties *swaggerSchemaObject `json:"additionalProperties,omitempty"` + Items *swaggerItemsObject `json:"items,omitempty"` // If the item is an enumeration include a list of all the *NAMES* of the // enum values. I'm not sure how well this will work but assuming all enums