Comments (1)
Hi, @rjanjyam! Sorry for the delay in response. I'm having trouble reproducing what you're seeing, but perhaps I'm not quite understanding.
Using a similar message as yours:
Example message
message FieldMaskGate {
Obj obj = 1;
google.protobuf.FieldMask field_mask = 2;
message Obj {
string code = 1;
}
option (buf.validate.message).cel = {
id: "obj.code",
message: "code should be present",
expression: "this.field_mask.paths.exists(p, p == 'obj.code') ? this.obj.code.size() > 0 : true";
};
}
All the following test cases pass:
Tests
func TestValidator_FieldMaskGate(t *testing.T) {
t.Parallel()
val, err := New()
require.NoError(t, err)
msg := &pb.FieldMaskGate{
Obj: &pb.FieldMaskGate_Obj{Code: "foo"},
}
err = val.Validate(msg)
require.NoError(t, err)
msg.FieldMask, err = fieldmaskpb.New(msg, "obj.code")
require.NoError(t, err)
err = val.Validate(msg)
require.NoError(t, err)
msg.Obj.Code = ""
err = val.Validate(msg)
valErr := &ValidationError{}
require.ErrorAs(t, err, &valErr)
assert.Equal(t, "obj.code", valErr.Violations[0].GetConstraintId())
msg.Obj = nil
err = val.Validate(msg)
require.ErrorAs(t, err, &valErr)
assert.Equal(t, "obj.code", valErr.Violations[0].GetConstraintId())
msg.FieldMask.Reset()
err = val.Validate(msg)
require.NoError(t, err)
}
If what you're looking for instead is to have protovalidate use a FieldMask to decide which fields to perform validation on generally, that feature does not exist. If you'd like, feel free to open a feature request issue over on the protovalidate repo for further discussion. There's a somewhat adjacent issue that covers skipping validation on certain fields.
from protovalidate-go.
Related Issues (20)
- gen proto issue HOT 1
- The validate returns an error object. How do I get the correct field name and the corresponding check message HOT 2
- [BUG] Non-deterministic error values when using `string.uuid` HOT 4
- [BUG] Some red wavy line about importing when VSCode/Goland displaying generated code HOT 3
- Vulnerability GO-2024-2609 HOT 1
- [BUG] resolveDeprecatedIndex() isn't functioning. HOT 3
- [BUG] Enum-related validation error messages contain numbers instead of value names HOT 1
- [Feature Request] Make dependency on PGV opt-in
- [BUG] string min_len and ignore_empty HOT 1
- [BUG] Recursive validation skipped depending on field order HOT 1
- Part of the validation code is not generated HOT 2
- [Question] How to use protovalidate-go in github-actions HOT 2
- Document recommendation for instantiating/managing validator instances HOT 2
- [Feature Request] Allow extending default cel.Env created by protovalidate.New HOT 4
- Fails to validate a simple message HOT 2
- [BUG] error evaluating repeated.unique: internal error: runtime error: invalid memory address or nil pointer dereference HOT 1
- [BUG] Cannot build with Bzlmod HOT 13
- [Question] What's the correct way to write cel expressions for validating a single item in a repeated field? HOT 1
- [BUG] *.pb.validate.go Validate AND ValidateAll cannot use. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protovalidate-go.