Adven27 / grpc-wiremock

gRPC Mock Server
MIT License
93 stars 40 forks source link

Handle compilation errors when protobuf message ends with Grpc #27

Closed krmahadevan closed 2 years ago

krmahadevan commented 2 years ago

Describe the bug A clear and concise description of what the bug is.

The grpc-wiremock tool assumes that in the generated code from the protobuf messages, only service classes would have its name end with Grpc.java. But a user can still end up defining a message which ends with Grpc. So when a message ends with Grpc, the tool ends up assuming that the message class is a service class and ends up adding a reference to the abstract ImplBase for it which does not exist.

To Reproduce Steps to reproduce the behavior:

  1. Use the below .proto file
```proto syntax="proto3"; package com.rationaleemotions; option java_multiple_files=true; message InputGrpc { string name = 1; } message OutputGrpc { string message = 1; } service HelloWorld { rpc greetUser (InputGrpc) returns (OutputGrpc); } ```
  1. Add a reference to the above proto file directory in the build.gradle and then run ./gradlew clean generateJava
  2. Now from within the IDE, open up the generated Java class src/main/java/io/adven/grpc/wiremock/Translator.java
  3. You will see the below mentioned problematic lines
@Service class ComRationaleemotionsHelloWorld extends com.rationaleemotions.HelloWorldGrpc.HelloWorldImplBase {}
@Service class ComRationaleemotionsInput extends com.rationaleemotions.InputGrpc.InputImplBase {}
@Service class ComRationaleemotionsOutput extends com.rationaleemotions.OutputGrpc.OutputImplBase {}

In the above generated code, only HelloWorldGrpc is a valid service class and so HelloWorldImplBase exists inside it. But this is not the case with InputGrpc and OutputGrpc

Expected behavior

The tool should not just rely on file names to distinguish service classes from message classes but it should be able to skip such ambiguous message classes that look like a service class based on file name.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

krmahadevan commented 2 years ago

I have raised a PR for this. It would be really great if this can be accepted and then an image released into docker hub.

I stumbled into this issue at work when I was trying to use this library for doing grpc mocking. I dont want to end up maintaining a docker image at work and would like to continue using this library with the fix.

Oh btw, thank you so much for this wonderful library. Awesome work πŸ‘

Adven27 commented 2 years ago

image released 1.3.4

Thanks for the kind words!

krmahadevan commented 2 years ago

@Adven27 - Thank you so much for helping with merging this PR and also in helping with a release as well. That was fast!! πŸ˜„