Repository navigation
Fix match('one') reporting any when exclusive object alternatives overlap - #3155
Closed
dyk1454683243-sudo wants to merge 3 commits into
Closed
dyk1454683243-sudo wants to merge 3 commits into
dyk1454683243-sudo wants to merge 3 commits into
Conversation
When every failed alternative only rejected keys declared on the other alternatives, report alternatives.one instead of alternatives.any. Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
Unknown-key failures can hide later object rules when abortEarly is true. Strip sibling keys and revalidate so overlap detection does not depend on that preference. Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
Author
|
Withdrawing this PR while I clean up a high-volume open-PR backlog. Sorry for the noise — happy to come back later with a focused change if useful. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #3058.
alternatives.match('one')already reportsalternatives.onewhen more than one alternative validates successfully. Exclusive object alternatives such as{ a }vs{ b }plus shared keys do not take that path: each object fails only because the other alternative's keys are unknown, so Joi previously reportedalternatives.any("does not match any of the allowed types").When failed alternatives only differ by keys declared on other alternatives, those sibling keys are stripped and each candidate is revalidated. If more than one then matches, report
alternatives.oneinstead ofalternatives.any.Revalidation is required because
abortEarlycan hide later object rules (for example.and()) behind anobject.unknownerror.Single-alternative matches, shared-only values, unrelated unknown keys, and real field errors are unchanged.