-
Notifications
You must be signed in to change notification settings - Fork 107
fix allOf of oneOfs by introducing cartesian product #982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PolyProgrammist
wants to merge
3
commits into
oxidecomputer:main
Choose a base branch
from
PolyProgrammist:allOfofOneOfs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems possible for there to be literal or effective duplicates in this list.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see there may be oneOf: [A, B] and oneOf: [C, D]
And maybe something like oneOf[{}, {type: string}] and oneOf[{type:string}, {type:string}] where for all of them the result would be {type:string}.
Do you think comparing like that is enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not quite right:
oneOf[{type: string}, {type: string}]would be equivalent to the schemafalse... and so therefore would the outerallOf.but perhaps something like this?
{ "allOf": [ { "oneOf": [ { "type": "object", "required": ["x"], "properties": { "x": { "const": 1 } } }, { "type": "object", "required": ["x"], "properties": { "x": { "const": 2 } } } ] }, { "oneOf": [ { "type": "object", "required": ["y"], "properties": { "y": { "const": 3 } } }, { "type": "object", "required": ["x", "y"], "properties": { "x": { "const": 1 }, "y": { "const": 3 } } } ] } ] }I think the expansion you have in mind is more of less
{ "oneOf": [ { "allOf": [ { "type": "object", "required": ["x"], "properties": { "x": { "const": 1 } } }, { "type": "object", "required": ["y"], "properties": { "y": { "const": 3 } } } ] }, { "allOf": [ { "type": "object", "required": ["x"], "properties": { "x": { "const": 1 } } }, { "type": "object", "required": ["x", "y"], "properties": { "x": { "const": 1 }, "y": { "const": 3 } } } ] }, { "allOf": [ { "type": "object", "required": ["x"], "properties": { "x": { "const": 2 } } }, { "type": "object", "required": ["y"], "properties": { "y": { "const": 3 } } } ] }, { "allOf": [ { "type": "object", "required": ["x"], "properties": { "x": { "const": 2 } } }, { "type": "object", "required": ["x", "y"], "properties": { "x": { "const": 1 }, "y": { "const": 3 } } } ] } ] }And if we further reduce that we get
{ "oneOf": [ { "type": "object", "required": ["x", "y"], "properties": { "x": { "const": 1 }, "y": { "const": 3 } } }, { "type": "object", "required": ["x", "y"], "properties": { "x": { "const": 1 }, "y": { "const": 3 } } }, { "type": "object", "required": ["x", "y"], "properties": { "x": { "const": 2 }, "y": { "const": 3 } } }, false ] }The first 2 are identical; the last one is unsatisfiable. I think we need check for exclusivity--perhaps by seeing if the A ∪ ⌐B is empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually that's not quite right and now I'm deeply uncertain about whether there might be duplicates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I've had time to sleep on it:
If we have two sets of schemas, each known to consist of mutually exclusive schemas, then the cartesian product of those two sets must also be pairwise mutually exclusive. Why? A value that was valid for multiple schemas of the cartesian product would necessarily be valid for multiple schemas in (at least) one of the input schema sets (which would invalidate the initial premise).
However! I don't believe that typify currently ensures that
oneOfs are mutually exclusive. Part of the (in-progress) typify rewrite is to ensure that that mutual exclusivity. For example, with an input like:{ "oneOf": [ { "type": "object", "required": ["y"], "properties": { "y": { "const": 3 } } }, { "type": "object", "required": ["x", "y"], "properties": { "x": { "const": 1 }, "y": { "const": 3 } } } ] }We would produce a type like this:
Which is all to say: this PR is wrong, but it's no more wrong that what we currently have and, indeed, it's quite a bit better in all but the most esoteric cases.