Skip to content

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

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

Closed
dvaldivia opened this issue Mar 11, 2024 · 2 comments
Closed
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
];

@smaye81
Copy link
Member

smaye81 commented May 29, 2025

@dvaldivia closing this issue. If you have any other problems, feel free to reopen or create a new one.

@smaye81 smaye81 closed this as completed May 29, 2025
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

3 participants