Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dvaldivia opened this issue Mar 11, 2024 · 1 comment
Open
Labels
Feature New feature or request

Comments

@dvaldivia
Copy link

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 dvaldivia added the Feature New feature or request label Mar 11, 2024
@nicksnyder
Copy link
Member

nicksnyder commented Mar 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants