Skip to content

Commit

Permalink
move scalapb-validation sbt instructions to scripted
Browse files Browse the repository at this point in the history
  • Loading branch information
github-brice-jaglin committed Feb 15, 2021
1 parent b667ab9 commit 70ba7a2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 9 deletions.
10 changes: 1 addition & 9 deletions docs/src/main/paradox/apidesign.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,7 @@ Follow the [documentation](https://scalapb.github.io/docs/validation) to update
in order to generate the validators using `sbt-protoc` (@ref[used by Akka gRPC](buildtools/sbt.md#sbt-protoc-settings)).

With the default parameters and target set by Akka gRPC, additions to your `build.sbt` should be:
```scala
import scalapb.GeneratorOption._

libraryDependencies +=
"com.thesamet.scalapb" %% "scalapb-validate-core" % scalapb.validate.compiler.BuildInfo.version % "protobuf"

Compile / PB.targets +=
scalapb.validate.gen(FlatPackage) -> (Compile / akkaGrpcCodeGeneratorSettings / target).value
```
@@snip[build.sbt](/sbt-plugin/src/sbt-test/gen-scala-server/10-scalapb-validate/build.sbt) { #setup }

The `validate_at_construction` option can be particularly interesting in a server-side context
since method implementations will automatically receive pre-validated requests and will not
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resolvers += Resolver.sonatypeRepo("staging")
resolvers += Resolver.bintrayRepo("akka", "snapshots")

//#setup
import scalapb.GeneratorOption._

enablePlugins(AkkaGrpcPlugin)

libraryDependencies +=
"com.thesamet.scalapb" %% "scalapb-validate-core" % scalapb.validate.compiler.BuildInfo.version % "protobuf"
Compile / PB.targets +=
scalapb.validate.gen(FlatPackage) -> (Compile / akkaGrpcCodeGeneratorSettings / target).value
//#setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % sys.props("project.version"))

libraryDependencies ++= Seq("com.thesamet.scalapb" %% "scalapb-validate-codegen" % "0.2.1")
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
syntax = "proto3";

option java_package = "example.myapp.helloworld.grpc";

package helloworld;

import "validate/validate.proto";

// The greeting service definition.
service GreeterService {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}

rpc ItKeepsTalking (stream HelloRequest) returns (HelloReply) {}

rpc ItKeepsReplying (HelloRequest) returns (stream HelloReply) {}

rpc StreamHellos (stream HelloRequest) returns (stream HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
string name = 1 [(validate.rules).string.min_len = 3];;
}

// The response message containing the greetings
message HelloReply {
string message = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package example.myapp.helloworld

import scala.concurrent.Future

import akka.NotUsed
import akka.stream.scaladsl.Source

import example.myapp.helloworld.grpc._

class GreeterServiceImpl extends GreeterService {
override def sayHello(in: HelloRequest): Future[HelloReply] = ???

override def streamHellos(in: Source[HelloRequest, NotUsed]): Source[HelloReply, NotUsed] = ???

override def itKeepsTalking(in: Source[HelloRequest, NotUsed]): Future[HelloReply] = ???

override def itKeepsReplying(in: HelloRequest): Source[HelloReply, NotUsed] = ???

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> compile

0 comments on commit 70ba7a2

Please sign in to comment.