Closed Julian closed 1 year ago
{
"description": "validation based on item keyword",
"schema": {
"$schema":"https://json-schema.org/draft/2020-12/schema",
"items": {
"type": "integer"
},
"additionalItems": {
"type": "string"
}
},
"tests": [
{
"description": "valid with a array of type integers",
"data": [1,2,3],
"valid": true
},
{
"description": "invalid with a array of mixed types",
"data": [1,"2","3"],
"valid": false
}
]
}
Hi @Julian can you please check if this test is valid . If its okay ,which file should I be adding this to or should i create a new one .
Thanks for trying to tackle this @0xSudarshan super appreciated. Here's some notes:
"schema"
against each of the things you put in tests
-- and seeing if the result matches. If it does, you probably have it right! If it doesn't, you probably have it wrong. Though technically both cases can be wrong, because implementations may have bugs, which is exactly why we add new tests :)draft2019-09
, draft7
and draft6
(and not to draft2020-12
-- the additionalItems
keyword doesn't exist there anymore in the new versions of the specification). The tests would be the same for all 3 directories, so you can basically copy paste, with only one difference -- the $schema
key needs to be present in 2019
(similar to how you have it shown, but use the 2019 URL which you'll find in the 2019 files). And then for draft7 and 6 you can delete that $schema
key"items": {}
so it has no way of testing an invalid example, whereas the one I showed can be tested against both valid and invalid examples like you showed -- but I'd put this new test right on top of the existing one there, and you should find a similar test in the draft7 and draft6 folders in the same spotadditionalItems
, and the best description I think is similar to the test that we're "improving" -- that one has description "when items is schema, additionalItems does nothing" -- I think what we should do is use that description for your new test, and rename the existing description to "when items is schema, boolean additionalItems does nothing" (where I added the word "boolean" -- remember to do that in all 3 folders.Let me know if that helps or if anything's unclear -- or if there's anything that'd help you as a new contributor to make this easier! And thanks again for giving this a shot!
Thanks @Julian ! I have raised a PR #643 could you pls review it .
In pre-2020 drafts,
items
could take a schema or an array of schemas, and there was anadditionalItems
keyword. See e.g. hereWe have no test at the minute that asserts against the result of including a single schema
items
alongside a (vacuous)additionalItems
(where the behavior should be that the result depends solely on theitems
schema).In other words, a schema such as:
when applied to
[1, 2, 3]
should succeed, and when applied to[1, "2", "3"]
should fail.