[Feature Request] Add an option to set your own descriptor resolver
Feature description:
Similar to WithExtensionTypeResolver, it would be helpful to allow adding your own WithDescriptorResolver option.
Problem it solves or use case:
It will allow using dynamic schema registries outside of global protoregistry.Files
Proposed implementation or solution:
Something like:
func WithDescriptors(resolver ...protodesc.Resolver) ValidatorOption {
return func(cfg *config) {
cfg.descResolver = resolver
}
}
@rauanmayemir, the only way a descriptor resolver might be used is for CEL expressions that operate on google.protobuf.Any messages. Is that the issue you are encountering? If not, please describe the issue you are encountering with dynamic schemas, in case you're running into something else (like a bug).
@jhump No, there was no issue. Apparently, I didn't even have to add my regular message descriptors because the input message already has a ProtoReflect() with all the information, is that correct?
That's correct. A descriptor resolver is generally unnecessary since the message being validated knows its own descriptor (and all fields therein know their message types, too).
The only time you would run into trouble is when using google.protobuf.Any messages, where the contained message payload is a dynamic message (i.e. not known to the program via protoregistry.GlobalFiles). In this case, there are some operations in CEL expressions that will try to unpack the Any message, which would fail in this case. This is the only case where you would benefit from an option like this, to provide additional dynamic message types to the CEL interpreter so it knows how to unpack them.
I think there is no issue here as it should indeed work just fine to use different descriptor registries with protovalidate. Please feel free to open another issue or comment here if there are any problems still.
There is no issue, but the feature request was still valid for when you want to add extra descriptors for Any messages.
Ah, I see. Re-opening for now.