From f720a4102c8907520debc52869532e44d4d0f22a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Vu=C4=8Dica?= Date: Sun, 17 Apr 2016 03:01:53 +0100 Subject: [PATCH] Allow period in path URL templates when generating Swagger templates. This allows for the templates to contain references to request proto messages' fields. --- examples/examplepb/a_bit_of_everything.pb.go | 276 +++++++++++------- .../examplepb/a_bit_of_everything.pb.gw.go | 58 ++++ examples/examplepb/a_bit_of_everything.proto | 7 + examples/examplepb/echo_service.pb.go | 34 ++- examples/examplepb/flow_combination.pb.go | 66 +++-- .../examplepb/streamless_everything.proto | 7 + .../streamless_everything.swagger.json | 37 +++ examples/server/a_bit_of_everything.go | 8 + protoc-gen-swagger/genswagger/template.go | 2 +- 9 files changed, 364 insertions(+), 131 deletions(-) diff --git a/examples/examplepb/a_bit_of_everything.pb.go b/examples/examplepb/a_bit_of_everything.pb.go index 18b174ac92f..10eca5f4e95 100644 --- a/examples/examplepb/a_bit_of_everything.pb.go +++ b/examples/examplepb/a_bit_of_everything.pb.go @@ -78,13 +78,14 @@ 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"` + SingleNested *ABitOfEverything_Nested `protobuf:"bytes,20,opt,name=single_nested,json=singleNested" json:"single_nested,omitempty"` } func (m *ABitOfEverything) Reset() { *m = ABitOfEverything{} } @@ -99,6 +100,13 @@ func (m *ABitOfEverything) GetNested() []*ABitOfEverything_Nested { return nil } +func (m *ABitOfEverything) GetSingleNested() *ABitOfEverything_Nested { + if m != nil { + return m.SingleNested + } + 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 +140,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 @@ -146,6 +154,7 @@ type ABitOfEverythingServiceClient interface { Delete(ctx context.Context, in *sub2.IdMessage, opts ...grpc.CallOption) (*EmptyMessage, error) Echo(ctx context.Context, in *gengo_grpc_gateway_examples_sub.StringMessage, opts ...grpc.CallOption) (*gengo_grpc_gateway_examples_sub.StringMessage, error) BulkEcho(ctx context.Context, opts ...grpc.CallOption) (ABitOfEverythingService_BulkEchoClient, error) + DeepPathEcho(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*ABitOfEverything, error) } type aBitOfEverythingServiceClient struct { @@ -307,6 +316,15 @@ func (x *aBitOfEverythingServiceBulkEchoClient) Recv() (*gengo_grpc_gateway_exam return m, nil } +func (c *aBitOfEverythingServiceClient) DeepPathEcho(ctx context.Context, in *ABitOfEverything, opts ...grpc.CallOption) (*ABitOfEverything, error) { + out := new(ABitOfEverything) + err := grpc.Invoke(ctx, "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/DeepPathEcho", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for ABitOfEverythingService service type ABitOfEverythingServiceServer interface { @@ -319,34 +337,47 @@ type ABitOfEverythingServiceServer interface { Delete(context.Context, *sub2.IdMessage) (*EmptyMessage, error) Echo(context.Context, *gengo_grpc_gateway_examples_sub.StringMessage) (*gengo_grpc_gateway_examples_sub.StringMessage, error) BulkEcho(ABitOfEverythingService_BulkEchoServer) error + DeepPathEcho(context.Context, *ABitOfEverything) (*ABitOfEverything, error) } func RegisterABitOfEverythingServiceServer(s *grpc.Server, srv ABitOfEverythingServiceServer) { 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 +406,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 +445,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 { @@ -470,6 +525,24 @@ func (x *aBitOfEverythingServiceBulkEchoServer) Recv() (*gengo_grpc_gateway_exam return m, nil } +func _ABitOfEverythingService_DeepPathEcho_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 + } + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).DeepPathEcho(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/DeepPathEcho", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).DeepPathEcho(ctx, req.(*ABitOfEverything)) + } + return interceptor(ctx, in, info, handler) +} + var _ABitOfEverythingService_serviceDesc = grpc.ServiceDesc{ ServiceName: "gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService", HandlerType: (*ABitOfEverythingServiceServer)(nil), @@ -498,6 +571,10 @@ var _ABitOfEverythingService_serviceDesc = grpc.ServiceDesc{ MethodName: "Echo", Handler: _ABitOfEverythingService_Echo_Handler, }, + { + MethodName: "DeepPathEcho", + Handler: _ABitOfEverythingService_DeepPathEcho_Handler, + }, }, Streams: []grpc.StreamDesc{ { @@ -520,64 +597,67 @@ 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, 0x80, 0x90, 0x96, 0x5d, 0xe1, 0xa5, - 0x45, 0x8a, 0x84, 0x22, 0x27, 0x9e, 0xb8, 0xd6, 0x3a, 0x1e, 0xcb, 0x3f, 0xa1, 0x51, 0x14, 0x2e, - 0x7a, 0x85, 0xc4, 0x05, 0x12, 0x3c, 0x00, 0x12, 0x77, 0x20, 0xc1, 0x8b, 0xf4, 0x92, 0x57, 0xe0, - 0x41, 0x38, 0x1e, 0xff, 0x74, 0x9c, 0x22, 0x12, 0x52, 0x69, 0x7b, 0x97, 0x99, 0xf3, 0xcd, 0x77, - 0xbe, 0x73, 0xce, 0x37, 0xe3, 0xa0, 0x9b, 0xe4, 0x91, 0x31, 0xf3, 0x1c, 0x12, 0xa8, 0xe9, 0x0f, - 0x6f, 0xac, 0x1a, 0xa3, 0xb1, 0x1d, 0x8e, 0xe8, 0x74, 0x44, 0xe6, 0xc4, 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dd, 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, + // 984 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xc4, 0x56, 0xdd, 0x6e, 0x1b, 0x45, + 0x14, 0x66, 0x1d, 0xc7, 0xb1, 0x8f, 0x7f, 0xe2, 0x4e, 0xf9, 0x09, 0x06, 0x94, 0x74, 0x69, 0x21, + 0x98, 0x6a, 0x97, 0x6e, 0x2a, 0x10, 0x95, 0x00, 0x35, 0xd4, 0x20, 0xa4, 0x90, 0xc0, 0x86, 0x16, + 0x29, 0x12, 0xb2, 0xd6, 0xf6, 0xc4, 0x59, 0xc5, 0xde, 0x59, 0xed, 0x8f, 0x69, 0x64, 0x85, 0x8b, + 0xde, 0x80, 0xc4, 0x45, 0x25, 0x78, 0x00, 0xae, 0x41, 0x82, 0x77, 0xe0, 0x9a, 0x4b, 0x5e, 0x81, + 0x07, 0xe1, 0xcc, 0xcc, 0xee, 0x32, 0xeb, 0x22, 0x6c, 0x1c, 0x29, 0xbd, 0xdb, 0x99, 0xf3, 0xcd, + 0x37, 0xdf, 0x99, 0xf3, 0x9d, 0x99, 0x85, 0x9b, 0xf4, 0xa1, 0x33, 0xf6, 0x47, 0x34, 0x34, 0x93, + 0x0f, 0xbf, 0x67, 0x3a, 0xdd, 0x9e, 0x1b, 0x75, 0xd9, 0x71, 0x97, 0x4e, 0x68, 0x70, 0x16, 0x9d, + 0xb8, 0xde, 0xd0, 0xf0, 0x03, 0x16, 0x31, 0x72, 0x63, 0x48, 0xbd, 0x21, 0x33, 0x86, 0x81, 0xdf, + 0x37, 0x86, 0x4e, 0x44, 0xbf, 0x76, 0xce, 0x8c, 0x94, 0xc0, 0xc8, 0x08, 0x5a, 0x2f, 0x0f, 0x19, + 0x1b, 0x8e, 0xa8, 0xe9, 0xf8, 0xae, 0xe9, 0x78, 0x1e, 0x8b, 0x9c, 0xc8, 0x65, 0x5e, 0x28, 0x49, + 0x5a, 0xad, 0x6c, 0xcb, 0x30, 0xee, 0x99, 0x63, 0x1a, 0x86, 0xce, 0x90, 0x26, 0xb1, 0x97, 0xd4, + 0x98, 0x95, 0x0f, 0xea, 0xdf, 0x96, 0xa1, 0x79, 0x77, 0xd7, 0x8d, 0x0e, 0x8e, 0x3b, 0x99, 0x30, + 0x42, 0xa0, 0x18, 0xc7, 0xee, 0x60, 0x43, 0xdb, 0xd2, 0xb6, 0x2b, 0xb6, 0xf8, 0x26, 0x0f, 0xa0, + 0xe4, 0xd1, 0x30, 0xa2, 0x83, 0x8d, 0xc2, 0xd6, 0xca, 0x76, 0xd5, 0x7a, 0xdf, 0x58, 0x48, 0xb7, + 0x31, 0x4b, 0x6e, 0xec, 0x0b, 0x16, 0x3b, 0x61, 0x23, 0x9b, 0x50, 0x3d, 0x1e, 0x31, 0x27, 0xea, + 0x4e, 0x9c, 0x51, 0x4c, 0x37, 0x56, 0x70, 0xcb, 0x82, 0x0d, 0x62, 0xea, 0x01, 0x9f, 0x21, 0xd7, + 0xa0, 0x36, 0x60, 0x71, 0x6f, 0x44, 0x13, 0x44, 0x11, 0x11, 0x9a, 0x5d, 0x95, 0x73, 0x12, 0x82, + 0x1c, 0xae, 0x17, 0xbd, 0x7d, 0x3b, 0x41, 0xac, 0x22, 0x62, 0xc5, 0x06, 0x31, 0x95, 0x71, 0xc4, + 0x2a, 0xa2, 0x84, 0x88, 0xa2, 0x5d, 0x8d, 0x15, 0x88, 0xe4, 0xd8, 0xb1, 0x12, 0xc4, 0x1a, 0x22, + 0x56, 0x05, 0xc7, 0x8e, 0x25, 0x01, 0xaf, 0x42, 0xfd, 0xd8, 0x7d, 0x48, 0x07, 0x19, 0x49, 0x19, + 0x21, 0x25, 0xbb, 0x96, 0x4c, 0xe6, 0x41, 0x19, 0x4f, 0x05, 0x41, 0x6b, 0x09, 0x28, 0x65, 0x7a, + 0x05, 0xa0, 0xc7, 0xd8, 0x28, 0x41, 0x00, 0x22, 0xca, 0x76, 0x85, 0xcf, 0x64, 0x62, 0xc3, 0x28, + 0xc0, 0xa3, 0x4a, 0x00, 0x55, 0x51, 0x85, 0xaa, 0x9c, 0xcb, 0xe5, 0x93, 0xed, 0x52, 0x47, 0x48, + 0x5d, 0xe6, 0x93, 0x6e, 0xf2, 0x39, 0x00, 0xf5, 0xe2, 0x71, 0x02, 0x68, 0x20, 0xa0, 0x61, 0x59, + 0x0b, 0xd6, 0x6c, 0x3f, 0x1e, 0xd3, 0xc0, 0xed, 0x77, 0x70, 0xbd, 0x5d, 0xe1, 0x2c, 0x92, 0xf2, + 0x06, 0x34, 0xc2, 0x7c, 0x76, 0xeb, 0x48, 0xbb, 0x6e, 0xd7, 0xc3, 0x5c, 0x7a, 0x19, 0x2c, 0x3b, + 0xa9, 0x26, 0xc2, 0x9a, 0x29, 0x4c, 0xa9, 0x49, 0xa8, 0xe6, 0x70, 0x05, 0x41, 0x57, 0x30, 0x4d, + 0x25, 0x87, 0x04, 0x92, 0xf1, 0x10, 0x84, 0x10, 0x09, 0x49, 0x59, 0x2c, 0x78, 0x2e, 0xa0, 0x3e, + 0xc5, 0x5c, 0x06, 0xdd, 0xdc, 0xa9, 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8d, 0x6f, 0xb6, 0x16, 0x3c, 0x4a, 0x6e, 0xc1, 0x6f, 0xa0, 0x74, 0x8f, 0x8e, 0x28, 0x4a, + 0x7d, 0xa2, 0xa2, 0x4b, 0x49, 0x48, 0xaa, 0xd9, 0x5e, 0xb4, 0x9a, 0x7f, 0x60, 0x35, 0x3b, 0xfd, + 0x13, 0x46, 0x8c, 0xff, 0xdc, 0x0d, 0xa5, 0x19, 0xf2, 0x71, 0x4b, 0xd5, 0xfd, 0x4f, 0xbc, 0xde, + 0x17, 0xc2, 0xbe, 0x22, 0x37, 0xe7, 0x09, 0xa3, 0xa8, 0xc6, 0x9c, 0xca, 0xeb, 0xe4, 0xe8, 0x45, + 0xbd, 0x69, 0x4e, 0xac, 0x0c, 0xcf, 0x63, 0x77, 0x56, 0x45, 0xec, 0x88, 0x90, 0x27, 0x42, 0xdc, + 0x9b, 0x65, 0xde, 0xd0, 0x97, 0x92, 0xd1, 0xc2, 0x0d, 0x2c, 0x54, 0xf3, 0x06, 0x46, 0x6f, 0xfe, + 0xae, 0x41, 0x8d, 0xbf, 0x90, 0x9f, 0x39, 0xd1, 0x89, 0x50, 0x79, 0xf9, 0x37, 0xe4, 0x07, 0x42, + 0xf7, 0xbb, 0xfa, 0xed, 0xb9, 0x16, 0xc9, 0xfd, 0xbf, 0x18, 0xfc, 0x8f, 0x82, 0x7b, 0x76, 0xb7, + 0x7a, 0x54, 0xc9, 0xe8, 0x7b, 0x25, 0xf1, 0x87, 0xbf, 0xf3, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xdb, 0x03, 0xf3, 0x17, 0x8f, 0x0c, 0x00, 0x00, } diff --git a/examples/examplepb/a_bit_of_everything.pb.gw.go b/examples/examplepb/a_bit_of_everything.pb.gw.go index f6f214bfb5d..ac9ff9c1c4f 100644 --- a/examples/examplepb/a_bit_of_everything.pb.gw.go +++ b/examples/examplepb/a_bit_of_everything.pb.gw.go @@ -461,6 +461,37 @@ func request_ABitOfEverythingService_BulkEcho_0(ctx context.Context, client ABit } +func request_ABitOfEverythingService_DeepPathEcho_0(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ABitOfEverything + var metadata runtime.ServerMetadata + + if err := json.NewDecoder(req.Body).Decode(&protoReq); err != nil { + return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) + } + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["single_nested.name"] + if !ok { + return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "single_nested.name") + } + + err = runtime.PopulateFieldFromPath(&protoReq, "single_nested.name", val) + + if err != nil { + return nil, metadata, err + } + + msg, err := client.DeepPathEcho(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + // RegisterABitOfEverythingServiceHandlerFromEndpoint is same as RegisterABitOfEverythingServiceHandler but // automatically dials to "endpoint" and closes the connection when "ctx" gets done. func RegisterABitOfEverythingServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { @@ -744,6 +775,29 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se }) + mux.Handle("POST", pattern_ABitOfEverythingService_DeepPathEcho_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(ctx) + defer cancel() + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { + select { + case <-done: + case <-closed: + cancel() + } + }(ctx.Done(), cn.CloseNotify()) + } + resp, md, err := request_ABitOfEverythingService_DeepPathEcho_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, w, req, err) + return + } + + forward_ABitOfEverythingService_DeepPathEcho_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -769,6 +823,8 @@ var ( pattern_ABitOfEverythingService_Echo_2 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "example", "echo"}, "")) pattern_ABitOfEverythingService_BulkEcho_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "example", "a_bit_of_everything", "echo"}, "")) + + pattern_ABitOfEverythingService_DeepPathEcho_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "example", "a_bit_of_everything", "single_nested.name"}, "")) ) var ( @@ -793,4 +849,6 @@ var ( forward_ABitOfEverythingService_Echo_2 = runtime.ForwardResponseMessage forward_ABitOfEverythingService_BulkEcho_0 = runtime.ForwardResponseStream + + forward_ABitOfEverythingService_DeepPathEcho_0 = runtime.ForwardResponseMessage ) diff --git a/examples/examplepb/a_bit_of_everything.proto b/examples/examplepb/a_bit_of_everything.proto index 406023ad010..bce017617a2 100644 --- a/examples/examplepb/a_bit_of_everything.proto +++ b/examples/examplepb/a_bit_of_everything.proto @@ -36,6 +36,7 @@ message ABitOfEverything { sint32 sint32_value = 17; sint64 sint64_value = 18; repeated string repeated_string_value = 19; + Nested single_nested = 20; } message EmptyMessage { @@ -104,4 +105,10 @@ service ABitOfEverythingService { body: "*" }; } + rpc DeepPathEcho(ABitOfEverything) returns (ABitOfEverything) { + option (google.api.http) = { + post: "/v1/example/a_bit_of_everything/{single_nested.name}" + body: "*" + }; + } } 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..4c92ada16e1 100644 --- a/examples/examplepb/streamless_everything.proto +++ b/examples/examplepb/streamless_everything.proto @@ -35,6 +35,7 @@ message ABitOfEverything { sint32 sint32_value = 17; sint64 sint64_value = 18; repeated string repeated_string_value = 19; + Nested single_nested = 20; } message EmptyMessage { @@ -107,4 +108,10 @@ service ABitOfEverythingService { body: "*" }; } + rpc DeepPathEcho(ABitOfEverything) returns (ABitOfEverything) { + option (google.api.http) = { + post: "/v1/example/a_bit_of_everything/{single_nested.name}" + body: "*" + }; + } } diff --git a/examples/examplepb/streamless_everything.swagger.json b/examples/examplepb/streamless_everything.swagger.json index 508508eb36e..1136ee27f80 100644 --- a/examples/examplepb/streamless_everything.swagger.json +++ b/examples/examplepb/streamless_everything.swagger.json @@ -254,6 +254,40 @@ ] } }, + "/v1/example/a_bit_of_everything/{single_nested.name}": { + "post": { + "summary": "ABitOfEverythingService.DeepPathEcho", + "operationId": "DeepPathEcho", + "responses": { + "default": { + "description": "Description", + "schema": { + "$ref": "#/definitions/examplepbABitOfEverything" + } + } + }, + "parameters": [ + { + "name": "single_nested.name", + "in": "path", + "required": true, + "type": "string", + "format": "string" + }, + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/examplepbABitOfEverything" + } + } + ], + "tags": [ + "ABitOfEverythingService" + ] + } + }, "/v1/example/a_bit_of_everything/{uuid}": { "get": { "summary": "ABitOfEverythingService.Lookup", @@ -417,6 +451,9 @@ "type": "integer", "format": "int32" }, + "single_nested": { + "$ref": "#/definitions/ABitOfEverythingNested" + }, "sint32_value": { "type": "integer", "format": "int32" diff --git a/examples/server/a_bit_of_everything.go b/examples/server/a_bit_of_everything.go index 20f24214bd9..0506557251d 100644 --- a/examples/server/a_bit_of_everything.go +++ b/examples/server/a_bit_of_everything.go @@ -206,3 +206,11 @@ func (s *_ABitOfEverythingServer) BulkEcho(stream examples.ABitOfEverythingServi })) return nil } + +func (s *_ABitOfEverythingServer) DeepPathEcho(ctx context.Context, msg *examples.ABitOfEverything) (*examples.ABitOfEverything, error) { + s.m.Lock() + defer s.m.Unlock() + + glog.Info(msg) + return msg, nil +} diff --git a/protoc-gen-swagger/genswagger/template.go b/protoc-gen-swagger/genswagger/template.go index 3793d0e5578..5a38ab12f7e 100644 --- a/protoc-gen-swagger/genswagger/template.go +++ b/protoc-gen-swagger/genswagger/template.go @@ -296,7 +296,7 @@ func templateToSwaggerPath(path string) string { // Parts is now an array of segments of the path. Interestingly, since the // syntax for this subsection CAN be handled by a regexp since it has no // memory. - re := regexp.MustCompile("{([a-z][a-z0-9_]*).*}") + re := regexp.MustCompile("{([a-z][a-z0-9_.]*).*}") for index, part := range parts { parts[index] = re.ReplaceAllString(part, "{$1}") }