Skip to content

Releases: bufbuild/protovalidate-cc

v0.4.0

17 Dec 16:03
15d5717
Compare
Choose a tag to compare

Breaking Change: The buf::validate::Validator::Validate method no longer returns a StatusOr containing a buf::validate::Violations message, but a StatusOr containing an instance of the new buf::validate::ValidationResult class. In most cases, using the proto() method of the violation is all that needs to be done:

     auto result = validator.Validate(message).value();
     for (int i = 0; i < result.violations_size(); i++) {
-        puts(result.violation(i).GetMessage().c_str())
+        puts(result.violation(i).proto().GetMessage().c_str())
     }

buf::validate::ValidationResult itself also has a proto() method that returns the protobuf buf::validate::Violations message equivalent.


The new buf::validate::ConstraintViolation class provides additional in-memory information about the violation which cannot be serialized to the wire:

  • field_value(): Returns an absl::optional containing a buf::validate::ProtoField pointing to the value of the field failing validation, if there is a field corresponding to the violation.
  • rule_value(): Returns an absl::optional containing a buf::validate::ProtoField pointing to 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 with email set to "invalid", the violation's field_value()->variant() will contain "invalid" and the rule_value()->variant() will contain true.

Some violations do not correspond directly to a field, such as a message constraint failure; in these cases, the field_value() will return absl::nullopt.

What's Changed

Full Changelog: v0.3.0...v0.4.0

v0.3.0

24 Sep 14:16
b03f050
Compare
Choose a tag to compare

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 includes the headers buf/validate/expression.pb.h or buf/validate/priv/private.pb.h now only needs to include buf/validate/validate.pb.h.
  • buf::validate::priv::field was moved to buf::validate::predefined and is no longer considered an internal implementation detail.

Note

This release requires Protobuf v27+. Depending on your WORKSPACE configuration, you may not have a new enough Protobuf version to support Protobuf Editions. For correct functionality, ensure that you set up a repository rule to import a newer version of Protobuf, as well as setting the --proto_compiler and --proto_toolchain_for_* Bazel build flags as necessary (see here for an example.)

What's Changed

Full Changelog: v0.2.0...v0.3.0

v0.2.0

15 Aug 16:07
a01c79d
Compare
Choose a tag to compare

Adds support for the string.host_and_port CEL utility function and Protobuf Editions, and bumps the versions of various dependencies.

Note

This release requires Protobuf v27+. Depending on your WORKSPACE configuration, you may not have a new enough Protobuf version to support Protobuf Editions. For correct functionality, ensure that you set up a repository rule to import a newer version of Protobuf, as well as setting the --proto_compiler and --proto_toolchain_for_* Bazel build flags as necessary (see here for an example.)

What's Changed

New Contributors

Full Changelog: v0.1.0...v0.2.0

v0.1.0

15 Dec 17:02
f170a7b
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: https://github.com/bufbuild/protovalidate-cc/commits/v0.1.0