Skip to content

Commit dd75313

Browse files
authored
Rename IGNORE_IF_UNPOPULATED to IGNORE_IF_ZERO_VALUE (#397)
`IGNORE_IF_UNPOPULATED` is a no-op for fields that track presence. It behaves the same as the default for them, and is only useful for fields that don't track presence. It reads "unpopulated" for fields that don't have a logical unpopulated state, yet it is only relevant for them. This is confusing. To address this we are renaming the field to `IGNORE_IF_ZERO_VALUE` along with a note to indicate it is a no-op for fields that track presence. While this is a breaking change, there is no change in the behavior. Migrating is as simple as updating all occurrences of `IGNORE_IF_UNPOPULATED` to `IGNORE_IF_ZERO_VALUE` and everything will continue to work as it was working before. Signed-off-by: Sri Krishna <skrishna@buf.build>
1 parent e3a20a6 commit dd75313

16 files changed

Lines changed: 128 additions & 193 deletions

File tree

proto/protovalidate-testing/buf/validate/conformance/cases/bytes.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ message BytesNotIPv6 {
9494
message BytesIPv6Ignore {
9595
bytes val = 1 [
9696
(buf.validate.field).bytes.ipv6 = true,
97-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
97+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE
9898
];
9999
}
100100
message BytesExample {

proto/protovalidate-testing/buf/validate/conformance/cases/ignore_empty_proto2.proto

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,29 @@ import "buf/validate/validate.proto";
2020

2121
message IgnoreEmptyProto2ScalarOptional {
2222
optional int32 val = 1 [
23-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
23+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
2424
(buf.validate.field).int32.gt = 0
2525
];
2626
}
2727

2828
message IgnoreEmptyProto2ScalarOptionalWithDefault {
2929
optional int32 val = 1 [
30-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
30+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
3131
(buf.validate.field).int32.gt = 0,
3232
default = 42
3333
];
3434
}
3535

3636
message IgnoreEmptyProto2ScalarRequired {
3737
required int32 val = 1 [
38-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
38+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
3939
(buf.validate.field).int32.gt = 0
4040
];
4141
}
4242

4343
message IgnoreEmptyProto2Message {
4444
optional Msg val = 1 [
45-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
45+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
4646
(buf.validate.field).cel = {
4747
id: "ignore_empty.proto2.message"
4848
message: "foobar"
@@ -57,22 +57,22 @@ message IgnoreEmptyProto2Message {
5757
message IgnoreEmptyProto2Oneof {
5858
oneof o {
5959
int32 val = 1 [
60-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
60+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
6161
(buf.validate.field).int32.gt = 0
6262
];
6363
}
6464
}
6565

6666
message IgnoreEmptyProto2Repeated {
6767
repeated int32 val = 1 [
68-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
68+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
6969
(buf.validate.field).repeated.min_items = 3
7070
];
7171
}
7272

7373
message IgnoreEmptyProto2Map {
7474
map<int32, int32> val = 1 [
75-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
75+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
7676
(buf.validate.field).map.min_pairs = 3
7777
];
7878
}

proto/protovalidate-testing/buf/validate/conformance/cases/ignore_empty_proto3.proto

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ import "buf/validate/validate.proto";
2020

2121
message IgnoreEmptyProto3Scalar {
2222
int32 val = 1 [
23-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
23+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
2424
(buf.validate.field).int32.gt = 0
2525
];
2626
}
2727

2828
message IgnoreEmptyProto3OptionalScalar {
2929
optional int32 val = 1 [
30-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
30+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
3131
(buf.validate.field).int32.gt = 0
3232
];
3333
}
3434

3535
message IgnoreEmptyProto3Message {
3636
optional Msg val = 1 [
37-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
37+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
3838
(buf.validate.field).cel = {
3939
id: "ignore_empty.proto3.message"
4040
message: "foobar"
@@ -49,41 +49,41 @@ message IgnoreEmptyProto3Message {
4949
message IgnoreEmptyProto3Oneof {
5050
oneof o {
5151
int32 val = 1 [
52-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
52+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
5353
(buf.validate.field).int32.gt = 0
5454
];
5555
}
5656
}
5757

5858
message IgnoreEmptyProto3Repeated {
5959
repeated int32 val = 1 [
60-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
60+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
6161
(buf.validate.field).repeated.min_items = 3
6262
];
6363
}
6464

6565
message IgnoreEmptyProto3Map {
6666
map<int32, int32> val = 1 [
67-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
67+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
6868
(buf.validate.field).map.min_pairs = 3
6969
];
7070
}
7171

7272
message IgnoreEmptyRepeatedItems {
7373
repeated int32 val = 1 [(buf.validate.field).repeated.items = {
74-
ignore: IGNORE_IF_UNPOPULATED
74+
ignore: IGNORE_IF_ZERO_VALUE
7575
int32: {gt: 0}
7676
}];
7777
}
7878

7979
message IgnoreEmptyMapPairs {
8080
map<string, int32> val = 1 [
8181
(buf.validate.field).map.keys = {
82-
ignore: IGNORE_IF_UNPOPULATED
82+
ignore: IGNORE_IF_ZERO_VALUE
8383
string: {min_len: 3}
8484
},
8585
(buf.validate.field).map.values = {
86-
ignore: IGNORE_IF_UNPOPULATED
86+
ignore: IGNORE_IF_ZERO_VALUE
8787
int32: {gt: 0}
8888
}
8989
];

proto/protovalidate-testing/buf/validate/conformance/cases/ignore_empty_proto_editions.proto

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import "buf/validate/validate.proto";
2020

2121
message IgnoreEmptyEditionsScalarExplicitPresence {
2222
int32 val = 1 [
23-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
23+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
2424
(buf.validate.field).int32.gt = 0
2525
];
2626
}
2727

2828
message IgnoreEmptyEditionsScalarExplicitPresenceWithDefault {
2929
int32 val = 1 [
30-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
30+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
3131
(buf.validate.field).int32.gt = 0,
3232
default = 42
3333
];
@@ -36,31 +36,31 @@ message IgnoreEmptyEditionsScalarExplicitPresenceWithDefault {
3636
message IgnoreEmptyEditionsScalarImplicitPresence {
3737
int32 val = 1 [
3838
features.field_presence = IMPLICIT,
39-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
39+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
4040
(buf.validate.field).int32.gt = 0
4141
];
4242
}
4343

4444
message IgnoreEmptyEditionsScalarLegacyRequired {
4545
int32 val = 1 [
4646
features.field_presence = LEGACY_REQUIRED,
47-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
47+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
4848
(buf.validate.field).int32.gt = 0
4949
];
5050
}
5151

5252
message IgnoreEmptyEditionsScalarLegacyRequiredWithDefault {
5353
int32 val = 1 [
5454
features.field_presence = LEGACY_REQUIRED,
55-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
55+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
5656
(buf.validate.field).int32.gt = 0,
5757
default = 42
5858
];
5959
}
6060

6161
message IgnoreEmptyEditionsMessageExplicitPresence {
6262
Msg val = 1 [
63-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
63+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
6464
(buf.validate.field).cel = {
6565
id: "ignore_empty.editions.message"
6666
message: "foobar"
@@ -75,7 +75,7 @@ message IgnoreEmptyEditionsMessageExplicitPresence {
7575
message IgnoreEmptyEditionsMessageExplicitPresenceDelimited {
7676
Msg val = 1 [
7777
features.message_encoding = DELIMITED,
78-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
78+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
7979
(buf.validate.field).cel = {
8080
id: "ignore_empty.editions.message"
8181
message: "foobar"
@@ -90,7 +90,7 @@ message IgnoreEmptyEditionsMessageExplicitPresenceDelimited {
9090
message IgnoreEmptyEditionsMessageLegacyRequired {
9191
Msg val = 1 [
9292
features.field_presence = LEGACY_REQUIRED,
93-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
93+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
9494
(buf.validate.field).cel = {
9595
id: "ignore_empty.editions.message"
9696
message: "foobar"
@@ -106,7 +106,7 @@ message IgnoreEmptyEditionsMessageLegacyRequiredDelimited {
106106
Msg val = 1 [
107107
features.message_encoding = DELIMITED,
108108
features.field_presence = LEGACY_REQUIRED,
109-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
109+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
110110
(buf.validate.field).cel = {
111111
id: "ignore_empty.editions.message"
112112
message: "foobar"
@@ -121,30 +121,30 @@ message IgnoreEmptyEditionsMessageLegacyRequiredDelimited {
121121
message IgnoreEmptyEditionsOneof {
122122
oneof o {
123123
int32 val = 1 [
124-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
124+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
125125
(buf.validate.field).int32.gt = 0
126126
];
127127
}
128128
}
129129

130130
message IgnoreEmptyEditionsRepeated {
131131
repeated int32 val = 1 [
132-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
132+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
133133
(buf.validate.field).repeated.min_items = 3
134134
];
135135
}
136136

137137
message IgnoreEmptyEditionsRepeatedExpanded {
138138
repeated int32 val = 1 [
139139
features.repeated_field_encoding = EXPANDED,
140-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
140+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
141141
(buf.validate.field).repeated.min_items = 3
142142
];
143143
}
144144

145145
message IgnoreEmptyEditionsMap {
146146
map<int32, int32> val = 1 [
147-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
147+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
148148
(buf.validate.field).map.min_pairs = 3
149149
];
150150
}

proto/protovalidate-testing/buf/validate/conformance/cases/ignore_proto2.proto

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ message Proto2ScalarOptionalIgnoreUnspecifiedWithDefault {
3131

3232
message Proto2ScalarOptionalIgnoreEmpty {
3333
optional int32 val = 1 [
34-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
34+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
3535
(buf.validate.field).int32.gt = 0
3636
];
3737
}
3838

3939
message Proto2ScalarOptionalIgnoreEmptyWithDefault {
4040
optional int32 val = 1 [
41-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
41+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
4242
(buf.validate.field).int32.gt = 0,
4343
default = -42
4444
];
@@ -72,14 +72,14 @@ message Proto2ScalarRequiredIgnoreUnspecifiedWithDefault {
7272

7373
message Proto2ScalarRequiredIgnoreEmpty {
7474
required int32 val = 1 [
75-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
75+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
7676
(buf.validate.field).int32.gt = 0
7777
];
7878
}
7979

8080
message Proto2ScalarRequiredIgnoreEmptyWithDefault {
8181
required int32 val = 1 [
82-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
82+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
8383
(buf.validate.field).int32.gt = 0,
8484
default = -42
8585
];
@@ -113,7 +113,7 @@ message Proto2MessageOptionalIgnoreUnspecified {
113113

114114
message Proto2MessageOptionalIgnoreEmpty {
115115
optional Msg val = 1 [
116-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
116+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
117117
(buf.validate.field).cel = {
118118
id: "proto2.message.ignore.empty"
119119
message: "foobar"
@@ -152,7 +152,7 @@ message Proto2MessageRequiredIgnoreUnspecified {
152152

153153
message Proto2MessageRequiredIgnoreEmpty {
154154
required Msg val = 1 [
155-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
155+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
156156
(buf.validate.field).cel = {
157157
id: "proto2.message.ignore.empty"
158158
message: "foobar"
@@ -196,7 +196,7 @@ message Proto2OneofIgnoreUnspecifiedWithDefault {
196196
message Proto2OneofIgnoreEmpty {
197197
oneof o {
198198
int32 val = 1 [
199-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
199+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
200200
(buf.validate.field).int32.gt = 0
201201
];
202202
}
@@ -205,7 +205,7 @@ message Proto2OneofIgnoreEmpty {
205205
message Proto2OneofIgnoreEmptyWithDefault {
206206
oneof o {
207207
int32 val = 1 [
208-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
208+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
209209
(buf.validate.field).int32.gt = 0,
210210
default = -42
211211
];
@@ -237,7 +237,7 @@ message Proto2RepeatedIgnoreUnspecified {
237237

238238
message Proto2RepeatedIgnoreEmpty {
239239
repeated int32 val = 1 [
240-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
240+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
241241
(buf.validate.field).repeated.min_items = 3
242242
];
243243
}
@@ -255,7 +255,7 @@ message Proto2MapIgnoreUnspecified {
255255

256256
message Proto2MapIgnoreEmpty {
257257
map<int32, int32> val = 1 [
258-
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED,
258+
(buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
259259
(buf.validate.field).map.min_pairs = 3
260260
];
261261
}
@@ -273,7 +273,7 @@ message Proto2RepeatedItemIgnoreUnspecified {
273273

274274
message Proto2RepeatedItemIgnoreEmpty {
275275
repeated int32 val = 1 [
276-
(buf.validate.field).repeated.items.ignore = IGNORE_IF_UNPOPULATED,
276+
(buf.validate.field).repeated.items.ignore = IGNORE_IF_ZERO_VALUE,
277277
(buf.validate.field).repeated.items.int32.gt = 0
278278
];
279279
}
@@ -291,7 +291,7 @@ message Proto2MapKeyIgnoreUnspecified {
291291

292292
message Proto2MapKeyIgnoreEmpty {
293293
map<int32, int32> val = 1 [
294-
(buf.validate.field).map.keys.ignore = IGNORE_IF_UNPOPULATED,
294+
(buf.validate.field).map.keys.ignore = IGNORE_IF_ZERO_VALUE,
295295
(buf.validate.field).map.keys.int32.gt = 0
296296
];
297297
}
@@ -309,7 +309,7 @@ message Proto2MapValueIgnoreUnspecified {
309309

310310
message Proto2MapValueIgnoreEmpty {
311311
map<int32, int32> val = 1 [
312-
(buf.validate.field).map.values.ignore = IGNORE_IF_UNPOPULATED,
312+
(buf.validate.field).map.values.ignore = IGNORE_IF_ZERO_VALUE,
313313
(buf.validate.field).map.values.int32.gt = 0
314314
];
315315
}

0 commit comments

Comments
 (0)