You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request] Add skipped_fields field constraint for finer-grained skipped behavior #112
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.
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.
Reacted by Kevin McDonald, Václav R. Gröhling, Johannes Brüderl, Martin Schneppenheim, Jacob Kristhammar, smthpickboy, blame2020, loodde, Asker Khuzhokov and Eddie Soller
changed the title [-][Feature Request] [/-][+][Feature Request] Add skipped_fields field constraint for finer-grained skipped behavior[/+]on Oct 17, 2023
This will work for Google AIP update methods, where the input message is typically just a partial message, and unset values should not trigger validation if not specified in FieldMask update_mask.
The only drawback is that the update_mask is dynamic and must be applied in runtime via a reflection. For that reason, it would be handy to have MessageConstraints to set skipped_fields on the target message, not on its parent. Maybe define a new well-known function for skipping validation that could be used in the MessageConstraints.cel?
This will work for Google AIP update methods, where the input message is typically just a partial message, and unset values should not trigger validation if not specified in FieldMask update_mask.
The only drawback is that the update_mask is dynamic and must be applied in runtime via a reflection. For that reason, it would be handy to have MessageConstraints to set skipped_fields on the target message, not on its parent. Maybe define a new well-known function for skipping validation that could be used in the MessageConstraints.cel?
This is essential for building an API that conforms to Google's AIP spec.
This will work for Google AIP update methods, where the input message is typically just a partial message, and unset values should not trigger validation if not specified in FieldMask update_mask.
The only drawback is that the update_mask is dynamic and must be applied in runtime via a reflection. For that reason, it would be handy to have MessageConstraints to set skipped_fields on the target message, not on its parent. Maybe define a new well-known function for skipping validation that could be used in the MessageConstraints.cel?
Agreed. We need a way to validate only the fields specified in google.protobuf.FieldMask update_mask.
Do we think it might be possible to update the Filter API to pass in a field path? That would make it possible to support field masks using the filter API. Today, we only pass in a message and a field/oneof/message descriptor, which make it extremely difficult to know how we got to a particular field.
I believe this is possible in a backwards compatible way... Is this a viable option?
Then, if an update_mask is provided it will be used to validate only those fields? You could also do something like: option (buf.validate.message).field_mask.paths = "foo.data"; to specify a hard coded list instead of having one provided in the call. I'm not sure what the paths are supposed to be relative to (would you specify foo.data or just data?), but I assume there is a standard for this and it would need to handle nested messages.
Do we think it might be possible to update the Filter API to pass in a field path? That would make it possible to support field masks using the filter API. Today, we only pass in a message and a field/oneof/message descriptor, which make it extremely difficult to know how we got to a particular field.
I believe this is possible in a backwards compatible way... Is this a viable option?
@DolceTriade the filter behavior is really only exposed by pv-go for buf lint support. It's not considered part of the actual protovalidate API. Since the filtering is not carried by the proto definitions themselves, it doesn't fit into the intent of the protovalidate annotations which are intended to be self contained and portable. Effectively, validation would be different across implementations, which we want to avoid building in as a footgun.
Maybe it would be better to have the field mask on the field itself like so:
That way it is clearer that the field mask paths are relative to the foo resource which then aligns with google's AIP 134.
@jeffsawatzky the primary issue here is that field rules right now (intentionally) don't carry a reference to the parent message or sibling fields. This would need to be on the message level, mapping a mask to its target field. There's prior art for this pattern in the synthetic message.one_of rules.
@DolceTriade the filter behavior is really only exposed by pv-go for buf lint support. It's not considered part of the actual protovalidate API. Since the filtering is not carried by the proto definitions themselves, it doesn't fit into the intent of the protovalidate annotations which are intended to be self contained and portable. Effectively, validation would be different across implementations, which we want to avoid building in as a footgun.
I see. It would be nice to support selective validation (which i don't think would be different between different implementations of protovalidate...)
@DolceTriade woild something like what is described in #486 be useful? Having validations run only under certain contexts and those contexts can be specified in the root request/response message options?
I see. It would be nice to support selective validation (which i don't think would be different between different implementations of protovalidate...)
Yep! That's the intent of this issue 😁 It's not just that the implementations have to support it; the protos (schema and/or data) themselves have to carry this information.
@DolceTriade woild something like what is described in #486 be useful? Having validations run only under certain contexts and those contexts can be specified in the root request/response message options?
A non-declarative variant would be better to be more universally useful. For example, a context needs to be declared ahead of time whereas a field mask could allow fields in a patch request to be skipped entirely (cuz they're empty and not meant to be modified).
Activity
[-][Feature Request] [/-][+][Feature Request] Add skipped_fields field constraint for finer-grained skipped behavior[/+]czabaj commentedon Mar 3, 2025
This will work for Google AIP update methods, where the input message is typically just a partial message, and unset values should not trigger validation if not specified in
FieldMask update_mask.The only drawback is that the
update_maskis dynamic and must be applied in runtime via a reflection. For that reason, it would be handy to haveMessageConstraintsto setskipped_fieldson the target message, not on its parent. Maybe define a new well-known function for skipping validation that could be used in theMessageConstraints.cel?smthpickboy commentedon May 17, 2025
This is essential for building an API that conforms to Google's AIP spec.
juanmarin-co commentedon Jul 23, 2025
¿Is there a workaround to implement dynamic validation given an update_mask? As @smthpickboy said, it is required for complying with Google's AIP
voidfoxy commentedon Sep 2, 2025
Agreed. We need a way to validate only the fields specified in
google.protobuf.FieldMask update_mask.DolceTriade commentedon Mar 11, 2026
Do we think it might be possible to update the Filter API to pass in a field path? That would make it possible to support field masks using the filter API. Today, we only pass in a message and a field/oneof/message descriptor, which make it extremely difficult to know how we got to a particular field.
I believe this is possible in a backwards compatible way... Is this a viable option?
jeffsawatzky commentedon May 27, 2026
Would something like this work?
Then, if an
update_maskis provided it will be used to validate only those fields? You could also do something like:option (buf.validate.message).field_mask.paths = "foo.data";to specify a hard coded list instead of having one provided in the call. I'm not sure what the paths are supposed to be relative to (would you specifyfoo.dataor justdata?), but I assume there is a standard for this and it would need to handle nested messages.jeffsawatzky commentedon May 27, 2026
Maybe it would be better to have the field mask on the field itself like so:
That way it is clearer that the field mask paths are relative to the
fooresource which then aligns with google's AIP 134.rodaine commentedon May 27, 2026
@DolceTriade the filter behavior is really only exposed by pv-go for
buf lintsupport. It's not considered part of the actual protovalidate API. Since the filtering is not carried by the proto definitions themselves, it doesn't fit into the intent of the protovalidate annotations which are intended to be self contained and portable. Effectively, validation would be different across implementations, which we want to avoid building in as a footgun.@jeffsawatzky the primary issue here is that field rules right now (intentionally) don't carry a reference to the parent message or sibling fields. This would need to be on the message level, mapping a mask to its target field. There's prior art for this pattern in the synthetic message.one_of rules.
DolceTriade commentedon May 27, 2026
I see. It would be nice to support selective validation (which i don't think would be different between different implementations of protovalidate...)
jeffsawatzky commentedon May 27, 2026
@DolceTriade woild something like what is described in #486 be useful? Having validations run only under certain contexts and those contexts can be specified in the root request/response message options?
rodaine commentedon May 28, 2026
Yep! That's the intent of this issue 😁 It's not just that the implementations have to support it; the protos (schema and/or data) themselves have to carry this information.
DolceTriade commentedon May 30, 2026
A non-declarative variant would be better to be more universally useful. For example, a context needs to be declared ahead of time whereas a field mask could allow fields in a patch request to be skipped entirely (cuz they're empty and not meant to be modified).
our use cases are very similar.