apache / pekko-grpc

Apache Pekko gRPC
https://pekko.apache.org/
Apache License 2.0
39 stars 17 forks source link

Codegen generates invalid java code (wrong types) for nested protobuf message in grpc call #328

Closed Siedlerchr closed 3 months ago

Siedlerchr commented 3 months ago

I am using gradle codegen plugin latest version 1.1.0 my Protobuf looks like this:

syntax = "proto3";

option java_generate_equals_and_hash = true;
option java_package = "org.example.service.v1";

message EnvelopeTest {
  oneof type
  {
    RequestTest request = 4;
    ResponseTest response = 6;
  }
  message RequestTest {
  }
  message ResponseTest {
  }
}

service TestGrpcsService {
  rpc Transceive(EnvelopeTest.RequestTest) returns (stream EnvelopeTest.ResponseTest) {}
}

However, the generated code does not compile due to wrong types, it's missing the EnvelopeTest in between, e.g. manually changing to solves the problem.

e.g. .../build/generated/source/proto/main/pekkoGrpc/org/example/service/v1/TestGrpcsServiceClientPowerApi.java:19: error: cannot find symbol public StreamResponseRequestBuilder<org.example.service.v1.Test.RequestTest, org.example.service.v1.Test.ResponseTest> transceive() ^ symbol: class RequestTest location: class Test

pjfanning commented 3 months ago

ScalaPB is what is being used under the hood to generate Scala classes from proto files. Maybe you could try testing with just ScalaPB to see if the issue is there.

https://github.com/scalapb/ScalaPB

raboof commented 3 months ago

Actually TestGrpcsServiceClientPowerApi.java is being generated by 'us' (https://github.com/apache/pekko-grpc/blob/main/codegen/src/main/twirl/templates/JavaClient/ClientPowerApi.scala.txt et al), while the RequestTest class is generated by (I think?) grpc-java. There appears to be a mismatch between the two in this case.

Do you get the same problem when you try with sbt rather than gradle? the sbt plugin is somewhat better-tested, and that might help narrow down whether the problem is in the gradle build/plugin or with the code generator component.

Siedlerchr commented 3 months ago

I tested the gradle plugin in scala mode by adding an empty scala file and the generated scala class looks correct. I wil try with sbt now

/*
 * Generated by Apache Pekko gRPC. DO NOT EDIT.
 */
@PekkoGrpcGenerated
trait TestGrpcsServicePowerApi {

  def transceive(in: org.example.service.v1.EnvelopeTest.RequestTest, metadata: pekko.grpc.scaladsl.Metadata): org.apache.pekko.stream.scaladsl.Source[org.example.service.v1.EnvelopeTest.ResponseTest, org.apache.pekko.NotUsed]

}
Siedlerchr commented 3 months ago

Okay, tested with sbt as well, this time in java mode again I used the template and just replaced it with my proto file and updated to latest pekko version and scala 3, same problem:

[error] .../testprotof/target/scala-3.4.2/pekko-grpc/main/org/example/service/v1/TestGrpcsService.java:14:1: Symbol nicht gefunden
[error]   Symbol: Klasse RequestTest
[error]   Ort: Klasse org.example.service.v1.Test
[error] org.example.service.v1.Test.RequestTest
raboof commented 3 months ago

@Siedlerchr I merged a possible fix in #331, could you test the nightly build once it's been published?