Skip to content

fix: anyOf compare alternatives #1037

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

Conversation

p-spacek
Copy link
Contributor

What does this PR do?

improve compare mechanism that should choose correct schema alternatives

What issues does this PR fix or reference?

fixes this issue #684
replces this PR #759

Is it tested? How?

added tests

@coveralls
Copy link

coveralls commented Mar 12, 2025

Coverage Status

coverage: 84.132% (+0.06%) from 84.075%
when pulling 12e9e87 on jigx-com:fix/anyOf-compare-alternatives
into 4602af7 on redhat-developer:main.

@@ -866,7 +872,7 @@ function validate(
const val = getNodeValue(node);
let enumValueMatch = false;
for (const e of schema.enum) {
if (equals(val, e) || (callFromAutoComplete && isString(val) && isString(e) && val && e.startsWith(val))) {
if (equals(val, e) || isAutoCompleteEqualMaybe(callFromAutoComplete, node, val, e)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null value is a good match in auto-completion

} else if (compareResult === 0) {
} else if (
compareResult === 0 ||
((node.value === null || node.type === 'null') && node.length === 0) // node with no value can match any schema potentially
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null yaml value is a good match for sub-schemas, similar to isAutoCompleteEqualMaybe for const and enums

if (
!maxOneMatch &&
!subValidationResult.hasProblems() &&
(!bestMatch.validationResult.hasProblems() || callFromAutoComplete)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(!bestMatch.validationResult.hasProblems() || callFromAutoComplete) didn't solve the previous problem properly
problem was when the order of the subschemas in anyOf changed.
this previous fix allows 'issues' only on the previous bestMatch

@brian-mulier-p
Copy link

Bump, I came across the same issue, I made a PR that also adds some gracefulMatching behaviour (naming is hard...) #1048
I parameterized it as it's probably a breaking change but to me that's a more natural behaviour

Copy link
Contributor

@msivasubramaniaan msivasubramaniaan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@msivasubramaniaan
Copy link
Contributor

@p-spacek Please resolve the conflicts

@p-spacek
Copy link
Contributor Author

@msivasubramaniaan thanks for review
done

Copy link
Contributor

@msivasubramaniaan msivasubramaniaan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@msivasubramaniaan msivasubramaniaan merged commit 93c76b5 into redhat-developer:main Apr 25, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants