Skip to content

Commit ccf1e1a

Browse files
Updates docs for ScalaPB Validation (#1518)
* Updates docs for ScalaPB Validation * Adds explanation about how to enable the validation * Apply suggestions from code review Co-authored-by: Francisco Diaz <[email protected]> Co-authored-by: Francisco Diaz <[email protected]>
1 parent 02b9fb1 commit ccf1e1a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

microsite/src/main/docs/reference/source-generation.md

+27
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ muSrcGenSerializationType := SerializationType.Protobuf // or SerializationType.
8181
| `muSrcGenCompressionType` | The compression type that will be used by generated RPC services. Set to `higherkindness.mu.rpc.srcgen.Model.GzipGen` for Gzip compression. | `higherkindness.mu.rpc.srcgen.Model.NoCompressionGen` |
8282
| `muSrcGenIdiomaticEndpoints` | Flag indicating if idiomatic gRPC endpoints should be used. If `true`, the service operations will be prefixed by the namespace. | `true` |
8383
| `muSrcGenProtocVersion` | Specifies the protoc version that [ScalaPB](https://scalapb.github.io/) should use when generating source files from proto files. | `None` (let ScalaPB choose the protoc version) |
84+
| `muSrcGenValidateProto` | Flag indicating if the plugin should generate validation methods based on rules and constraints defined in the specs. Only proto is supported at this moment. | `false` |
8485

8586
### muSrcGenJarNames
8687

@@ -109,6 +110,32 @@ sbt module containing the IDL definitions (`foo-domain`):
109110
//...
110111
```
111112

113+
### muSrcGenValidateProto
114+
115+
The sbt-mu-srcgen supports the plugin [scalapb-validate](https://github.com/scalapb/scalapb-validate).
116+
This plugin generates validators for your models, using the base validators defined by the [PGV protoc plugin](https://github.com/envoyproxy/protoc-gen-validate)
117+
118+
As you probably guessed, this is only compatible with proto and the setting will be ignored when working with Avro files.
119+
120+
To enable the validation methods generation, you need to set the setting `muSrcGenValidateProto` to true and
121+
import the PVG validators provided transitively by the `scalapb-validate-core` protobuf library:
122+
123+
```
124+
//...
125+
.settings(
126+
Seq(
127+
muSrcGenIdlType := IdlType.Proto,
128+
muSrcGenTargetDir := (Compile / sourceManaged).value / "compiled_proto",
129+
muSrcGenValidateProto := true,
130+
libraryDependencies ++= Seq(
131+
"com.thesamet.scalapb" %% "scalapb-validate-core" % scalapb.validate.compiler.BuildInfo.version % "protobuf",
132+
"io.higherkindness" %% "mu-rpc-service" % V.muRPC
133+
)
134+
)
135+
)
136+
//...
137+
```
138+
112139
## Implementation Notes: An Intentional Incompatibility with the Avro Standard
113140

114141
In order to make it easier for users to evolve their schemas over time,

0 commit comments

Comments
 (0)