Skip to content

Commit 68baacf

Browse files
Use getField CEL function (#352)
This is a proposal to remove our hack around the fact the `in` identifier is reserved in CEL. This is especially urgent for protovalidate-cc which is currently carrying patches to the CEL implementation in order to enable it, since cel-cpp doesn't allow this sort of functionality to be added in at runtime. Runtime PRs: - Go: bufbuild/protovalidate-go#225 - C++: bufbuild/protovalidate-cc#90 - Python: bufbuild/protovalidate-python#290 - Java: bufbuild/protovalidate-java#271
1 parent 774da77 commit 68baacf

File tree

2 files changed

+188
-188
lines changed

2 files changed

+188
-188
lines changed

proto/protovalidate/buf/validate/validate.proto

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ message FloatRules {
437437
// ```
438438
optional float const = 1 [(predefined).cel = {
439439
id: "float.const"
440-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
440+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
441441
}];
442442

443443
oneof less_than {
@@ -592,7 +592,7 @@ message FloatRules {
592592
// ```
593593
repeated float in = 6 [(predefined).cel = {
594594
id: "float.in"
595-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
595+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
596596
}];
597597

598598
// `in` requires the field value to not be equal to any of the specified
@@ -661,7 +661,7 @@ message DoubleRules {
661661
// ```
662662
optional double const = 1 [(predefined).cel = {
663663
id: "double.const"
664-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
664+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
665665
}];
666666
oneof less_than {
667667
// `lt` requires the field value to be less than the specified value (field <
@@ -813,7 +813,7 @@ message DoubleRules {
813813
// ```
814814
repeated double in = 6 [(predefined).cel = {
815815
id: "double.in"
816-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
816+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
817817
}];
818818

819819
// `not_in` requires the field value to not be equal to any of the specified
@@ -882,7 +882,7 @@ message Int32Rules {
882882
// ```
883883
optional int32 const = 1 [(predefined).cel = {
884884
id: "int32.const"
885-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
885+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
886886
}];
887887
oneof less_than {
888888
// `lt` requires the field value to be less than the specified value (field
@@ -1035,7 +1035,7 @@ message Int32Rules {
10351035
// ```
10361036
repeated int32 in = 6 [(predefined).cel = {
10371037
id: "int32.in"
1038-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
1038+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
10391039
}];
10401040

10411041
// `not_in` requires the field value to not be equal to any of the specified
@@ -1097,7 +1097,7 @@ message Int64Rules {
10971097
// ```
10981098
optional int64 const = 1 [(predefined).cel = {
10991099
id: "int64.const"
1100-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
1100+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
11011101
}];
11021102
oneof less_than {
11031103
// `lt` requires the field value to be less than the specified value (field <
@@ -1250,7 +1250,7 @@ message Int64Rules {
12501250
// ```
12511251
repeated int64 in = 6 [(predefined).cel = {
12521252
id: "int64.in"
1253-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
1253+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
12541254
}];
12551255

12561256
// `not_in` requires the field value to not be equal to any of the specified
@@ -1312,7 +1312,7 @@ message UInt32Rules {
13121312
// ```
13131313
optional uint32 const = 1 [(predefined).cel = {
13141314
id: "uint32.const"
1315-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
1315+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
13161316
}];
13171317
oneof less_than {
13181318
// `lt` requires the field value to be less than the specified value (field <
@@ -1465,7 +1465,7 @@ message UInt32Rules {
14651465
// ```
14661466
repeated uint32 in = 6 [(predefined).cel = {
14671467
id: "uint32.in"
1468-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
1468+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
14691469
}];
14701470

14711471
// `not_in` requires the field value to not be equal to any of the specified
@@ -1527,7 +1527,7 @@ message UInt64Rules {
15271527
// ```
15281528
optional uint64 const = 1 [(predefined).cel = {
15291529
id: "uint64.const"
1530-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
1530+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
15311531
}];
15321532
oneof less_than {
15331533
// `lt` requires the field value to be less than the specified value (field <
@@ -1679,7 +1679,7 @@ message UInt64Rules {
16791679
// ```
16801680
repeated uint64 in = 6 [(predefined).cel = {
16811681
id: "uint64.in"
1682-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
1682+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
16831683
}];
16841684

16851685
// `not_in` requires the field value to not be equal to any of the specified
@@ -1740,7 +1740,7 @@ message SInt32Rules {
17401740
// ```
17411741
optional sint32 const = 1 [(predefined).cel = {
17421742
id: "sint32.const"
1743-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
1743+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
17441744
}];
17451745
oneof less_than {
17461746
// `lt` requires the field value to be less than the specified value (field
@@ -1893,7 +1893,7 @@ message SInt32Rules {
18931893
// ```
18941894
repeated sint32 in = 6 [(predefined).cel = {
18951895
id: "sint32.in"
1896-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
1896+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
18971897
}];
18981898

18991899
// `not_in` requires the field value to not be equal to any of the specified
@@ -1954,7 +1954,7 @@ message SInt64Rules {
19541954
// ```
19551955
optional sint64 const = 1 [(predefined).cel = {
19561956
id: "sint64.const"
1957-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
1957+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
19581958
}];
19591959
oneof less_than {
19601960
// `lt` requires the field value to be less than the specified value (field
@@ -2107,7 +2107,7 @@ message SInt64Rules {
21072107
// ```
21082108
repeated sint64 in = 6 [(predefined).cel = {
21092109
id: "sint64.in"
2110-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
2110+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
21112111
}];
21122112

21132113
// `not_in` requires the field value to not be equal to any of the specified
@@ -2168,7 +2168,7 @@ message Fixed32Rules {
21682168
// ```
21692169
optional fixed32 const = 1 [(predefined).cel = {
21702170
id: "fixed32.const"
2171-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
2171+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
21722172
}];
21732173
oneof less_than {
21742174
// `lt` requires the field value to be less than the specified value (field <
@@ -2321,7 +2321,7 @@ message Fixed32Rules {
23212321
// ```
23222322
repeated fixed32 in = 6 [(predefined).cel = {
23232323
id: "fixed32.in"
2324-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
2324+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
23252325
}];
23262326

23272327
// `not_in` requires the field value to not be equal to any of the specified
@@ -2382,7 +2382,7 @@ message Fixed64Rules {
23822382
// ```
23832383
optional fixed64 const = 1 [(predefined).cel = {
23842384
id: "fixed64.const"
2385-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
2385+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
23862386
}];
23872387
oneof less_than {
23882388
// `lt` requires the field value to be less than the specified value (field <
@@ -2535,7 +2535,7 @@ message Fixed64Rules {
25352535
// ```
25362536
repeated fixed64 in = 6 [(predefined).cel = {
25372537
id: "fixed64.in"
2538-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
2538+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
25392539
}];
25402540

25412541
// `not_in` requires the field value to not be equal to any of the specified
@@ -2596,7 +2596,7 @@ message SFixed32Rules {
25962596
// ```
25972597
optional sfixed32 const = 1 [(predefined).cel = {
25982598
id: "sfixed32.const"
2599-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
2599+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
26002600
}];
26012601
oneof less_than {
26022602
// `lt` requires the field value to be less than the specified value (field <
@@ -2749,7 +2749,7 @@ message SFixed32Rules {
27492749
// ```
27502750
repeated sfixed32 in = 6 [(predefined).cel = {
27512751
id: "sfixed32.in"
2752-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
2752+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
27532753
}];
27542754

27552755
// `not_in` requires the field value to not be equal to any of the specified
@@ -2810,7 +2810,7 @@ message SFixed64Rules {
28102810
// ```
28112811
optional sfixed64 const = 1 [(predefined).cel = {
28122812
id: "sfixed64.const"
2813-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
2813+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
28142814
}];
28152815
oneof less_than {
28162816
// `lt` requires the field value to be less than the specified value (field <
@@ -2963,7 +2963,7 @@ message SFixed64Rules {
29632963
// ```
29642964
repeated sfixed64 in = 6 [(predefined).cel = {
29652965
id: "sfixed64.in"
2966-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
2966+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
29672967
}];
29682968

29692969
// `not_in` requires the field value to not be equal to any of the specified
@@ -3025,7 +3025,7 @@ message BoolRules {
30253025
// ```
30263026
optional bool const = 1 [(predefined).cel = {
30273027
id: "bool.const"
3028-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
3028+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
30293029
}];
30303030

30313031
// `example` specifies values that the field may have. These values SHOULD
@@ -3072,7 +3072,7 @@ message StringRules {
30723072
// ```
30733073
optional string const = 1 [(predefined).cel = {
30743074
id: "string.const"
3075-
expression: "this != rules.const ? 'value must equal `%s`'.format([rules.const]) : ''"
3075+
expression: "this != getField(rules, 'const') ? 'value must equal `%s`'.format([getField(rules, 'const')]) : ''"
30763076
}];
30773077

30783078
// `len` dictates that the field value must have the specified
@@ -3258,7 +3258,7 @@ message StringRules {
32583258
// ```
32593259
repeated string in = 10 [(predefined).cel = {
32603260
id: "string.in"
3261-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
3261+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
32623262
}];
32633263

32643264
// `not_in` specifies that the field value cannot be equal to any
@@ -3833,7 +3833,7 @@ message BytesRules {
38333833
// ```
38343834
optional bytes const = 1 [(predefined).cel = {
38353835
id: "bytes.const"
3836-
expression: "this != rules.const ? 'value must be %x'.format([rules.const]) : ''"
3836+
expression: "this != getField(rules, 'const') ? 'value must be %x'.format([getField(rules, 'const')]) : ''"
38373837
}];
38383838

38393839
// `len` requires the field value to have the specified length in bytes.
@@ -3954,7 +3954,7 @@ message BytesRules {
39543954
// ```
39553955
repeated bytes in = 8 [(predefined).cel = {
39563956
id: "bytes.in"
3957-
expression: "dyn(rules)['in'].size() > 0 && !(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
3957+
expression: "getField(rules, 'in').size() > 0 && !(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
39583958
}];
39593959

39603960
// `not_in` requires the field value to be not equal to any of the specified
@@ -4091,7 +4091,7 @@ message EnumRules {
40914091
// ```
40924092
optional int32 const = 1 [(predefined).cel = {
40934093
id: "enum.const"
4094-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
4094+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
40954095
}];
40964096

40974097
// `defined_only` requires the field value to be one of the defined values for
@@ -4129,7 +4129,7 @@ message EnumRules {
41294129
// ```
41304130
repeated int32 in = 3 [(predefined).cel = {
41314131
id: "enum.in"
4132-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
4132+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
41334133
}];
41344134

41354135
// `not_in` requires the field value to be not equal to any of the
@@ -4381,7 +4381,7 @@ message DurationRules {
43814381
// ```
43824382
optional google.protobuf.Duration const = 2 [(predefined).cel = {
43834383
id: "duration.const"
4384-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
4384+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
43854385
}];
43864386
oneof less_than {
43874387
// `lt` stipulates that the field must be less than the specified value of the `google.protobuf.Duration` type,
@@ -4534,7 +4534,7 @@ message DurationRules {
45344534
// ```
45354535
repeated google.protobuf.Duration in = 7 [(predefined).cel = {
45364536
id: "duration.in"
4537-
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''"
4537+
expression: "!(this in getField(rules, 'in')) ? 'value must be in list %s'.format([getField(rules, 'in')]) : ''"
45384538
}];
45394539

45404540
// `not_in` denotes that the field must not be equal to
@@ -4595,7 +4595,7 @@ message TimestampRules {
45954595
// ```
45964596
optional google.protobuf.Timestamp const = 2 [(predefined).cel = {
45974597
id: "timestamp.const"
4598-
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''"
4598+
expression: "this != getField(rules, 'const') ? 'value must equal %s'.format([getField(rules, 'const')]) : ''"
45994599
}];
46004600
oneof less_than {
46014601
// requires the duration field value to be less than the specified value (field < value). If the field value doesn't meet the required conditions, an error message is generated.

0 commit comments

Comments
 (0)