Skip to content

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

Closed
@olivierlemasle

Description

@olivierlemasle

🐛 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions