MapRules describe the rules applied to map values.
MapRules describe the rules applied to map values.
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.
OptionalkeysSpecifies the rules to be applied to each key in the field.
message MyMap {
// The keys in the field `value` must follow the specified rules.
map<string, string> value = 1 [(buf.validate.field).map.keys = {
string: {
min_len: 3
max_len: 10
}
}];
}
Note that the required rule does not apply. Map keys cannot be unset.
OptionalmaxSpecifies the maximum number of key-value pairs allowed. If the field has more key-value pairs than specified, an error message is generated.
message MyMap {
// The field `value` must have at most 3 key-value pairs.
map<string, string> value = 1 [(buf.validate.field).map.max_pairs = 3];
}
OptionalminSpecifies the minimum number of key-value pairs allowed. If the field has fewer key-value pairs than specified, an error message is generated.
message MyMap {
// The field `value` must have at least 2 key-value pairs.
map<string, string> value = 1 [(buf.validate.field).map.min_pairs = 2];
}
OptionalvaluesSpecifies the rules to be applied to the value of each key in the
field. Message values will still have their validations evaluated unless
ignore is specified.
message MyMap {
// The values in the field `value` must follow the specified rules.
map<string, string> value = 1 [(buf.validate.field).map.values = {
string: {
min_len: 5
max_len: 20
}
}];
}
Note that the required rule does not apply. Map values cannot be unset.
MapRules describe the rules applied to
mapvalues.