protovalidate icon indicating copy to clipboard operation
protovalidate copied to clipboard

[Feature Request] Have URI validations for string but also allow empty

Open dvaldivia opened this issue 1 year ago • 1 comments

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?

dvaldivia avatar Mar 11 '24 03:03 dvaldivia

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
];

nicksnyder avatar Mar 11 '24 16:03 nicksnyder