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

inconsistent identifier capitalization between protoc-gen-go and protoc-gen-grpc-gateway #683

Closed
palohan opened this issue Jun 26, 2018 · 3 comments · Fixed by #866
Closed

Comments

@palohan
Copy link

palohan commented Jun 26, 2018

In the following proto file, notice the underscores, numbers (and possibly other characters) in identifiers:

syntax = "proto3";
import "google/api/annotations.proto";
package template;

service Greeter {
  rpc Sen_dGet (Temp_lateRequest) returns (template_response) {
      option (google.api.http).get = "/get";
  }
  rpc SendGe2t (Temp_lateRequest) returns (template_response) {
      option (google.api.http).get = "/get";
  }
}

message Temp_lateRequest {
  string name = 1;
}

message template_response {
  string name = 1;
}

After compiling such file, building the executables produces these errors:

../template/template.pb.gw.go:36:15: undefined: Temp_lateRequest
../template/template.pb.gw.go:43:20: client.Sen_dGet undefined (type GreeterClient has no field or method Sen_dGet)
../template/template.pb.gw.go:53:15: undefined: Temp_lateRequest
../template/template.pb.gw.go:60:20: client.SendGe2t undefined (type GreeterClient has no field or method SendGe2t, but does have SendGe2T)

Looking at the pb.go file, we can see the identifiers are different from those in pb.gw.go file

type GreeterClient interface {
	SenDGet(ctx context.Context, in *TempLateRequest, opts ...grpc.CallOption) (*TemplateResponse, error)
	SendGe2T(ctx context.Context, in *TempLateRequest, opts ...grpc.CallOption) (*TemplateResponse, error)
}

Judging from the code, this happens because protoc-gen-go uses CamelCase

./grpc/grpc.go:159:	servName := generator.CamelCase(origServName)
./grpc/grpc.go:283:	methName := generator.CamelCase(origMethName)

whereas protoc-gen-grpc-gateway simply calls strings.Title

./protoc-gen-grpc-gateway/gengateway/template.go:85:		svcName := strings.Title(*svc.Name)
./protoc-gen-grpc-gateway/gengateway/template.go:89:			methName := strings.Title(*meth.Name)
@johanbrandhorst
Copy link
Collaborator

I think the easiest fix here will be copy-pasting the protoc-gen-go generator logic into the generator, but it is problematic since long term they will inevitably deviate. This here is another source of incompatibility with protoc-gen-gogo as well since the latter allows a custom name to be used. I wish we could have some way of reading from the file we use but I don't think it's possible.

This should be reasonably easy to fix, anyway.

@waveywaves
Copy link
Contributor

@johanbrandhorst I am starting work on this issue. Do let me know if there is something I need to keep in mind.

@johanbrandhorst
Copy link
Collaborator

@waveywaves thanks! I don't think there's anything particular to keep in mind if we can easily port the logic from protoc-gen-go.

waveywaves added a commit to waveywaves/grpc-gateway that referenced this issue Feb 15, 2019
The incompatibility caused between the generated .pb.gw.go
and .pb.go files due to inconsistent identifier capitalization
has been fixed here.

Logic from protoc-gen-go for the Message, Service and Method
Names is ported to protoc-gen-grpc-gateway.

Have made changes in the template.go file and have written a
test so we don't regress this in the future.

This fixes grpc-ecosystem#683
waveywaves added a commit to waveywaves/grpc-gateway that referenced this issue Feb 15, 2019
The incompatibility caused between the generated .pb.gw.go
and .pb.go files due to inconsistent identifier capitalization
has been fixed here.

Logic from protoc-gen-go for the Message, Service and Method
Names is ported to protoc-gen-grpc-gateway.

Have made changes in the template.go file and have written a
test so we don't regress this in the future.

This fixes grpc-ecosystem#683
johanbrandhorst pushed a commit that referenced this issue Feb 15, 2019
The incompatibility caused between the generated .pb.gw.go
and .pb.go files due to inconsistent identifier capitalization
has been fixed here.

Logic from protoc-gen-go for the Message, Service and Method
Names is ported to protoc-gen-grpc-gateway.

Have made changes in the template.go file and have written a
test so we don't regress this in the future.

This fixes #683
adasari pushed a commit to adasari/grpc-gateway that referenced this issue Apr 9, 2020
The incompatibility caused between the generated .pb.gw.go
and .pb.go files due to inconsistent identifier capitalization
has been fixed here.

Logic from protoc-gen-go for the Message, Service and Method
Names is ported to protoc-gen-grpc-gateway.

Have made changes in the template.go file and have written a
test so we don't regress this in the future.

This fixes grpc-ecosystem#683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants