Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand ignore_empty into ignore to handle other semantics #137

Merged
merged 6 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions proto/protovalidate/buf/validate/validate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ message FieldConstraints {
// described as "serialized in the wire format," which follows the following rules:
//
// - the following "nullable" fields must be explicitly set to be considered present:
// - singular message fields (may be their empty value)
// - singular message fields (whose fields may be unpopulated/default values)
// - member fields of a oneof (may be their default value)
// - proto3 optional fields (may be their default value)
// - proto2 scalar fields
Expand All @@ -160,22 +160,22 @@ message FieldConstraints {
// }
// ```
bool required = 25;
// If `ignore_empty` is true and applied to a non-nullable field (see
// `required` for more details), validation is skipped on the field if it is
// the default or empty value. Adding `ignore_empty` to a "nullable" field is
// a noop as these unset fields already skip validation (with the exception
// of `required`).
// DEPRECATED: use ignore=IGNORE_EMPTY instead.
bool ignore_empty = 26 [deprecated = true];
// Skip validation on the field if its value matches the specified rule.
//
// ```proto
// message MyRepeated {
// // The field `value` min_len rule is only applied if the field isn't empty.
// repeated string value = 1 [
// (buf.validate.field).ignore_empty = true,
// (buf.validate.field).min_len = 5
// message UpdateRequest {
// // The uri rule only applies if the field is populated and not an empty
// // string.
// optional string url = 1 [
// (buf.validate.field).ignore = IGNORE_DEFAULT,
// (buf.validate.field).string.uri = true,
// ];
// }
// ```
bool ignore_empty = 26;
Ignore ignore = 27;

oneof type {
// Scalar Field Types
FloatRules float = 1;
Expand Down Expand Up @@ -206,6 +206,19 @@ message FieldConstraints {
}
}

// Specifies how FieldConstraints.ignore behaves. See the documentation for
// FieldConstraints.required for definitions of "populated" and "nullable".
enum Ignore {
// Validation is never skipped on the field unless it's an unpopulated
// nullable field.
IGNORE_UNSPECIFIED = 0;
// Validation is skipped if the field is unpopulated.
IGNORE_EMPTY = 1;
// Validation is skipped if the field is unpopulated or if it is a nullable
// field populated with its default value.
IGNORE_DEFAULT = 2;
}

// FloatRules describes the constraints applied to `float` values. These
// rules may also be applied to the `google.protobuf.FloatValue` Well-Known-Type.
message FloatRules {
Expand Down
Loading