/
validate.proto
4130 lines (3973 loc) · 163 KB
/
validate.proto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2023 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";
package buf.validate;
import "buf/validate/expression.proto";
import "buf/validate/priv/private.proto";
import "google/protobuf/descriptor.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
option go_package = "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate";
option java_multiple_files = true;
option java_outer_classname = "ValidateProto";
option java_package = "build.buf.validate";
// MessageOptions is an extension to google.protobuf.MessageOptions. It allows
// the addition of validation rules at the message level. These rules can be
// applied to incoming messages to ensure they meet certain criteria before
// being processed.
extend google.protobuf.MessageOptions {
// Rules specify the validations to be performed on this message. By default,
// no validation is performed against a message.
optional MessageConstraints message = 1159;
}
// OneofOptions is an extension to google.protobuf.OneofOptions. It allows
// the addition of validation rules on a oneof. These rules can be
// applied to incoming messages to ensure they meet certain criteria before
// being processed.
extend google.protobuf.OneofOptions {
// Rules specify the validations to be performed on this oneof. By default,
// no validation is performed against a oneof.
optional OneofConstraints oneof = 1159;
}
// FieldOptions is an extension to google.protobuf.FieldOptions. It allows
// the addition of validation rules at the field level. These rules can be
// applied to incoming messages to ensure they meet certain criteria before
// being processed.
extend google.protobuf.FieldOptions {
// Rules specify the validations to be performed on this field. By default,
// no validation is performed against a field.
optional FieldConstraints field = 1159;
}
// MessageConstraints represents validation rules that are applied to the entire message.
// It includes disabling options and a list of Constraint messages representing Common Expression Language (CEL) validation rules.
message MessageConstraints {
// `disabled` is a boolean flag that, when set to true, nullifies any validation rules for this message.
// This includes any fields within the message that would otherwise support validation.
//
// ```proto
// message MyMessage {
// // validation will be bypassed for this message
// option (buf.validate.message).disabled = true;
// }
// ```
optional bool disabled = 1;
// `cel` is a repeated field of type Constraint. Each Constraint specifies a validation rule to be applied to this message.
// These constraints are written in Common Expression Language (CEL) syntax. For more information on
// CEL, [see our documentation](https://github.com/bufbuild/protovalidate/blob/main/docs/cel.md).
//
//
// ```proto
// message MyMessage {
// // The field `foo` must be greater than 42.
// option (buf.validate.message).cel = {
// id: "my_message.value",
// message: "value must be greater than 42",
// expression: "this.foo > 42",
// };
// optional int32 foo = 1;
// }
// ```
repeated Constraint cel = 3;
}
// The `OneofConstraints` message type enables you to manage constraints for
// oneof fields in your protobuf messages.
message OneofConstraints {
// If `required` is true, exactly one field of the oneof must be present. A
// validation error is returned if no fields in the oneof are present. The
// field itself may still be a default value; further constraints
// should be placed on the fields themselves to ensure they are valid values,
// such as `min_len` or `gt`.
//
// ```proto
// message MyMessage {
// oneof value {
// // Either `a` or `b` must be set. If `a` is set, it must also be
// // non-empty; whereas if `b` is set, it can still be an empty string.
// option (buf.validate.oneof).required = true;
// string a = 1 [(buf.validate.field).string.min_len = 1];
// string b = 2;
// }
// }
// ```
optional bool required = 1;
}
// FieldConstraints encapsulates the rules for each type of field. Depending on
// the field, the correct set should be used to ensure proper validations.
message FieldConstraints {
// `cel` is a repeated field used to represent a textual expression
// in the Common Expression Language (CEL) syntax. For more information on
// CEL, [see our documentation](https://github.com/bufbuild/protovalidate/blob/main/docs/cel.md).
//
// ```proto
// message MyMessage {
// // The field `value` must be greater than 42.
// optional int32 value = 1 [(buf.validate.field).cel = {
// id: "my_message.value",
// message: "value must be greater than 42",
// expression: "this > 42",
// }];
// }
// ```
repeated Constraint cel = 23;
// If `required` is true, the field must be populated. A populated field can be
// described as "serialized in the wire format," which includes:
//
// - the following "nullable" fields must be explicitly set to be considered populated:
// - 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 (both optional and required)
// - proto3 scalar fields must be non-zero to be considered populated
// - repeated and map fields must be non-empty to be considered populated
//
// ```proto
// message MyMessage {
// // The field `value` must be set to a non-null value.
// optional MyOtherMessage value = 1 [(buf.validate.field).required = true];
// }
// ```
bool required = 25;
// Skip validation on the field if its value matches the specified criteria.
// See Ignore enum for details.
//
// ```proto
// 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_IF_DEFAULT_VALUE,
// (buf.validate.field).string.uri = true,
// ];
// }
// ```
Ignore ignore = 27;
oneof type {
// Scalar Field Types
FloatRules float = 1;
DoubleRules double = 2;
Int32Rules int32 = 3;
Int64Rules int64 = 4;
UInt32Rules uint32 = 5;
UInt64Rules uint64 = 6;
SInt32Rules sint32 = 7;
SInt64Rules sint64 = 8;
Fixed32Rules fixed32 = 9;
Fixed64Rules fixed64 = 10;
SFixed32Rules sfixed32 = 11;
SFixed64Rules sfixed64 = 12;
BoolRules bool = 13;
StringRules string = 14;
BytesRules bytes = 15;
// Complex Field Types
EnumRules enum = 16;
RepeatedRules repeated = 18;
MapRules map = 19;
// Well-Known Field Types
AnyRules any = 20;
DurationRules duration = 21;
TimestampRules timestamp = 22;
}
// DEPRECATED: use ignore=IGNORE_ALWAYS instead. TODO: remove this field pre-v1.
bool skipped = 24 [deprecated = true];
// DEPRECATED: use ignore=IGNORE_IF_UNPOPULATED instead. TODO: remove this field pre-v1.
bool ignore_empty = 26 [deprecated = true];
}
// Specifies how FieldConstraints.ignore behaves. See the documentation for
// FieldConstraints.required for definitions of "populated" and "nullable".
enum Ignore {
// buf:lint:ignore ENUM_NO_ALLOW_ALIAS // allowance for deprecations. TODO: remove pre-v1.
option allow_alias = true;
// Validation is only skipped if it's an unpopulated nullable fields.
//
// ```proto
// syntax="proto3";
//
// message Request {
// // The uri rule applies to any value, including the empty string.
// string foo = 1 [
// (buf.validate.field).string.uri = true
// ];
//
// // The uri rule only applies if the field is set, including if it's
// // set to the empty string.
// optional string bar = 2 [
// (buf.validate.field).string.uri = true
// ];
//
// // The min_items rule always applies, even if the list is empty.
// repeated string baz = 3 [
// (buf.validate.field).repeated.min_items = 3
// ];
//
// // The custom CEL rule applies only if the field is set, including if
// // it's the "zero" value of that message.
// SomeMessage quux = 4 [
// (buf.validate.field).cel = {/* ... */}
// ];
// }
// ```
IGNORE_UNSPECIFIED = 0;
// Validation is skipped if the field is unpopulated. This rule is redundant
// if the field is already nullable. This value is equivalent behavior to the
// deprecated ignore_empty rule.
//
// ```proto
// syntax="proto3
//
// message Request {
// // The uri rule applies only if the value is not the empty string.
// string foo = 1 [
// (buf.validate.field).string.uri = true,
// (buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
// ];
//
// // IGNORE_IF_UNPOPULATED is equivalent to IGNORE_UNSPECIFIED in this
// // case: the uri rule only applies if the field is set, including if
// // it's set to the empty string.
// optional string bar = 2 [
// (buf.validate.field).string.uri = true,
// (buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
// ];
//
// // The min_items rule only applies if the list has at least one item.
// repeated string baz = 3 [
// (buf.validate.field).repeated.min_items = 3,
// (buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
// ];
//
// // IGNORE_IF_UNPOPULATED is equivalent to IGNORE_UNSPECIFIED in this
// // case: the custom CEL rule applies only if the field is set, including
// // if it's the "zero" value of that message.
// SomeMessage quux = 4 [
// (buf.validate.field).cel = {/* ... */},
// (buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
// ];
// }
// ```
IGNORE_IF_UNPOPULATED = 1;
// Validation is skipped if the field is unpopulated or if it is a nullable
// field populated with its default value. This is typically the zero or
// empty value, but proto2 scalars support custom defaults. For messages, the
// default is a non-null message with all its fields unpopulated.
//
// ```proto
// syntax="proto3
//
// message Request {
// // IGNORE_IF_DEFAULT_VALUE is equivalent to IGNORE_IF_UNPOPULATED in
// // this case; the uri rule applies only if the value is not the empty
// // string.
// string foo = 1 [
// (buf.validate.field).string.uri = true,
// (buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE
// ];
//
// // The uri rule only applies if the field is set to a value other than
// // the empty string.
// optional string bar = 2 [
// (buf.validate.field).string.uri = true,
// (buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE
// ];
//
// // IGNORE_IF_DEFAULT_VALUE is equivalent to IGNORE_IF_UNPOPULATED in
// // this case; the min_items rule only applies if the list has at least
// // one item.
// repeated string baz = 3 [
// (buf.validate.field).repeated.min_items = 3,
// (buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE
// ];
//
// // The custom CEL rule only applies if the field is set to a value other
// // than an empty message (i.e., fields are unpopulated).
// SomeMessage quux = 4 [
// (buf.validate.field).cel = {/* ... */},
// (buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE
// ];
// }
// ```
//
// This rule is affected by proto2 custom default values:
//
// ```proto
// syntax="proto2";
//
// message Request {
// // The gt rule only applies if the field is set and it's value is not
// the default (i.e., not -42). The rule even applies if the field is set
// to zero since the default value differs.
// optional int32 value = 1 [
// default = -42,
// (buf.validate.field).int32.gt = 0,
// (buf.validate.field).ignore = IGNORE_IF_DEFAULT_VALUE
// ];
// }
IGNORE_IF_DEFAULT_VALUE = 2;
// The validation rules of this field will be skipped and not evaluated. This
// is useful for situations that necessitate turning off the rules of a field
// containing a message that may not make sense in the current context, or to
// temporarily disable constraints during development.
//
// ```proto
// message MyMessage {
// // The field's rules will always be ignored, including any validation's
// // on value's fields.
// MyOtherMessage value = 1 [
// (buf.validate.field).ignore = IGNORE_ALWAYS];
// }
// ```
IGNORE_ALWAYS = 3;
// Deprecated: Use IGNORE_IF_UNPOPULATED instead. TODO: Remove this value pre-v1.
IGNORE_EMPTY = 1 [deprecated = true];
// Deprecated: Use IGNORE_IF_DEFAULT_VALUE. TODO: Remove this value pre-v1.
IGNORE_DEFAULT = 2 [deprecated = true];
}
// FloatRules describes the constraints applied to `float` values. These
// rules may also be applied to the `google.protobuf.FloatValue` Well-Known-Type.
message FloatRules {
// `const` requires the field value to exactly match the specified value. If
// the field value doesn't match, an error message is generated.
//
// ```proto
// message MyFloat {
// // value must equal 42.0
// float value = 1 [(buf.validate.field).float.const = 42.0];
// }
// ```
optional float const = 1 [(priv.field).cel = {
id: "float.const",
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''",
}];
oneof less_than {
// `lt` requires the field value to be less than the specified value (field <
// value). If the field value is equal to or greater than the specified value,
// an error message is generated.
//
// ```proto
// message MyFloat {
// // value must be less than 10.0
// float value = 1 [(buf.validate.field).float.lt = 10.0];
// }
// ```
float lt = 2 [(priv.field).cel = {
id: "float.lt",
expression:
"!has(rules.gte) && !has(rules.gt) && (this.isNan() || this >= rules.lt)"
"? 'value must be less than %s'.format([rules.lt]) : ''"
}];
// `lte` requires the field value to be less than or equal to the specified
// value (field <= value). If the field value is greater than the specified
// value, an error message is generated.
//
// ```proto
// message MyFloat {
// // value must be less than or equal to 10.0
// float value = 1 [(buf.validate.field).float.lte = 10.0];
// }
// ```
float lte = 3 [(priv.field).cel = {
id: "float.lte",
expression:
"!has(rules.gte) && !has(rules.gt) && (this.isNan() || this > rules.lte)"
"? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
}];
}
oneof greater_than {
// `gt` requires the field value to be greater than the specified value
// (exclusive). If the value of `gt` is larger than a specified `lt` or
// `lte`, the range is reversed, and the field value must be outside the
// specified range. If the field value doesn't meet the required conditions,
// an error message is generated.
//
// ```proto
// message MyFloat {
// // value must be greater than 5.0 [float.gt]
// float value = 1 [(buf.validate.field).float.gt = 5.0];
//
// // value must be greater than 5 and less than 10.0 [float.gt_lt]
// float other_value = 2 [(buf.validate.field).float = { gt: 5.0, lt: 10.0 }];
//
// // value must be greater than 10 or less than 5.0 [float.gt_lt_exclusive]
// float another_value = 3 [(buf.validate.field).float = { gt: 10.0, lt: 5.0 }];
// }
// ```
float gt = 4 [
(priv.field).cel = {
id: "float.gt",
expression:
"!has(rules.lt) && !has(rules.lte) && (this.isNan() || this <= rules.gt)"
"? 'value must be greater than %s'.format([rules.gt]) : ''"
},
(priv.field).cel = {
id: "float.gt_lt",
expression:
"has(rules.lt) && rules.lt >= rules.gt && (this.isNan() || this >= rules.lt || this <= rules.gt)"
"? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
},
(priv.field).cel = {
id: "float.gt_lt_exclusive",
expression:
"has(rules.lt) && rules.lt < rules.gt && (this.isNan() || (rules.lt <= this && this <= rules.gt))"
"? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
},
(priv.field).cel = {
id: "float.gt_lte",
expression:
"has(rules.lte) && rules.lte >= rules.gt && (this.isNan() || this > rules.lte || this <= rules.gt)"
"? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
},
(priv.field).cel = {
id: "float.gt_lte_exclusive",
expression:
"has(rules.lte) && rules.lte < rules.gt && (this.isNan() || (rules.lte < this && this <= rules.gt))"
"? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
}
];
// `gte` requires the field value to be greater than or equal to the specified
// value (exclusive). If the value of `gte` is larger than a specified `lt`
// or `lte`, the range is reversed, and the field value must be outside the
// specified range. If the field value doesn't meet the required conditions,
// an error message is generated.
//
// ```proto
// message MyFloat {
// // value must be greater than or equal to 5.0 [float.gte]
// float value = 1 [(buf.validate.field).float.gte = 5.0];
//
// // value must be greater than or equal to 5.0 and less than 10.0 [float.gte_lt]
// float other_value = 2 [(buf.validate.field).float = { gte: 5.0, lt: 10.0 }];
//
// // value must be greater than or equal to 10.0 or less than 5.0 [float.gte_lt_exclusive]
// float another_value = 3 [(buf.validate.field).float = { gte: 10.0, lt: 5.0 }];
// }
// ```
float gte = 5 [
(priv.field).cel = {
id: "float.gte",
expression:
"!has(rules.lt) && !has(rules.lte) && (this.isNan() || this < rules.gte)"
"? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
},
(priv.field).cel = {
id: "float.gte_lt",
expression:
"has(rules.lt) && rules.lt >= rules.gte && (this.isNan() || this >= rules.lt || this < rules.gte)"
"? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
},
(priv.field).cel = {
id: "float.gte_lt_exclusive",
expression:
"has(rules.lt) && rules.lt < rules.gte && (this.isNan() || (rules.lt <= this && this < rules.gte))"
"? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
},
(priv.field).cel = {
id: "float.gte_lte",
expression:
"has(rules.lte) && rules.lte >= rules.gte && (this.isNan() || this > rules.lte || this < rules.gte)"
"? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
},
(priv.field).cel = {
id: "float.gte_lte_exclusive",
expression:
"has(rules.lte) && rules.lte < rules.gte && (this.isNan() || (rules.lte < this && this < rules.gte))"
"? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
}
];
}
// `in` requires the field value to be equal to one of the specified values.
// If the field value isn't one of the specified values, an error message
// is generated.
//
// ```proto
// message MyFloat {
// // value must be in list [1.0, 2.0, 3.0]
// repeated float value = 1 (buf.validate.field).float = { in: [1.0, 2.0, 3.0] };
// }
// ```
repeated float in = 6 [(priv.field).cel = {
id: "float.in",
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''",
}];
// `in` requires the field value to not be equal to any of the specified
// values. If the field value is one of the specified values, an error
// message is generated.
//
// ```proto
// message MyFloat {
// // value must not be in list [1.0, 2.0, 3.0]
// repeated float value = 1 (buf.validate.field).float = { not_in: [1.0, 2.0, 3.0] };
// }
// ```
repeated float not_in = 7 [(priv.field).cel = {
id: "float.not_in",
expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''",
}];
// `finite` requires the field value to be finite. If the field value is
// infinite or NaN, an error message is generated.
bool finite = 8 [(priv.field).cel = {
id: "float.finite",
expression: "this.isNan() || this.isInf() ? 'value must be finite' : ''",
}];
}
// DoubleRules describes the constraints applied to `double` values. These
// rules may also be applied to the `google.protobuf.DoubleValue` Well-Known-Type.
message DoubleRules {
// `const` requires the field value to exactly match the specified value. If
// the field value doesn't match, an error message is generated.
//
// ```proto
// message MyDouble {
// // value must equal 42.0
// double value = 1 [(buf.validate.field).double.const = 42.0];
// }
// ```
optional double const = 1 [(priv.field).cel = {
id: "double.const",
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''",
}];
oneof less_than {
// `lt` requires the field value to be less than the specified value (field <
// value). If the field value is equal to or greater than the specified
// value, an error message is generated.
//
// ```proto
// message MyDouble {
// // value must be less than 10.0
// double value = 1 [(buf.validate.field).double.lt = 10.0];
// }
// ```
double lt = 2 [(priv.field).cel = {
id: "double.lt",
expression:
"!has(rules.gte) && !has(rules.gt) && (this.isNan() || this >= rules.lt)"
"? 'value must be less than %s'.format([rules.lt]) : ''"
}];
// `lte` requires the field value to be less than or equal to the specified value
// (field <= value). If the field value is greater than the specified value,
// an error message is generated.
//
// ```proto
// message MyDouble {
// // value must be less than or equal to 10.0
// double value = 1 [(buf.validate.field).double.lte = 10.0];
// }
// ```
double lte = 3 [(priv.field).cel = {
id: "double.lte",
expression:
"!has(rules.gte) && !has(rules.gt) && (this.isNan() || this > rules.lte)"
"? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
}];
}
oneof greater_than {
// `gt` requires the field value to be greater than the specified value
// (exclusive). If the value of `gt` is larger than a specified `lt` or `lte`,
// the range is reversed, and the field value must be outside the specified
// range. If the field value doesn't meet the required conditions, an error
// message is generated.
//
// ```proto
// message MyDouble {
// // value must be greater than 5.0 [double.gt]
// double value = 1 [(buf.validate.field).double.gt = 5.0];
//
// // value must be greater than 5 and less than 10.0 [double.gt_lt]
// double other_value = 2 [(buf.validate.field).double = { gt: 5.0, lt: 10.0 }];
//
// // value must be greater than 10 or less than 5.0 [double.gt_lt_exclusive]
// double another_value = 3 [(buf.validate.field).double = { gt: 10.0, lt: 5.0 }];
// }
// ```
double gt = 4 [
(priv.field).cel = {
id: "double.gt",
expression:
"!has(rules.lt) && !has(rules.lte) && (this.isNan() || this <= rules.gt)"
"? 'value must be greater than %s'.format([rules.gt]) : ''"
},
(priv.field).cel = {
id: "double.gt_lt",
expression:
"has(rules.lt) && rules.lt >= rules.gt && (this.isNan() || this >= rules.lt || this <= rules.gt)"
"? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
},
(priv.field).cel = {
id: "double.gt_lt_exclusive",
expression:
"has(rules.lt) && rules.lt < rules.gt && (this.isNan() || (rules.lt <= this && this <= rules.gt))"
"? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
},
(priv.field).cel = {
id: "double.gt_lte",
expression:
"has(rules.lte) && rules.lte >= rules.gt && (this.isNan() || this > rules.lte || this <= rules.gt)"
"? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
},
(priv.field).cel = {
id: "double.gt_lte_exclusive",
expression:
"has(rules.lte) && rules.lte < rules.gt && (this.isNan() || (rules.lte < this && this <= rules.gt))"
"? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
}
];
// `gte` requires the field value to be greater than or equal to the specified
// value (exclusive). If the value of `gte` is larger than a specified `lt` or
// `lte`, the range is reversed, and the field value must be outside the
// specified range. If the field value doesn't meet the required conditions,
// an error message is generated.
//
// ```proto
// message MyDouble {
// // value must be greater than or equal to 5.0 [double.gte]
// double value = 1 [(buf.validate.field).double.gte = 5.0];
//
// // value must be greater than or equal to 5.0 and less than 10.0 [double.gte_lt]
// double other_value = 2 [(buf.validate.field).double = { gte: 5.0, lt: 10.0 }];
//
// // value must be greater than or equal to 10.0 or less than 5.0 [double.gte_lt_exclusive]
// double another_value = 3 [(buf.validate.field).double = { gte: 10.0, lt: 5.0 }];
// }
// ```
double gte = 5 [
(priv.field).cel = {
id: "double.gte",
expression:
"!has(rules.lt) && !has(rules.lte) && (this.isNan() || this < rules.gte)"
"? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
},
(priv.field).cel = {
id: "double.gte_lt",
expression:
"has(rules.lt) && rules.lt >= rules.gte && (this.isNan() || this >= rules.lt || this < rules.gte)"
"? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
},
(priv.field).cel = {
id: "double.gte_lt_exclusive",
expression:
"has(rules.lt) && rules.lt < rules.gte && (this.isNan() || (rules.lt <= this && this < rules.gte))"
"? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
},
(priv.field).cel = {
id: "double.gte_lte",
expression:
"has(rules.lte) && rules.lte >= rules.gte && (this.isNan() || this > rules.lte || this < rules.gte)"
"? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
},
(priv.field).cel = {
id: "double.gte_lte_exclusive",
expression:
"has(rules.lte) && rules.lte < rules.gte && (this.isNan() || (rules.lte < this && this < rules.gte))"
"? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
}
];
}
// `in` requires the field value to be equal to one of the specified values.
// If the field value isn't one of the specified values, an error message is
// generated.
//
// ```proto
// message MyDouble {
// // value must be in list [1.0, 2.0, 3.0]
// repeated double value = 1 (buf.validate.field).double = { in: [1.0, 2.0, 3.0] };
// }
// ```
repeated double in = 6 [(priv.field).cel = {
id: "double.in",
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''",
}];
// `not_in` requires the field value to not be equal to any of the specified
// values. If the field value is one of the specified values, an error
// message is generated.
//
// ```proto
// message MyDouble {
// // value must not be in list [1.0, 2.0, 3.0]
// repeated double value = 1 (buf.validate.field).double = { not_in: [1.0, 2.0, 3.0] };
// }
// ```
repeated double not_in = 7 [(priv.field).cel = {
id: "double.not_in",
expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''",
}];
// `finite` requires the field value to be finite. If the field value is
// infinite or NaN, an error message is generated.
bool finite = 8 [(priv.field).cel = {
id: "double.finite",
expression: "this.isNan() || this.isInf() ? 'value must be finite' : ''",
}];
}
// Int32Rules describes the constraints applied to `int32` values. These
// rules may also be applied to the `google.protobuf.Int32Value` Well-Known-Type.
message Int32Rules {
// `const` requires the field value to exactly match the specified value. If
// the field value doesn't match, an error message is generated.
//
// ```proto
// message MyInt32 {
// // value must equal 42
// int32 value = 1 [(buf.validate.field).int32.const = 42];
// }
// ```
optional int32 const = 1 [(priv.field).cel = {
id: "int32.const",
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''",
}];
oneof less_than {
// `lt` requires the field value to be less than the specified value (field
// < value). If the field value is equal to or greater than the specified
// value, an error message is generated.
//
// ```proto
// message MyInt32 {
// // value must be less than 10
// int32 value = 1 [(buf.validate.field).int32.lt = 10];
// }
// ```
int32 lt = 2 [(priv.field).cel = {
id: "int32.lt",
expression:
"!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
"? 'value must be less than %s'.format([rules.lt]) : ''"
}];
// `lte` requires the field value to be less than or equal to the specified
// value (field <= value). If the field value is greater than the specified
// value, an error message is generated.
//
// ```proto
// message MyInt32 {
// // value must be less than or equal to 10
// int32 value = 1 [(buf.validate.field).int32.lte = 10];
// }
// ```
int32 lte = 3 [(priv.field).cel = {
id: "int32.lte",
expression:
"!has(rules.gte) && !has(rules.gt) && this > rules.lte"
"? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
}];
}
oneof greater_than {
// `gt` requires the field value to be greater than the specified value
// (exclusive). If the value of `gt` is larger than a specified `lt` or
// `lte`, the range is reversed, and the field value must be outside the
// specified range. If the field value doesn't meet the required conditions,
// an error message is generated.
//
// ```proto
// message MyInt32 {
// // value must be greater than 5 [int32.gt]
// int32 value = 1 [(buf.validate.field).int32.gt = 5];
//
// // value must be greater than 5 and less than 10 [int32.gt_lt]
// int32 other_value = 2 [(buf.validate.field).int32 = { gt: 5, lt: 10 }];
//
// // value must be greater than 10 or less than 5 [int32.gt_lt_exclusive]
// int32 another_value = 3 [(buf.validate.field).int32 = { gt: 10, lt: 5 }];
// }
// ```
int32 gt = 4 [
(priv.field).cel = {
id: "int32.gt",
expression:
"!has(rules.lt) && !has(rules.lte) && this <= rules.gt"
"? 'value must be greater than %s'.format([rules.gt]) : ''"
},
(priv.field).cel = {
id: "int32.gt_lt",
expression:
"has(rules.lt) && rules.lt >= rules.gt && (this >= rules.lt || this <= rules.gt)"
"? 'value must be greater than %s and less than %s'.format([rules.gt, rules.lt]) : ''"
},
(priv.field).cel = {
id: "int32.gt_lt_exclusive",
expression:
"has(rules.lt) && rules.lt < rules.gt && (rules.lt <= this && this <= rules.gt)"
"? 'value must be greater than %s or less than %s'.format([rules.gt, rules.lt]) : ''"
},
(priv.field).cel = {
id: "int32.gt_lte",
expression:
"has(rules.lte) && rules.lte >= rules.gt && (this > rules.lte || this <= rules.gt)"
"? 'value must be greater than %s and less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
},
(priv.field).cel = {
id: "int32.gt_lte_exclusive",
expression:
"has(rules.lte) && rules.lte < rules.gt && (rules.lte < this && this <= rules.gt)"
"? 'value must be greater than %s or less than or equal to %s'.format([rules.gt, rules.lte]) : ''"
}
];
// `gte` requires the field value to be greater than or equal to the specified value
// (exclusive). If the value of `gte` is larger than a specified `lt` or
// `lte`, the range is reversed, and the field value must be outside the
// specified range. If the field value doesn't meet the required conditions,
// an error message is generated.
//
// ```proto
// message MyInt32 {
// // value must be greater than or equal to 5 [int32.gte]
// int32 value = 1 [(buf.validate.field).int32.gte = 5];
//
// // value must be greater than or equal to 5 and less than 10 [int32.gte_lt]
// int32 other_value = 2 [(buf.validate.field).int32 = { gte: 5, lt: 10 }];
//
// // value must be greater than or equal to 10 or less than 5 [int32.gte_lt_exclusive]
// int32 another_value = 3 [(buf.validate.field).int32 = { gte: 10, lt: 5 }];
// }
// ```
int32 gte = 5 [
(priv.field).cel = {
id: "int32.gte",
expression:
"!has(rules.lt) && !has(rules.lte) && this < rules.gte"
"? 'value must be greater than or equal to %s'.format([rules.gte]) : ''"
},
(priv.field).cel = {
id: "int32.gte_lt",
expression:
"has(rules.lt) && rules.lt >= rules.gte && (this >= rules.lt || this < rules.gte)"
"? 'value must be greater than or equal to %s and less than %s'.format([rules.gte, rules.lt]) : ''"
},
(priv.field).cel = {
id: "int32.gte_lt_exclusive",
expression:
"has(rules.lt) && rules.lt < rules.gte && (rules.lt <= this && this < rules.gte)"
"? 'value must be greater than or equal to %s or less than %s'.format([rules.gte, rules.lt]) : ''"
},
(priv.field).cel = {
id: "int32.gte_lte",
expression:
"has(rules.lte) && rules.lte >= rules.gte && (this > rules.lte || this < rules.gte)"
"? 'value must be greater than or equal to %s and less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
},
(priv.field).cel = {
id: "int32.gte_lte_exclusive",
expression:
"has(rules.lte) && rules.lte < rules.gte && (rules.lte < this && this < rules.gte)"
"? 'value must be greater than or equal to %s or less than or equal to %s'.format([rules.gte, rules.lte]) : ''"
}
];
}
// `in` requires the field value to be equal to one of the specified values.
// If the field value isn't one of the specified values, an error message is
// generated.
//
// ```proto
// message MyInt32 {
// // value must be in list [1, 2, 3]
// repeated int32 value = 1 (buf.validate.field).int32 = { in: [1, 2, 3] };
// }
// ```
repeated int32 in = 6 [(priv.field).cel = {
id: "int32.in",
expression: "!(this in dyn(rules)['in']) ? 'value must be in list %s'.format([dyn(rules)['in']]) : ''",
}];
// `not_in` requires the field value to not be equal to any of the specified
// values. If the field value is one of the specified values, an error message
// is generated.
//
// ```proto
// message MyInt32 {
// // value must not be in list [1, 2, 3]
// repeated int32 value = 1 (buf.validate.field).int32 = { not_in: [1, 2, 3] };
// }
// ```
repeated int32 not_in = 7 [(priv.field).cel = {
id: "int32.not_in",
expression: "this in rules.not_in ? 'value must not be in list %s'.format([rules.not_in]) : ''",
}];
}
// Int64Rules describes the constraints applied to `int64` values. These
// rules may also be applied to the `google.protobuf.Int64Value` Well-Known-Type.
message Int64Rules {
// `const` requires the field value to exactly match the specified value. If
// the field value doesn't match, an error message is generated.
//
// ```proto
// message MyInt64 {
// // value must equal 42
// int64 value = 1 [(buf.validate.field).int64.const = 42];
// }
// ```
optional int64 const = 1 [(priv.field).cel = {
id: "int64.const",
expression: "this != rules.const ? 'value must equal %s'.format([rules.const]) : ''",
}];
oneof less_than {
// `lt` requires the field value to be less than the specified value (field <
// value). If the field value is equal to or greater than the specified value,
// an error message is generated.
//
// ```proto
// message MyInt64 {
// // value must be less than 10
// int64 value = 1 [(buf.validate.field).int64.lt = 10];
// }
// ```
int64 lt = 2 [(priv.field).cel = {
id: "int64.lt",
expression:
"!has(rules.gte) && !has(rules.gt) && this >= rules.lt"
"? 'value must be less than %s'.format([rules.lt]) : ''"
}];
// `lte` requires the field value to be less than or equal to the specified
// value (field <= value). If the field value is greater than the specified
// value, an error message is generated.
//
// ```proto
// message MyInt64 {
// // value must be less than or equal to 10
// int64 value = 1 [(buf.validate.field).int64.lte = 10];
// }
// ```
int64 lte = 3 [(priv.field).cel = {
id: "int64.lte",
expression:
"!has(rules.gte) && !has(rules.gt) && this > rules.lte"
"? 'value must be less than or equal to %s'.format([rules.lte]) : ''"
}];
}
oneof greater_than {
// `gt` requires the field value to be greater than the specified value
// (exclusive). If the value of `gt` is larger than a specified `lt` or
// `lte`, the range is reversed, and the field value must be outside the
// specified range. If the field value doesn't meet the required conditions,
// an error message is generated.
//
// ```proto
// message MyInt64 {
// // value must be greater than 5 [int64.gt]
// int64 value = 1 [(buf.validate.field).int64.gt = 5];
//
// // value must be greater than 5 and less than 10 [int64.gt_lt]
// int64 other_value = 2 [(buf.validate.field).int64 = { gt: 5, lt: 10 }];
//
// // value must be greater than 10 or less than 5 [int64.gt_lt_exclusive]
// int64 another_value = 3 [(buf.validate.field).int64 = { gt: 10, lt: 5 }];
// }
// ```
int64 gt = 4 [
(priv.field).cel = {