Add standalone Subsumption utility for anyOf/oneOf error collapsing.#211
Add standalone Subsumption utility for anyOf/oneOf error collapsing.#211srivastava-diya wants to merge 4 commits intohyperjump-io:mainfrom
Conversation
jdesrosiers
left a comment
There was a problem hiding this comment.
I think the approach here needs to be a little closer to real usage. I see a couple of places where the NormalizedOutput used for input isn't quite right and it could affect the implementation. We don't want to put in a ton of work and find that it doesn't work because we tested on bad input.
See if you can generate the NormalizedOutput from a schema to be sure you're working with actual results. Also, try to pass the AST instead of the getValue function. That way we can use it as is when we're ready to use it instead of having to refactor it.
| "": { | ||
| "https://json-schema.org/keyword/type": { "/type": false }, | ||
| "https://json-schema.org/keyword/minLength": { "/minLength": false } | ||
| } |
There was a problem hiding this comment.
It's not possible for type and minLength to both be false. If the value is not a string, then minLength is going to be true.
|
I get your point. I’ll adjust things accordingly. Thanks. |
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