grpc-gateway: grpc-gateway_out does not entirely obey the -M parameter

Hi,

I’m using grpc-gateway_out with the github.com/gogo/protobuf project and I came across a case where the grpc-gateway generated code is invalid when using the -M parameter to the compiler.

When using the google/protobuf/empty.proto and want to replace the generated file with one from github.com/gogo/protobuf/types/ via grpc-gateway_out=Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types the generated code will import github.com/gogo/protobuf/types as expected, but the code still uses the empty.Empty to reference the Empty struct.

This results in both an unused import and an undefined reference compile error. The correct action should be to use types.Empty in the generated functions in this case.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 7
  • Comments: 15

Commits related to this issue

Most upvoted comments

At work I wrote a post-generate workaround for this in python:

def correct_grpc_gateway_imports(package):
    '''
    Workaround for https://github.com/grpc-ecosystem/grpc-gateway/issues/229.
    Replace instances of 'empty.Empty' with 'types.Empty' in any files.
    '''
    for root, dirs, filenames in os.walk(package):
        for filename in filenames:
            with open(os.path.join(root, filename), 'r') as f:
                file_contents = f.read()

            file_contents = file_contents.replace('empty.Empty', 'types.Empty')

            with open(os.path.join(root, filename), 'w') as f:
                f.write(file_contents)