-
Notifications
You must be signed in to change notification settings - Fork 343
Open
Labels
FeatureNew feature or requestNew feature or request
Description
Feature
There are situations where a protovalidate rule is redundant. For example, both rules in the following example express the same requirement: The field hello cannot be "":
syntax="proto3";
import "buf/validate/validate.proto";
message Message {
string hello = 1 [
(buf.validate.field).required = true,
(buf.validate.field).string.min_len = 1
];
}
// error raised for an empty field:
// hello: value is required [required]It's similar for other standard rules:
syntax="proto3";
import "buf/validate/validate.proto";
message Message {
string email = 1 [
(buf.validate.field).required = true,
(buf.validate.field).string.email = true
];
}
// error raised for an empty field:
// email: value is required [required]In this case, removing the required rule would actually produce a more helpful error:
email: value is empty, which is not a valid email address [string.email]
This applies to many of the standard rules on fields with implicit presence when combined with the required rule, but it depends on rule values.
buf lint could detect such situations, and alert the user about redundant rules. This leads to a more simple schema, and better error messages.
Metadata
Metadata
Assignees
Labels
FeatureNew feature or requestNew feature or request