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

[Question]: Validate partial message, e.g. only fields specified via field mask #299

Closed
czabaj opened this issue Jan 30, 2025 · 1 comment
Labels
Duplicate This issue or pull request already exists Feature New feature or request

Comments

@czabaj
Copy link

czabaj commented Jan 30, 2025

When I use this library to validate an update request message, the client can set only some fields on the message and specify via an updateMask which fields they are. However, the protovalidate checks the whole message and reports validation errors for missing fields, that were omitted intentionally. How to approach this scenario?

One way is to iterate over all validation error violations and filter out violations on unaffected fields, i.e., those not in the updateMask.

Another way might be to hook into the Validate logic with a predicate function that would allow conditionally skip validation of certain fields. I was looking into the code and even if I would create a new instance of the Validate function for the update request purpose, there is no option that would allow me to hook into the validation process like I want, or is there?

Anyway, using updateMask for partial update request messages should be common. Is there a paved way to deal with such a case?

@rodaine rodaine transferred this issue from bufbuild/protovalidate-go Jan 30, 2025
@rodaine
Copy link
Member

rodaine commented Jan 30, 2025

Hey, @czabaj! Moved this to the main protovalidate repo since it's a global concern and not specific to the Go implementation. There's been some previous discussion on this topic if you'd like to comment on that existing issue.

@rodaine rodaine closed this as completed Jan 30, 2025
@rodaine rodaine added Duplicate This issue or pull request already exists Feature New feature or request labels Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate This issue or pull request already exists Feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants