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] Add skipped_fields field constraint for finer-grained skipped behavior #112

Open
rodaine opened this issue Oct 17, 2023 · 0 comments
Labels
Feature New feature or request

Comments

@rodaine
Copy link
Member

rodaine commented Oct 17, 2023

Feature description:

Today, we support the skipped standard constraint on message fields to skip any validation constraints applied to the underlying type. This is currently an all or nothing scenario, when perhaps it's desired to opt-out of one or a few of the message's fields.

Potentially, we can support this via a skipped_fields constraint which takes a FieldMask and can specify which not to evaluate.

Problem it solves or use case:

Example use-case where a message describing a resource elided a constraint for a field and had the RPC request object use a CEL expression to validate that nested field.

Proposed implementation or solution:

# validate.proto

# <snip>

message FieldConstraints {
  # <snip>
  oneof skip {
    bool skipped = 24;
    google.protobuf.FieldMask skipped_fields = XX;
  }
  # <snip>
}

# <snip>
# example.proto

message Foo {
  string id   = 1 [(buf.validate.field).string.uuid = true];
  bytes  data = 2 [(buf.validate.field).bytes.min_len = 42];
}

message Bar {
  Foo foo = 1 [(buf.validate.field).skipped_fields.paths = "id" ];
}

In the example above, Foo by itself will verify the value of the id field to be a UUID and the data field to be of a minimum length. However, if validate is called on a Bar containing a Foo, only the data field will be evaluated as id has been skipped.

@rodaine rodaine added the Feature New feature or request label Oct 17, 2023
@rodaine rodaine changed the title [Feature Request] [Feature Request] Add skipped_fields field constraint for finer-grained skipped behavior Oct 17, 2023
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

1 participant