Breaking Change: The build.buf.protovalidate.ValidationResult.getViolations()
method no longer returns a list of protobuf build.buf.validate.Violations
messages, but a list of a new wrapper class, build.buf.protovalidate.Violation
. In most cases, changing the import for Violation
and calling the toProto()
method of the violation is all that needs to be done:
// Note that the import should also change from `build.buf.validate.Violation`
// to `build.buf.protovalidate.Violation`.
for (Violation violation : validator.validate(msg).getViolations()) {
- System.out.println(violation.getConstraintId());
+ System.out.println(violation.toProto().getConstraintId());
}
ValidationResult
also has a toProto()
method that returns the protobuf build.buf.validate.Violations
message equivalent. This can be used to get a list of protobuf build.buf.validate.Violation
messages, using the getViolationsList()
getter of said message, as before.
+ List<build.buf.validate.Violation> violations = validator.validate(msg).getViolations();
- List<build.buf.validate.Violation> violations = validator.validate(msg).toProto().getViolationsList();
The new build.buf.protovalidate.Violation
class provides additional getters for in-memory information about the violation which cannot be serialized to the wire:
getFieldValue()
: Returns the value of the field failing validation, if there is a field corresponding to the violation.getRuleValue()
: Returns the value of the rule failing validation, if there is a rule corresponding to the violation.
Take, for example, the following protobuf message schema:
message User {
string email = 1 [(buf.validate.field).string.email = true];
}
If you try to validate the message User.newBuilder().setEmail("invalid").build()
, getFieldValue().getValue()
will return "invalid"
and getRuleValue().getValue()
will return true
.
Some violations do not correspond directly to a field, such as a message constraint failure; in these cases, the return value of getFieldValue()
will be null.
What's Changed
- Bump org.junit:junit-bom from 5.11.1 to 5.11.2 by @dependabot in #194
- Bump com.google.errorprone:error_prone_core from 2.32.0 to 2.33.0 by @dependabot in #193
- Update to gradle 8.10.2 by @pkwarren in #195
- Regenerate code with protoc 28.2 by @pkwarren in #196
- Bump net.ltgt.errorprone from 4.0.1 to 4.1.0 by @dependabot in #199
- Bump build.buf:buf from 1.44.0 to 1.45.0 by @dependabot in #197
- Bump com.uber.nullaway:nullaway from 0.11.3 to 0.12.0 by @dependabot in #201
- Bump maven-publish from 0.29.0 to 0.30.0 by @dependabot in #198
- Bump com.google.errorprone:error_prone_core from 2.33.0 to 2.34.0 by @dependabot in #200
- Bump org.junit:junit-bom from 5.11.2 to 5.11.3 by @dependabot in #203
- Bump com.google.errorprone:error_prone_core from 2.34.0 to 2.35.1 by @dependabot in #204
- Bump com.google.protobuf:protobuf-java from 4.28.2 to 4.28.3 by @dependabot in #205
- Bump build.buf:buf from 1.45.0 to 1.46.0 by @dependabot in #207
- Bump com.uber.nullaway:nullaway from 0.12.0 to 0.12.1 by @dependabot in #208
- Bump build.buf:buf from 1.46.0 to 1.47.2 by @dependabot in #209
- Fixes for complex predefined rule types by @jchadwick-buf in #210
- Bump com.google.errorprone:error_prone_core from 2.35.1 to 2.36.0 by @dependabot in #211
- Strict conformance fixes by @jchadwick-buf in #212
- Implement structured field and rule paths for violations by @jchadwick-buf in #213
- Add field and rule value to violations by @jchadwick-buf in #215
Full Changelog: v0.4.2...v0.5.0