Jrinehart/tcn 2782 protovalidate java custom rules cannot use repeated nested #246
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
protovalidate-javacannot use a CEL expression wherethisrepresents a repeated message.EvaluatorBuilder'sprocessFieldExpressionis currently directly usingDecls.newObjectType()to create an object type based on the name of the message type in the field instead of honoring whether or not the field is repeated and returning aDecls.newListType().provalidaterecently added conformance tests that illustrate this problem.To fix this, this PR:
.protothat demonstrate the issue.EvaluatorBuilder'sprocessFieldExpressionto delegate the determination of the CEL type toDescriptorMappings.getCELType(), which uses theFieldDescriptorto determine the correct type to return. This method requires passing aforItemsflag stating if the type returned should be the list (or map) type for a field or the type of the items in the collection. Using the newnestedRuleproperty's state provides the value of this flag, similar to how it's used inprocessStandardConstraintsto pass theforItemsflag toconstraintCache.compile().valueEvaluator.getNestedRule() == nullwas used to determine behavior, I moved this comparison into ahasNestedRule()method onValueEvaluator, using conformance state to check regression.Conformance notes:
This PR passes conformance in
protovalidate-java.It has been tested against the conformance suite at the current head of
protovalidate(which now includes the standard library, so there are many new failures).Before changes in this PR, there were 137 failures. After, there were 135:
Running
field_expression/repeated/messageshows that the two conformance tests fixed were for the desired issue: