MessageRules represents validation rules that are applied to the entire message. It includes disabling options and a list of Rule messages representing Common Expression Language (CEL) validation rules.
MessageRules represents validation rules that are applied to the entire message. It includes disabling options and a list of Rule messages representing Common Expression Language (CEL) validation rules.
Optional[customReturns a safe value for JSON logs.
Returns a safe value for JSON logs.
Optional[unknownPreserves protobuf fields that this SDK version does not recognize.
Contains the fully qualified protobuf type name.
cel is a repeated field of type Rule. Each Rule specifies a validation rule to be applied to this message.
These rules are written in Common Expression Language (CEL) syntax. For more information,
see our documentation.
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;
}
cel_expression is a repeated field CEL expressions. Each expression specifies a validation
rule to be applied to this message. These rules are written in Common Expression Language (CEL) syntax.
This is a simplified form of the cel Rule field, where only expression is set. This allows for
simpler syntax when defining CEL Rules where id and message derived from the expression. id will
be same as the expression.
For more information, see our documentation.
message MyMessage {
// The field `foo` must be greater than 42.
option (buf.validate.message).cel_expression = "this.foo > 42";
// The field `foo` must be less than 84.
option (buf.validate.message).cel_expression = "this.foo < 84";
optional int32 foo = 1;
}
oneof is a repeated field of type MessageOneofRule that specifies a list of fields
of which at most one can be present. If required is also specified, then exactly one
of the specified fields must be present.
This will enforce oneof-like constraints with a few features not provided by actual Protobuf oneof declarations:
Note that adding a field to a oneof will also set the IGNORE_IF_ZERO_VALUE on the fields. This means
only the field that is set will be validated and the unset fields are not validated according to the field rules.
This behavior can be overridden by setting ignore against a field.
message MyMessage {
// Only one of `field1` or `field2` _can_ be present in this message.
option (buf.validate.message).oneof = { fields: ["field1", "field2"] };
// Exactly one of `field3` or `field4` _must_ be present in this message.
option (buf.validate.message).oneof = { fields: ["field3", "field4"], required: true };
string field1 = 1;
bytes field2 = 2;
bool field3 = 3;
int32 field4 = 4;
}
MessageRules represents validation rules that are applied to the entire message. It includes disabling options and a list of Rule messages representing Common Expression Language (CEL) validation rules.