Skip to content

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

Merged
Martin Aeschlimann (aeschli) merged 3 commits into
microsoft:mainfrom
ATKasem:fix/anyof-deprecated-match
Aug 23, 2026
Merged

Fix: select matching deprecated alternative in anyOf/oneOf (#304)#343
Martin Aeschlimann (aeschli) merged 3 commits into
microsoft:mainfrom
ATKasem:fix/anyof-deprecated-match

Conversation

@ATKasem

Copy link
Copy Markdown
Contributor

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
Aaron Thomas (ATKasem) force-pushed the fix/anyof-deprecated-match branch from ef9972b to 9f5eee1 Compare July 17, 2026 19:43
@ATKasem

Copy link
Copy Markdown
Contributor Author

Martin Aeschlimann (@aeschli) — gentle ping, open since July 17.

Small fix (+36/-1): in an anyOf/oneOf, a branch that matches the value but is marked deprecated is treated as a non-match, so a non-matching sibling gets reported instead. With the schema from #304, "text value" reports Value is not accepted. Valid values: "unused literal" rather than Value is deprecated. The cause is hasProblems() counting the deprecation notice like a validation error when selecting the best alternative.

Let me know if you'd prefer the deprecation notice tracked separately from problems rather than filtered at the comparison site — happy to restructure.

@aeschli

Copy link
Copy Markdown
Collaborator

Thanks Aaron Thomas (@ATKasem) !

@aeschli
Martin Aeschlimann (aeschli) merged commit 815b238 into microsoft:main Aug 23, 2026
3 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.

Deprecated matching string pattern inside anyOf is not considered a match

4 participants