PGV repo includes a comprehensive test suite defined over these proto files.
To run this test suite against scalapb-validate:
-
Run
./make_harness.sh
. This will download a prebuilt statically-compiled executor built from protoc-gen-validate that runs the test harness. -
In SBT, run
e2eJVM2_13/test:runMain scalapb.validate.ScalaHarness
.
-
Note the latest snapshot version on Sonatype Snapshots
-
Add the following to your
project/plugins.sbt
, replace the validateVersion value with the snapshot version you have found in the previous step:ThisBuild / resolvers += Resolver.sonatypeRepo("snapshots") addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.34") libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.10.8" val validateVersion = "0.1.2" libraryDependencies += "com.thesamet.scalapb" %% "scalapb-validate-codegen" % validateVersion
-
Add the following to your
build.sbt
:ThisBuild / resolvers += Resolver.sonatypeRepo("snapshots") Compile / PB.targets := Seq( 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" )
-
import
validate/validate.proto
in your protobufs and set up validators as described in protoc-gen-validate documentation. -
The generated code will generate a Validator object for each message class. For example, if you have a
Person
message, it will generate aPersonValidator
object that has avalidate(instance: Person)
method that returns a validationResult
.
See a full example at the examples directory.