Skip to content

Fix: select matching deprecated alternative in anyOf/oneOf (#304)#343

Open
ATKasem wants to merge 1 commit into
microsoft:mainfrom
ATKasem:fix/anyof-deprecated-match
Open

Fix: select matching deprecated alternative in anyOf/oneOf (#304)#343
ATKasem wants to merge 1 commit into
microsoft:mainfrom
ATKasem:fix/anyof-deprecated-match

Conversation

@ATKasem

@ATKasem ATKasem commented Jul 17, 2026

Copy link
Copy Markdown

Fixes #304.

In an anyOf/oneOf, a branch that actually matches the value but is marked deprecated was treated as a non-match, so a non-matching sibling got reported instead. With the schema from the issue, "text value" matches the pattern branch, but the hover/validation showed Value is not accepted. Valid values: "unused literal". instead of Value is deprecated.

The cause is that the deprecation notice is pushed as a problem, and ValidationResult.hasProblems() counted it like a validation error when selecting the best alternative. The const case in the issue only worked by luck — enumValueMatch is a separate tiebreaker in compare(); a pattern branch has nothing equivalent, so the deprecated-but-matching branch lost.

Fix: exclude deprecation problems from hasProblems() (they're advisory, severity: Warning, code: ErrorCode.Deprecated). Match selection now ignores them, while the deprecation diagnostic itself is still reported.

Added a test in parser.test.ts covering the issue's schema (matching value → Deprecated; non-matching value → the non-match error, unchanged). Full parser.test.js passes; jsonSchemaTestSuite failure count is unchanged from main on my machine (pre-existing URN cases).

A deprecation notice is advisory, not a validation failure, but
hasProblems() counted it like any other problem. So a deprecated branch
of an anyOf/oneOf that actually matched the value was treated as a
non-match, and a non-matching sibling was reported instead (e.g. a
const branch's 'Value is not accepted' message). The const case
happened to work only because enumValueMatch is a separate tiebreaker;
a pattern branch had no such luck.

Exclude deprecation problems from hasProblems() so match selection
ignores them. The deprecation diagnostic is still reported.

Fixes microsoft#304
@ATKasem
ATKasem force-pushed the fix/anyof-deprecated-match branch from ef9972b to 9f5eee1 Compare July 17, 2026 19:43
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.

Deprecated matching string pattern inside anyOf is not considered a match

1 participant