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

Add access to custom options (of host messages). #203

Open
yangzh opened this issue Apr 25, 2024 · 2 comments
Open

Add access to custom options (of host messages). #203

yangzh opened this issue Apr 25, 2024 · 2 comments
Labels
Feature New feature or request

Comments

@yangzh
Copy link

yangzh commented Apr 25, 2024

Feature description:
Thanks for this great idea and great library!
I would like to see the custom option (of host messages) to accessible by protovalidate / CEL.

For example, if I have a .proto file:

extend google.protobuf.EnumValueOptions {
string alt_name = 10000;
}

enum PartOfSpeech {
UNKNOWN = 0;
NOUN = 1 [(alt_name) = "noun"];
VERB = 2 [(alt_name) = "verb"];
etc.
}

message Token {
string pos = 1 [(buf.protovalidate).string = {
in_enum_values: "alt_name" }];
}

so that the validation rule basically limit the value of "pos" to be one of "noun", "verb", etc. (as long as we supply alt_name for each enum value.

This particular case might be trickier (than what's required by this feature), it will have to somehow aggregate the alt_name from all enum values, and use that set as the target for "in" operation: you get the idea.

But in general, I want to access to the custom option as supplied by original protobuf authors, in protovalidate, or more generally in CEL.

Proposed implementation or solution:
I guess beside binding "this" into the evaluation context, you need to somehow make the custom options (of the host message) accessible from inside the evaluation context as well.

Contribution:
I don't have time to implement, but I'm happy to elaborate and help testing the feature.

@yangzh yangzh added the Feature New feature or request label Apr 25, 2024
@rodaine rodaine transferred this issue from bufbuild/protovalidate-go Apr 25, 2024
@rodaine
Copy link
Member

rodaine commented Jun 25, 2024

Hey @yangzh! Thanks for the thoughtful question! Out of the box, CEL does not have a lot of reflection support to get information off the types themselves. Enums especially are erased to just their int32 value. Protovalidate could potentially expose more reflection information in the CEL environment in the future, but for now we are keeping the rules scoped to the element (message or oneof or field) they're attached to.

@kevin-break
Copy link

Thanks for the thoughts and clarifications!

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

3 participants