-
-
Notifications
You must be signed in to change notification settings - Fork 216
No other keywords allowed beside "$ref" #197
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
Conversation
Oops, one of those was actually testing that the adjacent keyword was organizing! That's what I get for not reading descriptions. Will update momentarily. |
The spec for $ref, whether in its own JSON Reference spec or as part of the JSON Schema Core spec, states that keywords adjacent to "$ref" MUST be ignored. Therefore these tests were invalid, even though the intent was clear to most readers. The correct way to combine "$ref"s is with "allOf". These tests have probably generally worked b/c "definitions" is usually processed up front.
b110f8d
to
c911798
Compare
Just looking at a glance, the way it is now is so wrong it makes me wonder if it's that way intentionally. |
@awwright yeah I was puzzled. I even filed #198 about whether we should be testing to catch this problem (if it is a problem) of Now that we have the assertion vs annotation concept, we could change the |
Fwiw we have a use case where we use Example: {
"Foo": {
"$id": "#Foo",
"$ref": "#GenericObject"
},
"GenericObject": {
"$id": "#GenericObject",
...
}
} While this works with our validator (ajv) I wonder if this is future-proof — or is it still invalid usage of TIA |
@handrews Arguably, definitions is not a keyword. Even though it's reserved in meta-schema, it is just "a standardized location" in the JSON instance that exists and can be addressed unrelated to the position of $ref. There is no reason why these schemas should be invalid. I think we should really fix the spec to allow at least definitions and annotations together with $ref or better make $ref a normal validation keyword, rather than "fix" this test. As we've agreed that $ref is delegation rather than inclusion I see absolutely no reason to require ignoring anything in the same object. @inca it is future proof. Even if at some point ignoring definitions or $id alongside $ref will become the default behaviour (which I doubt), there will be an option to not ignore them. I also often use annotation keywords with $ref. |
Actually as I've worked out more of how the different keywords need to be treated, I see pros and cons to both. We will discuss it as part of the next draft, not here. As the spec currently stands, |
@inca based on the current and prior specifications, that behavior is incorrect. Again, this is a PR for the tests for the spec as written, and is not the place to debate changes to the spec. This topic should be addressed during draft-08 as it fits with the planned theme of that release (re-usability). |
@inca Having looked at this again (I'd forgotten exactly what this PR was doing already), this change will not impact your use of ajv in any way, nor will it cause ajv to start failing the test. The problem here is that a conforming implementation is allowed by the current spec to ignore the |
So yeah this one's definitely me, and was definitely "intentional" in that I've had people ask about it in the past and responded that my reading of the spec at the time was that this was fine and allowed :)! I'm happy to be overruled if others feel that isn't the case. But essentially my reasoning was that there's a difference between JSON Schema saying that Again though, happy to be convinced (or just defer) that the spec in fact doesn't allow this. |
@@ -125,7 +125,7 @@ | |||
"b": {"$ref": "#/definitions/a"}, | |||
"c": {"$ref": "#/definitions/b"} | |||
}, | |||
"$ref": "#/definitions/c" | |||
"allOf": [{"$ref": "#/definitions/c"}] |
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.
IIRC allOf isn't in draft 3.
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.
... and that's another good reason to close this. I forgot that draft-03 had extends
or something.
Here's the last time this came up, with in fact both you @handrews and @awwright participating :) I'm guessing that there's a slight nuance here in that you're I guess talking specifically about how since But yeah, if there's consensus, happy to defer. |
@Julian given the history I think we should actually stick with what's there. Particularly given the work in draft-07 that starts classifying keywords into assertions and/or annotations, I was already intending to pursue that further in draft-08. And |
Sounds reasonable to me! |
The spec for $ref, whether in its own JSON Reference spec
or as part of the JSON Schema Core spec, states that keywords
adjacent to "$ref" MUST be ignored. Therefore these tests were
invalid, even though the intent was clear to most readers.
The correct way to combine "$ref"s is with "allOf".
This addresses #113.