@@ -127,8 +127,8 @@ absl::Status MessageConstraintRules::Validate(
127
127
absl::Status FieldConstraintRules::Validate (
128
128
ConstraintContext& ctx, const google::protobuf::Message& message) const {
129
129
static const google::protobuf::FieldDescriptor* requiredField =
130
- FieldConstraints ::descriptor ()->FindFieldByNumber (
131
- FieldConstraints ::kRequiredFieldNumber );
130
+ FieldRules ::descriptor ()->FindFieldByNumber (
131
+ FieldRules ::kRequiredFieldNumber );
132
132
google::api::expr::runtime::Activation activation;
133
133
cel::runtime::CelValue result;
134
134
std::string subPath;
@@ -141,11 +141,11 @@ absl::Status FieldConstraintRules::Validate(
141
141
return absl::OkStatus ();
142
142
} else if (required_) {
143
143
Violation violation;
144
- *violation.mutable_constraint_id () = " required" ;
144
+ *violation.mutable_rule_id () = " required" ;
145
145
*violation.mutable_message () = " value is required" ;
146
146
*violation.mutable_field ()->mutable_elements ()->Add () = fieldPathElement (field_);
147
147
*violation.mutable_rule ()->mutable_elements ()->Add () =
148
- staticFieldPathElement<FieldConstraints, FieldConstraints ::kRequiredFieldNumber >();
148
+ staticFieldPathElement<FieldRules, FieldRules ::kRequiredFieldNumber >();
149
149
ctx.violations .emplace_back (
150
150
std::move (violation),
151
151
ProtoField{&message, field_},
@@ -161,11 +161,11 @@ absl::Status FieldConstraintRules::Validate(
161
161
return absl::OkStatus ();
162
162
} else if (required_) {
163
163
Violation violation;
164
- *violation.mutable_constraint_id () = " required" ;
164
+ *violation.mutable_rule_id () = " required" ;
165
165
*violation.mutable_message () = " value is required" ;
166
166
*violation.mutable_field ()->mutable_elements ()->Add () = fieldPathElement (field_);
167
167
*violation.mutable_rule ()->mutable_elements ()->Add () =
168
- staticFieldPathElement<FieldConstraints, FieldConstraints ::kRequiredFieldNumber >();
168
+ staticFieldPathElement<FieldRules, FieldRules ::kRequiredFieldNumber >();
169
169
ctx.violations .emplace_back (
170
170
std::move (violation),
171
171
ProtoField{&message, field_},
@@ -176,11 +176,11 @@ absl::Status FieldConstraintRules::Validate(
176
176
if (!message.GetReflection ()->HasField (message, field_)) {
177
177
if (required_) {
178
178
Violation violation;
179
- *violation.mutable_constraint_id () = " required" ;
179
+ *violation.mutable_rule_id () = " required" ;
180
180
*violation.mutable_message () = " value is required" ;
181
181
*violation.mutable_field ()->mutable_elements ()->Add () = fieldPathElement (field_);
182
182
*violation.mutable_rule ()->mutable_elements ()->Add () =
183
- staticFieldPathElement<FieldConstraints, FieldConstraints ::kRequiredFieldNumber >();
183
+ staticFieldPathElement<FieldRules, FieldRules ::kRequiredFieldNumber >();
184
184
ctx.violations .emplace_back (
185
185
std::move (violation),
186
186
ProtoField{&message, field_},
@@ -235,11 +235,11 @@ absl::Status EnumConstraintRules::Validate(
235
235
auto value = message.GetReflection ()->GetEnumValue (message, field_);
236
236
if (field_->enum_type ()->FindValueByNumber (value) == nullptr ) {
237
237
Violation violation;
238
- *violation.mutable_constraint_id () = " enum.defined_only" ;
238
+ *violation.mutable_rule_id () = " enum.defined_only" ;
239
239
*violation.mutable_message () = " value must be one of the defined enum values" ;
240
240
*violation.mutable_field ()->mutable_elements ()->Add () = fieldPathElement (field_);
241
241
*violation.mutable_rule ()->mutable_elements ()->Add () = fieldPathElement (EnumRules::descriptor ()->FindFieldByNumber (EnumRules::kDefinedOnlyFieldNumber ));
242
- *violation.mutable_rule ()->mutable_elements ()->Add () = fieldPathElement (FieldConstraints ::descriptor ()->FindFieldByNumber (FieldConstraints ::kEnumFieldNumber ));
242
+ *violation.mutable_rule ()->mutable_elements ()->Add () = fieldPathElement (FieldRules ::descriptor ()->FindFieldByNumber (FieldRules ::kEnumFieldNumber ));
243
243
ctx.violations .emplace_back (
244
244
std::move (violation),
245
245
ProtoField{&message, field_},
@@ -280,7 +280,7 @@ absl::Status RepeatedConstraintRules::Validate(
280
280
ctx.appendFieldPathElement (element, pos);
281
281
ctx.appendRulePathElement ({
282
282
fieldPathElement (RepeatedRules::descriptor ()->FindFieldByNumber (RepeatedRules::kItemsFieldNumber )),
283
- fieldPathElement (FieldConstraints ::descriptor ()->FindFieldByNumber (FieldConstraints ::kRepeatedFieldNumber )),
283
+ fieldPathElement (FieldRules ::descriptor ()->FindFieldByNumber (FieldRules ::kRepeatedFieldNumber )),
284
284
}, pos);
285
285
ctx.setFieldValue (ProtoField{&message, field_, i}, pos);
286
286
}
@@ -320,7 +320,7 @@ absl::Status MapConstraintRules::Validate(
320
320
if (ctx.violations .size () > pos) {
321
321
ctx.appendRulePathElement ({
322
322
fieldPathElement (MapRules::descriptor ()->FindFieldByNumber (MapRules::kKeysFieldNumber )),
323
- fieldPathElement (FieldConstraints ::descriptor ()->FindFieldByNumber (FieldConstraints ::kMapFieldNumber )),
323
+ fieldPathElement (FieldRules ::descriptor ()->FindFieldByNumber (FieldRules ::kMapFieldNumber )),
324
324
}, pos);
325
325
ctx.setFieldValue (ProtoField{&elemMsg, keyField}, pos);
326
326
ctx.setForKey (pos);
@@ -340,7 +340,7 @@ absl::Status MapConstraintRules::Validate(
340
340
if (ctx.violations .size () > valuePos) {
341
341
ctx.appendRulePathElement ({
342
342
fieldPathElement (MapRules::descriptor ()->FindFieldByNumber (MapRules::kValuesFieldNumber )),
343
- fieldPathElement (FieldConstraints ::descriptor ()->FindFieldByNumber (FieldConstraints ::kMapFieldNumber )),
343
+ fieldPathElement (FieldRules ::descriptor ()->FindFieldByNumber (FieldRules ::kMapFieldNumber )),
344
344
}, valuePos);
345
345
ctx.setFieldValue (ProtoField{&elemMsg, valueField}, pos);
346
346
}
@@ -389,15 +389,15 @@ absl::Status FieldConstraintRules::ValidateAny(
389
389
}
390
390
if (!found) {
391
391
Violation violation;
392
- *violation.mutable_constraint_id () = " any.in" ;
392
+ *violation.mutable_rule_id () = " any.in" ;
393
393
*violation.mutable_message () = " type URL must be in the allow list" ;
394
394
if (field.index () == -1 ) {
395
395
*violation.mutable_field ()->mutable_elements ()->Add () = fieldPathElement (field.descriptor ());
396
396
}
397
397
*violation.mutable_rule ()->mutable_elements ()->Add () =
398
398
staticFieldPathElement<AnyRules, AnyRules::kInFieldNumber >();
399
399
*violation.mutable_rule ()->mutable_elements ()->Add () =
400
- staticFieldPathElement<FieldConstraints, FieldConstraints ::kAnyFieldNumber >();
400
+ staticFieldPathElement<FieldRules, FieldRules ::kAnyFieldNumber >();
401
401
ctx.violations .emplace_back (
402
402
std::move (violation),
403
403
field,
@@ -407,15 +407,15 @@ absl::Status FieldConstraintRules::ValidateAny(
407
407
for (const auto & block : anyRules_->not_in ()) {
408
408
if (block == typeUri) {
409
409
Violation violation;
410
- *violation.mutable_constraint_id () = " any.not_in" ;
410
+ *violation.mutable_rule_id () = " any.not_in" ;
411
411
*violation.mutable_message () = " type URL must not be in the block list" ;
412
412
if (field.index () == -1 ) {
413
413
*violation.mutable_field ()->mutable_elements ()->Add () = fieldPathElement (field.descriptor ());
414
414
}
415
415
*violation.mutable_rule ()->mutable_elements ()->Add () =
416
416
staticFieldPathElement<AnyRules, AnyRules::kNotInFieldNumber >();
417
417
*violation.mutable_rule ()->mutable_elements ()->Add () =
418
- staticFieldPathElement<FieldConstraints, FieldConstraints ::kAnyFieldNumber >();
418
+ staticFieldPathElement<FieldRules, FieldRules ::kAnyFieldNumber >();
419
419
ctx.violations .emplace_back (
420
420
std::move (violation),
421
421
field,
@@ -432,7 +432,7 @@ absl::Status OneofConstraintRules::Validate(
432
432
if (required_) {
433
433
if (!message.GetReflection ()->HasOneof (message, oneof_)) {
434
434
Violation violation;
435
- *violation.mutable_constraint_id () = " required" ;
435
+ *violation.mutable_rule_id () = " required" ;
436
436
*violation.mutable_message () = " exactly one field is required in oneof" ;
437
437
*violation.mutable_field ()->mutable_elements ()->Add () = oneofPathElement (*oneof_);
438
438
ctx.violations .emplace_back (std::move (violation), absl::nullopt, absl::nullopt);
0 commit comments