protovalidate
protovalidate copied to clipboard
[Feature Request] Have URI validations for string but also allow empty
I'm trying to have an optional field that if it's set, I want to make sure it's a URI, but if it's missing or empty, I want to allow it, so I set my validation and message in the following way
message AppUpdateFields {
optional int64 volumeSize = 1;
optional string storageClass = 2;
optional string targetUrl = 3 [(buf.validate.field).string = {
min_len: 0,
uri: true}];
}
However it's not allowing for empty string, how can this be achieved?
Try (buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
optional string targetUrl = 3 [
(buf.validate.field).string.uri = true,
(buf.validate.field).ignore = IGNORE_IF_UNPOPULATED
];