Skip to content

Add standalone Subsumption utility for anyOf/oneOf error collapsing.#211

Draft
srivastava-diya wants to merge 3 commits intohyperjump-io:mainfrom
srivastava-diya:main
Draft

Add standalone Subsumption utility for anyOf/oneOf error collapsing.#211
srivastava-diya wants to merge 3 commits intohyperjump-io:mainfrom
srivastava-diya:main

Conversation

@srivastava-diya
Copy link
Copy Markdown
Contributor

Description

Discussed : #173

This PR introduces a standalone isSubsumed(altA, altB, getValue) utility in src/subsumption.js as discussed in #173 . it is aimed at collapsing redundant error alternatives in anyOf and oneOf handlers, without touching any existing handlers yet.

Approach

isSubsumed(altA, altB, getValue) takes two NormalizedOutput alternatives and returns true if altA algebraically subsumes altB meaning altA's failure set is a superset of altB's, making altB redundant, or altA is more general than altB.

isSubsumed accepts a getValue callback for schema value resolution, keeping it decoupled from any specific resolver architecture. It will integrate cleanly once the synchronous AST-based resolver from #204 lands, no changes to subsumption.js is required at that point.

Rules implemented:

  • Type hierarchies like type["string", "number"] subsumes type: "string"

  • Implicit type subsumption , type: string subsumes minLength/maxLength failures also type: number subsumes minimum/maximum/multipleOf, etc.

  • Enum/const : enum: ["a", "b"] subsumes enum: ["a"] and const: "a"

  • Boundary constraints like maxLength: 10 subsumes maxLength: 5, minLength: 1 subsumes minLength: 3 same logic for minimum, maximum, minItems, maxItems, minContains, maxContains, etc.

  • Nested applicators recursive support for anyOf/oneOf within anyOf/oneOf

Files Changed

  • src/subsumption.js : the utility (not wired into any handlers yet)

  • src/subsumption.test.js : isolated unit tests , covering all examples from the issue discussion.

Not included in this draft

  • Wiring into anyOf/oneOf handlers intentionally not done yet.

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.

1 participant