Skip to content

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

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

Add standalone Subsumption utility for anyOf/oneOf error collapsing.#211
srivastava-diya wants to merge 4 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.

Copy link
Copy Markdown
Collaborator

@jdesrosiers jdesrosiers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/subsumption.test.js
Comment on lines +17 to +20
"": {
"https://json-schema.org/keyword/type": { "/type": false },
"https://json-schema.org/keyword/minLength": { "/minLength": false }
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@srivastava-diya
Copy link
Copy Markdown
Contributor Author

I get your point. I’ll adjust things accordingly. Thanks.

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.

2 participants