-
-
Notifications
You must be signed in to change notification settings - Fork 294
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
Fixes for dynamic scope and keywords #1041
Conversation
The path from this root schema to any particular keyword (that | ||
includes any "$ref" and "$dynamicRef" keywords that may have | ||
been resolved) is considered the keyword's "validation path." | ||
<cref> |
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 removed the cref here because I'm mostly sure it's just left over from the recursive keywords and doesn't apply any more. At the least, it's not correct that, $dyanmicAnchor is only allowed in the root schema. If someone thinks there's still some value in this cref, let me know and we'll try to correct it instead of delete it.
<cref> | ||
Requiring both the initial and final URI fragment to be defined | ||
by "$dynamicAnchor" ensures that the more common "$anchor" | ||
never unexpectedly changes the dynamic resolution process | ||
due to a naming conflict across resources. Users of | ||
"$dynamicAnchor" are expected to be aware of the possibility | ||
of such name collisions, while users of "$anchor" are not. | ||
</cref> |
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 removed this cref because it appears to be wrong. There's no way that an $anchor
can change dynamic scope resolution and even if it could, it's not clear how bookending could possibly solve that problem. If anyone knows what this means, please share and I'll put it back in.
Many thanks! |
How is it not true? The dynamic path is affected by the instance data because it can change the path through applicator keywords, which can change which references are followed or not followed. Example:
We cannot know the dynamic scope in a particular subschema without knowing how we got there, and how we got there depends on the evaluation result of the if/then/else applicator keywords. |
@karenetheridge If I'm wrong about this, it should be relatively easy to prove because it would mean my implementation has a bug. I resolve all URLs during the compile step before it has an instance. All we need is one example we can run on https://json-schema.hyperjump.io and get instant feedback. We can then use that example in the test suite as well. |
What $schema should it have? |
Sorry, I forgot to mention, use |
I implemented this first with recursiveRef, so I could test it locally (if others make affirmative noises I can add this to the 2019-09 test suite): schema:
passing data: produces result:
failing data: produces results:
I believe the equivalent schema, in draft2020-12, would be:
Before runtime, we cannot know the destination of the $dynamicRef because we do not know the path by which we got here, and anywhere in the higher scope could have declared a $dynamicAnchor -- and indeed both of the possible source paths ( https://json-schema.hyperjump.io/ thinks both of those data instances pass against the schema. I believe the second one should not (similarly to the 2019-09 version of the schema with $recursiveRef). |
Well, this is embarrassing, but it seems you found a bug not related to this discussion. https://json-schema.hyperjump.io doesn't give the right result for this schema either and there are no branches. {
"$id": "main.json",
"$defs": {
"inner": {
"$id": "inner.json",
"$dynamicAnchor": "node",
"title": "inner",
"additionalProperties": {
"$dynamicRef": "#node"
}
}
},
"allOf": [{
"title": "integer node",
"$id": "integerNode.json",
"$dynamicAnchor": "node",
"type": [ "object", "integer" ],
"$ref": "main.json#/$defs/inner"
}]
} I think the problem is with the mutually recursive references. I'm working to understand the problem better so I can either fix it quickly or find a workaround so we can see if the schema exposes a bug related to this discussion. |
@karenetheridge, I found the bug and I've confirmed that your schema does trip up my validator. Let's definitely add it to the test suite. |
So does this mean @karenetheridge is correct and the contents of this PR is wrong in relation to...
? |
ok, test case added! json-schema-org/JSON-Schema-Test-Suite#450 |
Yes, @Relequestual, that means I was wrong. I'll submit up a PR reverting the relevant changes. |
Thanks! =] |
This PR fixes errors in the spec for the dynamic and keywords and dynamic scope. The spec describes dynamic scope to only be resolvable when processing an instance. This wasn't true for the recursive keywords, and it isn't true for the dynamic keywords either. You need to know all the schemas and how they reference each other, but you don't need an instance. The vast majority of these changes cover that issue. The rest fixes minor typos and such.