-
-
Notifications
You must be signed in to change notification settings - Fork 216
test for confusing not-identifiers in enums #471
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
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.
Looking at the $anchor
tests, I don't think the second test has any chance of catching bugs. It doesn't match the enum
, so it will always fail validation (pass the test) even if the implementation interprets the $anchor
as a real identifier.
My implementation works by removing $anchor
keywords from the schema when it per-processes the schema and storing them separately. So, a test that has a chance of tripping up an implementation like mine would be { "type": "null" }
. It would match the enum
and then where #faux_anchor
resolves would determine whether the test passes or not.
Another thing to consider is that my implementation processes $anchors
in the order they appear in the schema, so the real anchor would overwrite the not-an-anchor and the test would pass. Although the ordering of properties in an array is undefined, I think we will be more likely to catch bugs if we order the $defs
in a way that is most likely to make the not-an-anchor be chosen over the real anchor. By a large margin, the most common ordering to expect from parsers is to preserve the ordering from the schema. Therefore, I suggest reordering to $defs
. It won't catch all problems, but I think that configuration would be the most likely to catch bugs.
I think the same applies to the |
I'll take a look at rejigging it to make it more likely to be trippable.
I was thinking of implementations that worked the other way -- of recording the first anchor it saw, rather than the last. Perhaps there should be a second test with the reverse order, so both implementation choices have a chance of being caught? |
5c92ccf
to
016b11f
Compare
I made the following changes:
|
195c9d0
to
813bf4e
Compare
tests/draft2020-12/id.json
Outdated
{ | ||
"description": "in implementations that strip $id, this may match either of the $defs", | ||
"data": { | ||
"type": "null" | ||
}, | ||
"valid": false | ||
}, |
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.
You can't just strip out $id
s like you can with $anchor
s, so I don't see this catching bugs the same way it would with $anchor
. What I do is replace the entire schema with an object that represents a reference and is not expressible in JSON. Because it's not expressible in JSON, we can't create a test that would catch that. I think we can drop this test for the "id.json" tests and just keep them for "anchor.json" tests.
{ | |
"description": "in implementations that strip $id, this may match either of the $defs", | |
"data": { | |
"type": "null" | |
}, | |
"valid": false | |
}, |
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.
okay, I removed those tests for id/$id.
813bf4e
to
5f1f16b
Compare
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.
lgtm. 👍
A naive implementation would add all $id or $anchors to its list of known resources, without checking if they are actually in subschemas or the value of a keyword like enum, const or examples.
5f1f16b
to
9f97865
Compare
rebased and merged! |
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.
Found running against my lib.
"id_in_enum": { | ||
"enum": [ | ||
{ | ||
"id": "https://localhost:1234/my_identifier.json", |
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.
Are these suppose to be $id
? id
was replaced by $id
in draft 6.
"id_in_enum": { | ||
"enum": [ | ||
{ | ||
"id": "https://localhost:1234/my_identifier.json", |
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.
Here, too.
It looks like we were too permissive in: #71 This addresses issues from: - json-schema-org/JSON-Schema-Test-Suite#471 - json-schema-org/JSON-Schema-Test-Suite#484 The first issue is more important, I think. We were resolving `$id` in keywords like `enum` and `const`, which is unexpected since those values are literal. The second issue is a little trickier. It's possible people are using non-standard keys to store reference schemas, which will cause issues since this only looks in `definitions` now.
It looks like we were too permissive in: #71 This addresses issues from: - json-schema-org/JSON-Schema-Test-Suite#471 - json-schema-org/JSON-Schema-Test-Suite#484 The first issue is more important, I think. We were resolving `$id` in keywords like `enum` and `const`, which is unexpected since those values are literal. The second issue is a little trickier. It's possible people are using non-standard keys to store reference schemas, which will cause issues since this only looks in `definitions` now.
It looks like we were too permissive in: #71 This addresses issues from: - json-schema-org/JSON-Schema-Test-Suite#471 - json-schema-org/JSON-Schema-Test-Suite#484 The first issue is more important, I think. We were resolving `$id` in keywords like `enum` and `const`, which is unexpected since those values are literal. The second issue is a little trickier. It's possible people are using non-standard keys to store reference schemas, which will cause issues since this only looks in `definitions` now.
It looks like we were too permissive in: #71 This addresses issues from: - json-schema-org/JSON-Schema-Test-Suite#471 - json-schema-org/JSON-Schema-Test-Suite#484 The first issue is more important, I think. We were resolving `$id` in keywords like `enum` and `const`, which is unexpected since those values are literal. The second issue is a little trickier. It's possible people are using non-standard keys to store reference schemas, which will cause issues since this only looks in `definitions` now.
It looks like we were too permissive in: #71 This addresses issues from: - json-schema-org/JSON-Schema-Test-Suite#471 - json-schema-org/JSON-Schema-Test-Suite#484 The first issue is more important, I think. We were resolving `$id` in keywords like `enum` and `const`, which is unexpected since those values are literal. The second issue is a little trickier. It's possible people are using non-standard keys to store reference schemas, which will cause issues since this only looks in `definitions` now.
It looks like we were too permissive in: #71 This addresses issues from: - json-schema-org/JSON-Schema-Test-Suite#471 - json-schema-org/JSON-Schema-Test-Suite#484 The first issue is more important, I think. We were resolving `$id` in keywords like `enum` and `const`, which is unexpected since those values are literal. The second issue is a little trickier. It's possible people are using non-standard keys to store reference schemas, which will cause issues since this only looks in `definitions` now.
It looks like we were too permissive in: #71 This addresses issues from: - json-schema-org/JSON-Schema-Test-Suite#471 - json-schema-org/JSON-Schema-Test-Suite#484 The first issue is more important, I think. We were resolving `$id` in keywords like `enum` and `const`, which is unexpected since those values are literal. The second issue is a little trickier. It's possible people are using non-standard keys to store reference schemas, which will cause issues since this only looks in `definitions` now.
It looks like we were too permissive in: #71 This addresses issues from: - json-schema-org/JSON-Schema-Test-Suite#471 - json-schema-org/JSON-Schema-Test-Suite#484 The first issue is more important, I think. We were resolving `$id` in keywords like `enum` and `const`, which is unexpected since those values are literal. The second issue is a little trickier. It's possible people are using non-standard keys to store reference schemas, which will cause issues since this only looks in `definitions` now.
A naive implementation would add all $id or $anchors to its list of known
resources, without checking if they are actually in subschemas or the value of
a keyword like enum, const or examples.