Releases: bufbuild/protovalidate-java
v0.8.0
Breaking Changes
New API for creating a validator.
Validators are now created via ValidatorFactory using a builder pattern. To migrate, users should make the following changes:
With no config
import build.buf.protovalidate.Validator;
+ import build.buf.protovalidate.ValidatorFactory;
- Validator validator = new Validator();
+ Validator validator = ValidatorFactory.newBuilder().build();With config
import build.buf.protovalidate.Validator;
+ import build.buf.protovalidate.ValidatorFactory;
Config cfg = Config.newBuilder().setFailFast(true).build();
- Validator validator = new Validator(cfg);
+ Validator validator = ValidatorFactory.newBuilder().withConfig(cfg).build();Also note that the returned type is an interface (still named Validator) and no longer a concrete class.
In addition to the above change, users can now seed the validator with descriptors for warming up the cache. To do so, use the buildWithDescriptors method on the builder. The signature is:
buildWithDescriptors(List<Descriptor>, boolean disableLazy) throws CompilationException, InvalidStateException;An example creating a validator with seed descriptors:
MyMessage msg = MyMessage.newBuilder().build();
List<Descriptor> seedDescriptors = new ArrayList<Descriptor>();
seedDescriptors.add(msg.getDescriptorForType());
try {
Validator validator = ValidatorFactory.newBuilder().buildWithDescriptors(seedDescriptors, false);
// Note you can also create a validator with a config
// Validator validator = ValidatorFactory.newBuilder().withConfig(cfg).buildWithDescriptors(seedDescriptors, false);
// Also note that the buildWithDescriptors function is what throws the exception so the validator
// builder can be created ahead of time with no need for catching an exception.
} catch (CompilationException ce) {
// Exception pre-warming the cache with the seed descriptors
} catch (IllegalStateException ise) {
// This is thrown if seedDescriptors is empty and disableLazy is true
}For more context on the changes, see PR #283.
ValidationResult.toString output changed
The toString method of ValidationResult will now print Validation OK if there are no violations. Previously, this text was always Validation error: regardless of whether there were any actual violations.
Protovalidate Compatibility
This release is compatible with Protovalidate v0.11.1.
What's Changed
- Refactor validator creation to support various configurations by @smaye81 in #283
- Fix operator in ValidationResult toString by @smaye81 in #286
- Upgrade to Protovalidate 0.11.1 by @smaye81 in #287
Full Changelog: v0.7.2...v0.8.0
v0.7.2
v0.7.1
What's Changed
- Add TypeScript / JavaScript to the supported languages in README.md by @jrinehart-buf in #279
- Bump com.uber.nullaway:nullaway from 0.12.6 to 0.12.7 by @dependabot in #280
- Switch from s01 to Maven central by @pkwarren in #281
Full Changelog: v0.7.0...v0.7.1
v0.7.0
Breaking Changes
-
The most notable change is that the validation for IP addresses and prefixes (both v4 and v6), email addresses, and URIs has been significantly enhanced to adhere to the relevant RFCs for each. Note that these tighter validations result in breaking changes as some previously-passing values may now be failures. Additionally, with regards to
string.email/isEmailvalidation, we no longer follow RFC 5322 and instead use the HTML standard's definition for valid email addresses.-
For more context on the validation changes and conformance tests added, see the corresponding PR in Protovalidate: bufbuild/protovalidate#320.
-
For full details of the validation changes as they apply to protovalidate-java, see #258.
-
-
In addition, all references to the usage of
constrainthave been changed torule. Previously, these were used interchangeably which led to some confusion. The v0.11.0 release of Protovalidate contains this full rename, which necessitated the change in protovalidate-java and was implemented in #273. As a result, any reference toconstraintin code will need to be changed torule.
What's Changed
This release is compatible with Protovalidate v0.11.0.
- Fix CEL bindings for maps for
thisvariable by @smaye81 in #278 - Fix some issues with custom format function by @smaye81 in #277
- Fix CEL bindings for lists for
thisvariable by @smaye81 in #276 - Fix IPv6 double colon parsing by @smaye81 in #274
- Upgrade to Protovalidate v0.11.0 by @smaye81 in #273
- Fix Ignore Always detection by @smaye81 in #272
- Implement getField CEL function by @jchadwick-buf in #271
- Upgrade validation logic by @smaye81 in #258
- Remove checked in generated code by @pkwarren in #263
- Update to Protovalidate 0.10.4 by @smaye81 in #259
- Prepare GitHub docs for shift to buf.build/docs by @jrinehart-buf in #238
Full Changelog: v0.6.0...v0.7.0
v0.6.0
Breaking Changes
The internal package has been removed. The APIs exposed in internal were never considered to be public, but were nonetheless possible for external packages to import. This is no longer possible. If you were relying on an API that was exposed via internal, please file an issue.
What's Changed
- Makefile: add GRADLE argument by @jchadwick-buf in #218
- Update Buf logo in README by @smallsamantha in #219
- Bump com.google.guava:guava from 33.3.1-jre to 33.4.0-jre by @dependabot in #224
- Update proto generated code to match runtime version by @pkwarren in #231
- Bump com.diffplug.spotless:spotless-plugin-gradle from 6.25.0 to 7.0.2 by @dependabot in #228, #234
- Bump org.assertj:assertj-core from 3.26.3 to 3.27.3 by @dependabot in #220, #225, #232
- Refactor the API for v1 by @jchadwick-buf in #226
- Add URN validation to URI rule by @smaye81 in #236
- Remove support for deprecated options by @jchadwick-buf in #235
- Bump com.uber.nullaway:nullaway from 0.12.1 to 0.12.4 by @dependabot in #217, #227, #239
- Bump maven-publish from 0.30.0 to 0.31.0 by @dependabot in #242
- Bump com.google.protobuf:protobuf-java from 4.28.3 to 4.30.1 by @dependabot in #216, #222, #230, #243
- Bump build.buf:buf from 1.47.2 to 1.50.1 by @dependabot in #221, #229, #233, #245
- Fix custom predefined rules with repeated nested message values by @jrinehart-buf in #246
- Bump org.junit:junit-bom from 5.11.3 to 5.12.1 by @dependabot in #223, #237, #244
- Update to protovalidate 0.10.3 by @timostamm in #247
New Contributors
- @smallsamantha made their first contribution in #219
- @smaye81 made their first contribution in #236
- @jrinehart-buf made their first contribution in #246
- @timostamm made their first contribution in #247
Full Changelog: v0.5.0...v0.6.0
v0.5.0
Breaking Changes
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
v0.4.2
What's Changed
- Bump com.google.guava:guava from 33.3.0-jre to 33.3.1-jre by @dependabot in #190
- Bump org.junit:junit-bom from 5.11.0 to 5.11.1 by @dependabot in #189
- Bump build.buf:buf from 1.41.0 to 1.44.0 by @dependabot in #192
- Bump com.google.protobuf:protobuf-java from 4.28.1 to 4.28.2 by @dependabot in #186
Full Changelog: v0.4.1...v0.4.2
v0.4.1
What's Changed
- Fix over-eager caching of Now variable by @jchadwick-buf in #191
Full Changelog: v0.4.0...v0.4.1
v0.4.0
Adds support for custom predefined field constraints. See the protovalidate documentation for more information.
Updates protovalidate to v0.8.1. Note that this is a breaking change. You may need to make some adjustments to your code:
- Code that imports
build.buf.validate.ExpressionProtoorbuild.buf.validate.priv.PrivateProtoshould now only importbuild.buf.validate.ValidateProto. build.buf.validate.priv.PrivateProto.fieldwas moved tobuild.buf.validate.ValidateProto.predefined
What's Changed
- Implement predefined field constraints by @jchadwick-buf in #178
Full Changelog: v0.3.2...v0.4.0
v0.3.2
What's Changed
- Login to the BSR for code generation by @pkwarren in #179
- Bump build.buf:buf from 1.40.1 to 1.41.0 by @dependabot in #180
- Bump com.google.errorprone:error_prone_core from 2.31.0 to 2.32.0 by @dependabot in #181
- Bump org.projectnessie.cel:cel-bom from 0.5.0 to 0.5.1 by @dependabot in #183
- Bump com.google.protobuf:protobuf-java from 4.28.0 to 4.28.1 by @dependabot in #182
- Bump com.uber.nullaway:nullaway from 0.11.2 to 0.11.3 by @dependabot in #184
Full Changelog: v0.3.1...v0.3.2