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

Option -module does not work anymore for protoc-gen-grpc-gateway v2 #1753

Closed
olivierlemasle opened this issue Oct 14, 2020 · 1 comment · Fixed by #1754
Closed

Option -module does not work anymore for protoc-gen-grpc-gateway v2 #1753

olivierlemasle opened this issue Oct 14, 2020 · 1 comment · Fixed by #1754

Comments

@olivierlemasle
Copy link
Contributor

🐛 Bug Report

The option module fails for protoc-gen-grpc-gateway v2.

Actually, the issue is that the module prefix is removed a first time by protoc-gen-grpc-gateway, then protogen attempts to remove the prefix a second time. It then fails with an error "generated file does not match prefix".

To Reproduce

  1. Create a service file service.proto:

    syntax = "proto3";
    package your.service.v1;
    option go_package = "github.com/yourorg/yourproject/your/service/v1";
    message StringMessage {
      string value = 1;
    }
    service YourService {
      rpc Echo(StringMessage) returns (StringMessage) {}
    }
  2. Generate protobuf definitions and go-grpc with option module=:

    protoc -I . \
       --go_out . \
       --go_opt module=github.com/yourorg/yourproject \
       --go-grpc_out . \
       --go-grpc_opt module=github.com/yourorg/yourproject \
       service.proto
    

    It generates definitions in the right directory:
    image

  3. Then, use protoc-gen-grpc-gateway with the same module= option:

    protoc -I . \
       --grpc-gateway_out . \
        --grpc-gateway_opt module=github.com/yourorg/yourproject \
       --grpc-gateway_opt logtostderr=true \
       --grpc-gateway_opt generate_unbound_methods=true \
       service.proto
    

    It fails with:

    --grpc-gateway_out: your/service/v1/service.pb.gw.go: generated file does not match prefix "github.com/yourorg/yourproject"
    

Expected behavior

I'd expect the last command to generate your/service/v1/service_grpc.pb.go.

Actual Behavior

See above

Your Environment

Fedora 32

➜  protoc --version
libprotoc 3.11.2
➜  protoc-gen-go-grpc -version
protoc-gen-go-grpc 1.0
olivierlemasle added a commit to olivierlemasle/grpc-gateway that referenced this issue Oct 14, 2020
When option module=... is used, protoc-gen-grpc-gateway removes the module
prefix a first time, then uses protogen, which tries to remove the prefix
a second time.

Fixes grpc-ecosystem#1753
@olivierlemasle
Copy link
Contributor Author

Created PR #1754 to fix it

olivierlemasle added a commit to olivierlemasle/grpc-gateway that referenced this issue Oct 14, 2020
When option module=... is used, protoc-gen-grpc-gateway removes the module
prefix a first time, then uses protogen, which tries to remove the prefix
a second time.

Fixes grpc-ecosystem#1753
johanbrandhorst pushed a commit that referenced this issue Oct 15, 2020
When option module=... is used, protoc-gen-grpc-gateway removes the module
prefix a first time, then uses protogen, which tries to remove the prefix
a second time.

Fixes #1753
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant