-
Notifications
You must be signed in to change notification settings - Fork 19
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
Allow passing a custom env for a validator #60
Conversation
So that the caller can include custom CEL functions
Hey @simon0191! We want to ensure that any rules present on a proto are portable to any consumer of that message. If custom CEL expressions are used, they would need to be present everywhere. This is why we currently don't allow access to the underlying CEL environment in Go or any other supported language and will likely keep it this way to preserve this invariant of the project. We are, however, exploring ways of making custom CEL expressions portable so that they can be applied easily to multiple fields without repeating the expression logic in N places. (The design there is not likely to be what it ultimately looks like, but feel free to give feedback there and stay tuned for feature updates!) |
I'm assuming your example above is just demonstrative, but just in case it's not, there is a standard constraint for UUIDs already. |
@rodaine we have a use case where we want to run certain validations only for Update calls in gRPC, but not for create calls. in this case, we cannot use standard constraints, because they would apply to all validations, as the field is present in both Update and Create calls. so we add this as CEL expression to UpdateXYZ request, so it only applies to the Update call. |
Ah, that makes sense! We still want to make sure that everything remains self-contained within the proto files + the agreed upon functions required by the protovalidate spec, so we still likely won't accept this change. If it's an option, another strategy you could use for this is have create/update request messages only include fields that can actually be mutated by the caller and only return the resource's message in responses. In my experience, this makes the semantics of the types clearer (there's no ambiguity about what a user can set vs what's computed by the server). That said, I can see a feature where instead of just |
This would be really useful.
Good alternative. We'll give this a try.
This also sounds like a good addition Thanks for the feedback @rodaine |
Quick and dirty PR aiming for some feedback :)
Allow passing a custom env for a validator so that the caller can include custom CEL functions.
For example: