Skip to content

v0.8.0

Compare
Choose a tag to compare
@jchadwick-buf jchadwick-buf released this 12 Dec 16:35
· 3 commits to main since this release
a2088eb

Breaking Change: The protovalidate.ValidationError type is no longer a protobuf buf.validate.Violations message alias, but a struct containing a slice of protovalidate.Violation instances. In most cases, accessing the Proto member of the violation is all that needs to be done:

     for _, violation := range err.Violations {
-        fmt.Println(violation.GetMessage())
+        fmt.Println(violation.Proto.GetMessage())
     }

protovalidate.ValidationError still has a ToProto() method that returns the protobuf buf.validate.Violations message equivalent.


The new protovalidate.Violation structure contains additional in-memory information about the violation which cannot be serialized to the wire:

  • FieldValue: A protoreflect.Value containing the value of the field failing validation, if there is a field corresponding to the violation.
  • FieldDescriptor: A protoreflect.FieldDescriptor corresponding to the field failing validation.
  • RuleValue: A protoreflect.Value containing the value of the rule failing validation, if there is a rule corresponding to the violation.
  • RuleDescriptor: A protoreflect.FieldDescriptor corresponding to the rule failing validation.

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 struct pb.User{Email: "invalid"}, the FieldValue will be "invalid" and the RuleValue will be true.

Some violations do not correspond directly to a field, such as a message constraint failure; in these cases, the FieldValue will be an invalid value and the FieldDescriptor will be nil.

What's Changed

  • Implement structured field and rule paths, add field and rule values to ValidationErrors by @jchadwick-buf in #154
  • Bump the go group with 2 updates by @dependabot in #161

Full Changelog: v0.7.3...v0.8.0