As is our custom at Improving, we want to use protoc-gen-validate to write validation annotations to our protobuffers messages. We find this makes the semantic terms of an API much more comprehensible. This is supported for Scala via ScalaPB Validation and per its recommendations we’ve written a configuration function for sbt, like this:
def protoValidation(proj: Project): Project = {
proj.settings(
Compile / PB.targets := Seq(
scalapb.validate.preprocessor() -> (Compile / sourceManaged).value / "scalapb",
scalapb.gen() -> (Compile / sourceManaged).value / "scalapb",
scalapb.validate.gen() -> (Compile / sourceManaged).value / "scalapb"
),
libraryDependencies ++= Seq(
"com.thesamet.scalapb" %% "scalapb-validate-core" % scalapb.validate.compiler.BuildInfo.version % "protobuf",
)
)
}
However, there seems to be a conflict with the protoc plugins used with Kalix. When we apply the above sbt config function then Kalix does not generate the expected Scala code (Main.scala, for example) and when we don’t apply this function, it does generate that code. This is annoying, of course.
I haven’t found any documentation on kalix.io suggesting how to use protoc-gen-validate with Kalix nor any discussion here. So, I’m asking the Kalix community to be brilliant and show me how to do this. I think it would be highly useful if the Kalix Java/Scala SDK supported validation directly so the above sbt configuration wasn’t even necessary. protoc-gen-validate supports Java without any need for scalapb’s code generator.