-
-
Notifications
You must be signed in to change notification settings - Fork 217
Added test cases from Foundations of JSON Schema research paper #128
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
Added test cases from Foundations of JSON Schema research paper #128
Conversation
Fixes #115 |
Awesome! Very nice work, really appreciated, will definitely have a look. I'm sure it's in the paper which I haven't read, so forgive me for being lazy, but just in case -- what's the license on the tests from the paper? |
7d6cc6b
to
2541700
Compare
That's a good question - there is no mention of a license in the research paper or in the source code from in the appendix. For all of the tests I've treated them as a bug report and written the smallest, cleanest test that can reproduce the issue, rather than copying any of them directly into the test suite. |
As a note, I was in direct contact with several of the authors, and they wanted the tests to be integrated into the official test suite, but hadn't been able to put any time into it. |
@Relequestual @Julian Should we get formal approval from the authors? Is there any way to get one of them to 👍 this PR? Furthermore, @Julian can you confirm that I (and the paper's authors) have interpreted the spec correctly in the tests in this pull request? |
Incidentally, these tests will fail on a lot of implementations, as shown by the paper. I've also tested them on the implementation I contribute to (https://github.com/ruby-json-schema/json-schema/) and even the latest version does not pass all of them |
Somewhat worrying. I think @Julian will need to review for sure. As for contacting the paper authors, I'm not sure they use github... Would suggest emailing them. |
Dear All, this is Domagoj, one of the authors of the paper. Iain contacted me already, but just to restate what I said to him, we do maintain a webpage with more informal introduction to our formalization at http://cswr.github.io/JsonSchema/ in case you want to take a look. Over there, at http://cswr.github.io/JsonSchema/spec/why/, you can also find a bit more details on the tests you were discussing, and some thoughts on what we think was going on with the implementations. Best, |
Thanks @DomagojVrgoc ! |
"description": "property order of array of objects is ignored", | ||
"data": [{"foo": "bar", "bar": "foo"}, {"bar": "foo", "foo": "bar"}], | ||
"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.
This (and the two array tests below) are my interpretation of the test T1 in the paper, which test that schemas ignore the ordering of properties in JSON objects (according to the JSON rfc, objcet properties are not ordered) but respect the ordering of arrays (which are ordered - this wasn't in the paper but it seems important and closely related)
tests/draft4/ref.json
Outdated
} | ||
] | ||
}, | ||
{ |
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.
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.
Fwiw, the draft spec in the repository now specifically advises against schemas with this sort of infinite recursion. The update being released is intended to clarify and be reverse-compatible with draft-04.
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 agree with @awwright, I don't think it should be included.
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.
To clarify: The spec says that implementations MUST NOT fall into an infinite loop, but I don't know how we would test this correctly. We're testing that the schema is invalid, not for a particular valid/invalid result
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've removed the recursive tests now. It's good to know that the draft spec has been updated to include that.
tests/draft4/refRemote.json
Outdated
@@ -50,6 +50,26 @@ | |||
] | |||
}, | |||
{ | |||
"description": "ref with other properties", |
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.
This also tests T2 but for remote references
tests/draft4/ref.json
Outdated
@@ -141,6 +141,59 @@ | |||
] | |||
}, | |||
{ | |||
"description": "recursive refs", |
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.
This tests T4 from the paper, which checks that recsursive $refs are allowed. In this case I have made a schema that tests that implementations aren't thrown into an infinite loop, and can still validate parts of the schema which are not infinite.
tests/draft4/dependencies.json
Outdated
@@ -109,5 +109,43 @@ | |||
"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.
There was an additional test in the code in the appendix, which was not described in the paper, that tests what happens when dependences extend the schema with additonal rules. I think this isn't so much an edge case as something not covered by the test suite at present
I didn't include test T3 from the paper because I couldn't see a succinct way of doing it... The original test checks that a schema for an object ignores value-based properties (eg. multipleOf) I could add a test to every json schema property that refers to values and make sure they do nothing when used on an object or array? (eg minimum, maximum, multipleOf etc) but it would make for a lot of extra tests. I'd appreciate hearing opinions on the best course of action on that test. |
I can't claim I've fully read and understood all of the above, but I would think that a validator would check the schema is valid against the schema for schemas, if that makes sense. So a check would be done to make sure that properties such as minimum are only where they are relevant. |
So - rather than simply ignore those properties, we would fail validation because the schema itself is invalid? (Is that correct?) Is that how we handle invalid schemas in the test suite already? (Are there even any tests for schemas that are invalid?) |
If I were writing a library, that's how I'd do it. If you get part way through and find it's partially invalid, you've wasted time. If you take a softer approach, and ignore some parts based on some rules you've made up, then you're asking for unexpected behaviour. I would think it's better to let the user know they have done something wrong. I don't remember seeing any tests to confirm this behaviour, which is OK, as I also don't remember it being part of the spec. I feel it probably should / could be though. Maybe I should raise an issue to ask the question? In terms of my experience developing a collaboriative international API, I tend to read rules in a stricter, less forgiving manner than others. Make of that what you will. |
Yeah I think it's worth raising as another issue. FYI the ruby json-schema gem validates the user's schema against the appropriate meta schema (eg http://json-schema.org/draft-04/schema), before validating the data against the user's schema. It works well. If you agree with that way of doing things, if the meta schema says a schema with type: object can have a multipleOf property, the it is valid and it's up to the validator (and the common test suite) to handle that appropriately. |
New issue logged. Hum. yeah, that's a good point. Should the spec say things like "unless the object is of type x, then properties y and z should be ignore."? If so, then it would make sense to bake that into the metaschema, I would feel. |
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 think some tests should be removed.
tests/draft4/dependencies.json
Outdated
{ | ||
"description": "matches dependency", | ||
"data": {"bar": 1}, | ||
"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.
I don't understand why this test should fail. By the spec, when the property foo is absent, the schema in "dependencies" keyword should not apply. Can you please explain?
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.
@epoberezkin You're correct - that's a typo. I've corrected it now so that this data is valid.
tests/draft4/ref.json
Outdated
} | ||
] | ||
}, | ||
{ |
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 agree with @awwright, I don't think it should be included.
2541700
to
569392f
Compare
215981a
to
0e1ee65
Compare
Thanks for your very thorough feedback @Relequestual @epoberezkin and @awwright - I've removed several tests that used invalid schemas, and corrected one test that @epoberezkin pointed out had a mistake in it. I believe this should be ready to merge now but please let me know if I should make further changes. |
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 suggest removing $ref tests about ignoring other keywords.
tests/draft4/ref.json
Outdated
"type": "number", | ||
"maximum": 5, | ||
"$ref": "#/definitions/a" | ||
} |
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 would suggest not merging the test for $ref with other keywords in the same schema object, given the on-going discussion (@handrews) about whether they should be validated, ignored or prohibited (making the schema invalid).
I think the way we have in the spec now ("ignored") is the worst option, as it produces unexpected validation successes that are usually the most difficult to detect.
Probably, this test (and a similar one below) could be split into a separate PR so that everything else could be 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.
Thanks @epoberezkin - I will move these two tests into a separate pull request. Can you please confirm which issue you're referring to? (I believe #113 ?)
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.
This, for example: json-schema-org/json-schema-spec#194
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.
Also, should we add the remaining tests to draft-6 as well?
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.
@epoberezkin The current behavior of "$ref"
is clear and AFAIK not going to change in Draft 06. Tests that test its current behavior should be accepted.
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.
@handrews @epoberezkin Can I confirm that the $ref tests here do not need to be removed from this PR before merging? (Is that the consensus?)
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.
Or have I misunderstood the current behaviour for additonal properties alongside a $ref? These tests assume that any additonal properties are ignored/overwitten by those in a $ref, my reading of the json ref spec is that this is correct, but I'm not 100% sure. Either way if someone could explicitly clarify for me here I'll make the appropriate changes
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.
Your understanding is correct as far as I undertsand. I haven't however reviewed this specific change.
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.
Thanks @Relequestual
I think that's the final problem with this pull request?
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.
Sorry I simply don't have time to digest the whole issue right now.
tests/draft4/refRemote.json
Outdated
"type": "number", | ||
"maximum": 5, | ||
"$ref": "http://localhost:1234/integer.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.
Same as above, I would suggest not merging this test
0e1ee65
to
5551a40
Compare
@epoberezkin I've added these tests to draft6 now (in addition to draft4) |
@iainbeeston @epoberezkin @Julian can anyone summarize what's going on here and where we are? We'll also want to copy these to draft-07 (which is backwards-compatible with draft-06, so that should be trivial. |
The last time I looked I think there were a bunch of stuff here that needed cleaning up after review comments, but will have to have another look to see exactly what / how. |
Are these tests still desired? It's been... 6 years since anyone looked at them. A rebase is also required. If not, we should close it. |
5551a40
to
4d61c78
Compare
4d61c78
to
dbe2cd3
Compare
@gregsdennis I've rebased this, added the same tests to draft7 and removed the two ref-based tests that were controversial. This means there are only 2 new test cases added (to drafts 4, 6 and 7) |
Thanks, @iainbeeston. One last thing: could you add those tests to
please? You'll need to change |
In the 25th internationl world wide web conference there was a paper named "Foundations of JSON Schema", presented by: * Felipe Pezoa ([email protected]) * Juan L. Reutter ([email protected]) * Fernando Suarez ([email protected]) * Martín Ugarte ([email protected]) * Domagoj Vrgo ([email protected]) See: http://www2016.net/proceedings/proceedings/p263.pdf This paper compared a number of json schema implementations, using a set of 5 tests which highlighted inconsistencies between the implementations. I have reproduced those tests here. All credit should go to the authors of the paper for highlighting these inconsistencies and publishing the details of them online.
dbe2cd3
to
07fd389
Compare
@gregsdennis I've done that now, hopefully it's ready to merge? 🤞 |
Thank you. I still need to run it on my implementation (or someone else can run it on theirs). I can probably do that tomorrow. For now, it's Friday night. Thanks for updating the PR. |
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.
Works on my implementation.
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.
yep. works for me. Thanks for the additions.
In the 25th internationl world wide web conference there was a paper
named "Foundations of JSON Schema", presented by:
See:
http://www2016.net/proceedings/proceedings/p263.pdf
This paper compared a number of json schema implementations, using a set
of 5 tests which highlighted inconsistencies between the
implementations. I have reproduced those tests here. All credit should
go to the authors of the paper for highlighting these inconsistencies
and publishing the details of them online.