Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Service, Method, Message Identifiers to be CamelCased #866

Merged
merged 1 commit into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions protoc-gen-grpc-gateway/gengateway/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func (b binding) FieldMaskField() string {
fieldMaskField = f
}
}

if fieldMaskField != nil {
return generator2.CamelCase(fieldMaskField.GetName())
}
Expand Down Expand Up @@ -145,13 +144,18 @@ func applyTemplate(p param, reg *descriptor.Registry) (string, error) {
return "", err
}
var targetServices []*descriptor.Service

for _, msg := range p.Messages {
msgName := generator2.CamelCase(*msg.Name)
msg.Name = &msgName
}
for _, svc := range p.Services {
var methodWithBindingsSeen bool
svcName := strings.Title(*svc.Name)
svcName := generator2.CamelCase(*svc.Name)
svc.Name = &svcName
for _, meth := range svc.Methods {
glog.V(2).Infof("Processing %s.%s", svc.GetName(), meth.GetName())
methName := strings.Title(*meth.Name)
methName := generator2.CamelCase(*meth.Name)
meth.Name = &methName
for _, b := range meth.Bindings {
methodWithBindingsSeen = true
Expand Down
95 changes: 95 additions & 0 deletions protoc-gen-grpc-gateway/gengateway/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,98 @@ func TestAllowPatchFeature(t *testing.T) {
}
}
}

func TestIdentifierCapitalization(t *testing.T){
msgdesc1 := &protodescriptor.DescriptorProto{
Name: proto.String("Exam_pleRequest"),
}
msgdesc2 := &protodescriptor.DescriptorProto{
Name: proto.String("example_response"),
}
meth1 := &protodescriptor.MethodDescriptorProto{
Name: proto.String("ExampleGe2t"),
InputType: proto.String("Exam_pleRequest"),
OutputType: proto.String("example_response"),
}
meth2 := &protodescriptor.MethodDescriptorProto{
Name: proto.String("Exampl_eGet"),
InputType: proto.String("Exam_pleRequest"),
OutputType: proto.String("example_response"),
}
svc := &protodescriptor.ServiceDescriptorProto{
Name: proto.String("Example"),
Method: []*protodescriptor.MethodDescriptorProto{meth1, meth2},
}
msg1 := &descriptor.Message{
DescriptorProto: msgdesc1,
}
msg2 := &descriptor.Message{
DescriptorProto: msgdesc2,
}
file := descriptor.File{
FileDescriptorProto: &protodescriptor.FileDescriptorProto{
Name: proto.String("example.proto"),
Package: proto.String("example"),
Dependency: []string{"a.example/b/c.proto", "a.example/d/e.proto"},
MessageType: []*protodescriptor.DescriptorProto{msgdesc1, msgdesc2},
Service: []*protodescriptor.ServiceDescriptorProto{svc},
},
GoPkg: descriptor.GoPackage{
Path: "example.com/path/to/example/example.pb",
Name: "example_pb",
},
Messages: []*descriptor.Message{msg1, msg2},
Services: []*descriptor.Service{
{
ServiceDescriptorProto: svc,
Methods: []*descriptor.Method{
{
MethodDescriptorProto: meth1,
RequestType: msg1,
ResponseType: msg1,
Bindings: []*descriptor.Binding{
{
HTTPMethod: "GET",
Body: &descriptor.Body{FieldPath: nil},
},
},
},
},
},
{
ServiceDescriptorProto: svc,
Methods: []*descriptor.Method{
{
MethodDescriptorProto: meth2,
RequestType: msg2,
ResponseType: msg2,
Bindings: []*descriptor.Binding{
{
HTTPMethod: "GET",
Body: &descriptor.Body{FieldPath: nil},
},
},
},
},
},
},
}

got, err := applyTemplate(param{File: crossLinkFixture(&file), RegisterFuncSuffix: "Handler", AllowPatchFeature: true}, descriptor.NewRegistry())
if err != nil {
t.Errorf("applyTemplate(%#v) failed with %v; want success", file, err)
return
}
if want := `msg, err := client.ExampleGe2T(ctx, &protoReq, grpc.Header(&metadata.HeaderMD)`; !strings.Contains(got, want) {
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
}
if want := `msg, err := client.ExamplEGet(ctx, &protoReq, grpc.Header(&metadata.HeaderMD)`; !strings.Contains(got, want) {
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
}
if want := `var protoReq ExamPleRequest`; !strings.Contains(got, want) {
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
}
if want := `var protoReq ExampleResponse`; !strings.Contains(got, want) {
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
}
}