Add standalone Subsumption utility for anyOf/oneOf error collapsing.#211
Draft
srivastava-diya wants to merge 3 commits intohyperjump-io:mainfrom
Draft
Add standalone Subsumption utility for anyOf/oneOf error collapsing.#211srivastava-diya wants to merge 3 commits intohyperjump-io:mainfrom
srivastava-diya wants to merge 3 commits intohyperjump-io:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.isSubsumedaccepts agetValuecallback 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