-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
Test interaction between unevaluatedProperties and additionalProperties #755
base: main
Are you sure you want to change the base?
Test interaction between unevaluatedProperties and additionalProperties #755
Conversation
We do have this test already: JSON-Schema-Test-Suite/tests/draft2020-12/unevaluatedProperties.json Lines 134 to 162 in 82a0774
Your case should be covered by the "with additional properties" scenario. Note how |
Thanks for taking a look :) I am aware of this test, I actually started writing this one based off it. The difference between the two is that a real life JSON Schema implementation (check-jsonschema) works correctly for one, but not for the other. That is a strong reason to cover both variants in the test suite. |
I'd be interested in what the difference between the tests is that trips up the implementation. To me, your new test is a duplicate. If you can do some experimentation with it to isolate what the trigger is, maybe we can better target the test. |
I did experiment a bit and to me it seems the difference is whether additionalProperties is If this is about the description of the tests, I’m fine with rewording them to, e.g.
or anything else you see fit. I’m not so happy about calling this test a duplicate. Tests do only ever confirm that some property holds for a single input. For everything but the most trivial cases, the wast majority of inputs are never tested. So for any one of these inputs an implementation might misbehave while working fine for the rest. Thus adding a test for another input is not adding a duplicate, but sampling more of the input space and gaining more confidence a property holds. |
Sry, reopening, closed by accident |
I'll let @Julian weigh in here, but I wonder whether the implementation is failing to handle I'm not arguing that a case that an implementation misses shouldn't be added. In fact, our general policy is to include these cases. I'm just trying to dig down to find what the implementation is actually failing on so that we can create the appropriate test. |
I think the additional test being proposed in this PR is good and we should keep it, and additionally we should simplify the existing test that Greg linked to above -- the It's possible that this failing implementation is looking directly at |
Thanks for the PR. We (speaking on behalf of the implementation for a minute) definitely handle (Back to ignoring the implementation) -- splitting/simplifying the existing test does seem right to me as well, though changing existing tests is careful work, so I'd typically hope if a new contributor is willing to try to figure that out great, if not this new test seems pretty straightforward to me to merge and then file an issue to do that for whoever is willing. |
Simplified tests by removing the superfluous type keywords in the whole file and additionally removing the Is there an easy way to actually run this test suite with one or more tools btw? |
here's a testing result from @sourcemeta/jsonschema validate --trace command notice, {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": { "type": "string" },
"unevaluatedProperties": false
} {
"foo": "foo"
} -> (push) "/additionalProperties"
at ""
at keyword location "#/additionalProperties"
<- (pass) "/additionalProperties"
at ""
at keyword location "#/additionalProperties" {
"foo": "foo",
"bar": 1
} -> (push) "/additionalProperties"
at ""
at keyword location "#/additionalProperties"
<- (fail) "/additionalProperties"
at ""
at keyword location "#/additionalProperties" Using the Official JSON Schema Test {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"foo": {
"type": "string"
}
},
"additionalProperties": true,
"unevaluatedProperties": false
} {
"foo": "foo"
} -> (push) "/properties/foo/type"
at "/foo"
at keyword location "#/properties/foo/type"
<- (pass) "/properties/foo/type"
at "/foo"
at keyword location "#/properties/foo/type"
-> (push) "/type"
at ""
at keyword location "#/type"
<- (pass) "/type"
at ""
at keyword location "#/type" {
"foo": "foo",
"bar": 1
} -> (push) "/properties/foo/type"
at "/foo"
at keyword location "#/properties/foo/type"
<- (pass) "/properties/foo/type"
at "/foo"
at keyword location "#/properties/foo/type"
-> (push) "/type"
at ""
at keyword location "#/type"
<- (pass) "/type"
at ""
at keyword location "#/type" Interestingly, it doesn't have any output for this schema for either instance. I wonder if it's silently failing. @jviotti {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": true,
"unevaluatedProperties": false
} {
"foo": "foo"
} {
"foo": "foo",
"bar": 1
} |
Note that latter schema is doing nothing, so no assertions are generated! You are not adding a |
Does this need something to move forward? |
I found this scenario where the output of check-jsonschema deviates from my reading of the spec.
In my understanding,
unevaluatedProperties: false
should evaluate successfully if the subschemaadditionalProperties
matches all properties. E.g.{"foo": "foo"}
should be a valid instance of the following schema.