Skip to content

fix: anyOf compare alternatives#32

Open
p-spacek wants to merge 10 commits into
jigxfrom
fix/anyOf-compare-alternatives
Open

fix: anyOf compare alternatives#32
p-spacek wants to merge 10 commits into
jigxfrom
fix/anyOf-compare-alternatives

Conversation

@p-spacek
Copy link
Copy Markdown
Collaborator

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 redhat-developer#684
replces this PR redhat-developer#759

Is it tested? How?

added tests

@p-spacek p-spacek changed the title fix: anyOf compare alternatives fix: anyOf compare alternatives [create PR into redhat after test] Oct 24, 2024
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
Copy Markdown
Collaborator 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
Copy Markdown
Collaborator 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
Copy Markdown
Collaborator 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

return bestMatch;
}

function mergeValidationMatches(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

only refactor - move to separate function, no functional change

18,
DiagnosticSeverity.Error,
'yaml-schema: Package',
'yaml-schema: Composer Package',
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

test fix

msivasubramaniaan and others added 4 commits March 11, 2025 12:26
Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
The import from `prettier` includes support for all languages supported
by Prettier. The `prettier/standalone` import only includes the core.
The `prettier` export also points to `prettier/standalone` for the
`browser` export condition.

This means that with this change `yaml-language-server` has to load less
code, leading to faster startup time. And depending on configuration, it
may lead to smaller bundle sizes.

Co-authored-by: Muthurajan Sivasubramanian <93245779+msivasubramaniaan@users.noreply.github.com>
* add function to calculate remainder for floats correctly without rounding errors and fix checking if a number is a multipleOf for floats

* fix formatting

* add unit test

* rm copyright

---------

Co-authored-by: Steinke, Rico <Rico.Steinke@vector.com>
Co-authored-by: Muthurajan Sivasubramanian <93245779+msivasubramaniaan@users.noreply.github.com>
@p-spacek p-spacek changed the base branch from jigx to main March 12, 2025 13:35
@p-spacek p-spacek changed the base branch from main to jigx March 12, 2025 13:35
@p-spacek p-spacek changed the title fix: anyOf compare alternatives [create PR into redhat after test] fix: anyOf compare alternatives Mar 12, 2025
p-spacek and others added 5 commits March 12, 2025 14:47
* added support for enum yes and no

Signed-off-by: msivasubramaniaan <msivasub@redhat.com>

* added support for enum yes and no

Signed-off-by: msivasubramaniaan <msivasub@redhat.com>

* added test case

Signed-off-by: msivasubramaniaan <msivasub@redhat.com>

* Quote were appended based on the yaml settings

---------

Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
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