Skip to content

Commit

Permalink
Remove deprecated options (#297)
Browse files Browse the repository at this point in the history
Removes deprecated fields in `validate.proto`, removes mention of them
from relevant documentation, and replaces usages in the conformance
suite with the proper up-to-date options.

**This is a breaking change.**

Runtime PRs:
- Go: bufbuild/protovalidate-go#178
- C++: bufbuild/protovalidate-cc#69
- Python: bufbuild/protovalidate-python#246
- Java: bufbuild/protovalidate-java#235
  • Loading branch information
jchadwick-buf authored Jan 28, 2025
1 parent 65f2484 commit 79e5a7d
Show file tree
Hide file tree
Showing 31 changed files with 3,225 additions and 3,293 deletions.
3 changes: 1 addition & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ use_repo(go_deps, "com_github_bufbuild_protocompile", "com_github_spf13_pflag",

buf = use_extension("@rules_buf//buf:extensions.bzl", "buf")
buf.toolchains(
sha256 = "bb9d7b4a1fc9ddebc285faa09b9c3e4ce176b94585a1d7988371d73b208aa0f5",
version = "v1.35.0",
version = "v1.50.0",
)
6 changes: 3 additions & 3 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ load("@rules_buf//buf:repositories.bzl", "rules_buf_dependencies", "rules_buf_to

rules_buf_dependencies()

rules_buf_toolchains(version = "v1.35.0")
rules_buf_toolchains(version = "v1.50.0")

load("@rules_buf//gazelle/buf:repositories.bzl", "gazelle_buf_dependencies")

Expand Down
9 changes: 4 additions & 5 deletions docs/standard-constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ proper validations for each field type:
```protobuf
message FieldConstraints {
repeated Constraint cel = 23;
bool skipped = 24;
bool required = 25;
bool ignore_empty = 26;
Ignore ignore = 27;
oneof type {
// Scalar Field Types
// ...
Expand Down Expand Up @@ -212,13 +211,13 @@ message Event {

### Other constraints

`FieldConstraints` contains other constraints that can be applied to fields
including `skipped`, `required`, and `ignore_empty`.
`FieldConstraints` contains other constraints that can be applied to fields,
including `required` and `ignore`.

```protobuf
message Event {
int64 start_time = 1 [(buf.validate.field).required = true];
int64 end_time = 2[(buf.validate.field).ignore_empty = true];
int64 end_time = 2[(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED];
}
```

Expand Down
2 changes: 1 addition & 1 deletion examples/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ deps:
- buf.build/bufbuild/protovalidate
lint:
use:
- DEFAULT
- STANDARD
except:
- DIRECTORY_SAME_PACKAGE
- PACKAGE_DEFINED
Expand Down
6 changes: 3 additions & 3 deletions examples/option_field_ignore_empty.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ message SubmitFeedbackRequest {
string feedback = 1;
// email is the email.
string email = 2 [
// `ignore_empty` skips validation on a field if it's empty.
// The email will be not validated if it's empty.
(buf.validate.field).ignore_empty = true,
// `IGNORE_IF_UNPOPULATED` skips validation on a field if it's unpopulated.
// The email will be not validated if it's the empty string.
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
// `string.email` validates that a string field is a valid email.
(buf.validate.field).string.email = true
];
Expand Down
4 changes: 2 additions & 2 deletions examples/option_number_allow_values.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ service CarService {

message SearchCarRequest {
optional fixed32 number_of_seats = 1 [(buf.validate.field) = {
// `ignore_empty` skips validation if the field isn't set.
ignore_empty: true
// `IGNORE_IF_UNPOPULATED` skips validation if the field isn't set.
ignore: IGNORE_IF_UNPOPULATED
fixed32: {
// `in` requires that the value must be one of the specified values.
// In this case, it validates that the number of seats is either 5 or 7.
Expand Down
2 changes: 1 addition & 1 deletion examples/option_number_range.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ message CreateReviewRequest {
message CreateReviewResponse {
// aggregated_review is the aggregated review after this one in request is created.
// This value is empty if there are less than a 100 reviews submitted.
AggregatedReview aggregated_review = 1 [(buf.validate.field).ignore_empty = true];
AggregatedReview aggregated_review = 1 [(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED];
}

message AggregatedReview {
Expand Down
4 changes: 2 additions & 2 deletions examples/option_string_match_pattern.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ message UserProfile {
// must match it.
pattern: "^(\\+\\d{1,2}\\s)?\\(?\\d{3}\\)?[\\s.-]\\d{3}[\\s.-]\\d{4}$"
}
ignore_empty: true
ignore: IGNORE_IF_UNPOPULATED
}];
// `hostname` specifies that the field value must be a valid hostname as defined
// by [RFC 1034](https://tools.ietf.org/html/rfc1034#section-3.5).
Expand All @@ -43,7 +43,7 @@ message UserProfile {
// defined by [RFC 3986](https://tools.ietf.org/html/rfc3986#section-3).
// (buf.validate.field).string.uri_ref = true,
(buf.validate.field).string.uri = true,
(buf.validate.field).ignore_empty = true
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
];
// `ip` specifies that a string field must be a valid ip address, in either v4 or v6.
string last_login_at = 6 [(buf.validate.field).string.ip = true];
Expand Down
2 changes: 1 addition & 1 deletion proto/protovalidate-testing/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ breaking:
- buf/validate/conformance
lint:
use:
- DEFAULT
- STANDARD
except:
- PROTOVALIDATE
ignore_only:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ message BytesNotIPv6 {
message BytesIPv6Ignore {
bytes val = 1 [
(buf.validate.field).bytes.ipv6 = true,
(buf.validate.field).ignore_empty = true
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
];
}
message BytesExample {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ import "buf/validate/validate.proto";

message IgnoreEmptyProto2ScalarOptional {
optional int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}

message IgnoreEmptyProto2ScalarOptionalWithDefault {
optional int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0,
default = 42
];
}

message IgnoreEmptyProto2ScalarRequired {
required int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}

message IgnoreEmptyProto2Message {
optional Msg val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).cel = {
id: "ignore_empty.proto2.message"
message: "foobar"
Expand All @@ -57,22 +57,22 @@ message IgnoreEmptyProto2Message {
message IgnoreEmptyProto2Oneof {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}
}

message IgnoreEmptyProto2Repeated {
repeated int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).repeated.min_items = 3
];
}

message IgnoreEmptyProto2Map {
map<int32, int32> val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).map.min_pairs = 3
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ import "buf/validate/validate.proto";

message IgnoreEmptyProto3Scalar {
int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}

message IgnoreEmptyProto3OptionalScalar {
optional int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}

message IgnoreEmptyProto3Message {
optional Msg val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).cel = {
id: "ignore_empty.proto3.message"
message: "foobar"
Expand All @@ -49,41 +49,41 @@ message IgnoreEmptyProto3Message {
message IgnoreEmptyProto3Oneof {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}
}

message IgnoreEmptyProto3Repeated {
repeated int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).repeated.min_items = 3
];
}

message IgnoreEmptyProto3Map {
map<int32, int32> val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).map.min_pairs = 3
];
}

message IgnoreEmptyRepeatedItems {
repeated int32 val = 1 [(buf.validate.field).repeated.items = {
ignore_empty: true
ignore: IGNORE_IF_UNPOPULATED
int32: {gt: 0}
}];
}

message IgnoreEmptyMapPairs {
map<string, int32> val = 1 [
(buf.validate.field).map.keys = {
ignore_empty: true
ignore: IGNORE_IF_UNPOPULATED
string: {min_len: 3}
},
(buf.validate.field).map.values = {
ignore_empty: true
ignore: IGNORE_IF_UNPOPULATED
int32: {gt: 0}
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import "buf/validate/validate.proto";

message IgnoreEmptyEditionsScalarExplicitPresence {
int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}

message IgnoreEmptyEditionsScalarExplicitPresenceWithDefault {
int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0,
default = 42
];
Expand All @@ -36,31 +36,31 @@ message IgnoreEmptyEditionsScalarExplicitPresenceWithDefault {
message IgnoreEmptyEditionsScalarImplicitPresence {
int32 val = 1 [
features.field_presence = IMPLICIT,
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}

message IgnoreEmptyEditionsScalarLegacyRequired {
int32 val = 1 [
features.field_presence = LEGACY_REQUIRED,
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}

message IgnoreEmptyEditionsScalarLegacyRequiredWithDefault {
int32 val = 1 [
features.field_presence = LEGACY_REQUIRED,
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0,
default = 42
];
}

message IgnoreEmptyEditionsMessageExplicitPresence {
Msg val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).cel = {
id: "ignore_empty.editions.message"
message: "foobar"
Expand All @@ -75,7 +75,7 @@ message IgnoreEmptyEditionsMessageExplicitPresence {
message IgnoreEmptyEditionsMessageExplicitPresenceDelimited {
Msg val = 1 [
features.message_encoding = DELIMITED,
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).cel = {
id: "ignore_empty.editions.message"
message: "foobar"
Expand All @@ -90,7 +90,7 @@ message IgnoreEmptyEditionsMessageExplicitPresenceDelimited {
message IgnoreEmptyEditionsMessageLegacyRequired {
Msg val = 1 [
features.field_presence = LEGACY_REQUIRED,
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).cel = {
id: "ignore_empty.editions.message"
message: "foobar"
Expand All @@ -106,7 +106,7 @@ message IgnoreEmptyEditionsMessageLegacyRequiredDelimited {
Msg val = 1 [
features.message_encoding = DELIMITED,
features.field_presence = LEGACY_REQUIRED,
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).cel = {
id: "ignore_empty.editions.message"
message: "foobar"
Expand All @@ -121,30 +121,30 @@ message IgnoreEmptyEditionsMessageLegacyRequiredDelimited {
message IgnoreEmptyEditionsOneof {
oneof o {
int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).int32.gt = 0
];
}
}

message IgnoreEmptyEditionsRepeated {
repeated int32 val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).repeated.min_items = 3
];
}

message IgnoreEmptyEditionsRepeatedExpanded {
repeated int32 val = 1 [
features.repeated_field_encoding = EXPANDED,
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).repeated.min_items = 3
];
}

message IgnoreEmptyEditionsMap {
map<int32, int32> val = 1 [
(buf.validate.field).ignore_empty = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
(buf.validate.field).map.min_pairs = 3
];
}
Loading

0 comments on commit 79e5a7d

Please sign in to comment.