Skip to content

Latest commit

 

History

History
56 lines (36 loc) · 2.82 KB

README.md

File metadata and controls

56 lines (36 loc) · 2.82 KB

Snapshot Artifacts

Running the test harness (Linux only)

PGV repo includes a comprehensive test suite defined over these proto files.

To run this test suite against scalapb-validate:

  1. Run ./make_harness.sh. This will download a prebuilt statically-compiled executor built from protoc-gen-validate that runs the test harness.

  2. In SBT, run e2eJVM2_13/test:runMain scalapb.validate.ScalaHarness.

Adding the latest snapshot release to your project

  1. Note the latest snapshot version on Sonatype Snapshots

    Snapshot Artifacts

  2. 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
    
  3. 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"	
    )
    
  4. import validate/validate.proto in your protobufs and set up validators as described in protoc-gen-validate documentation.

  5. The generated code will generate a Validator object for each message class. For example, if you have a Person message, it will generate a PersonValidator object that has a validate(instance: Person) method that returns a validation Result.

Examples

See a full example at the examples directory.