json-schema-org / JSON-Schema-Test-Suite

A language agnostic test suite for the JSON Schema specifications
MIT License
627 stars 208 forks source link

Add a test for schema-items alongside "ignored" additionalItems #635

Closed Julian closed 1 year ago

Julian commented 1 year ago

In pre-2020 drafts, items could take a schema or an array of schemas, and there was an additionalItems keyword. See e.g. here

We 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 the items schema).

In other words, a schema such as:

{
  "items": {"type": "integer"},
  "additionalItems": {"type": "string"}
}

when applied to [1, 2, 3] should succeed, and when applied to [1, "2", "3"] should fail.

ghost commented 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 .

Julian commented 1 year ago

Thanks for trying to tackle this @0xSudarshan super appreciated. Here's some notes:

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!

ghost commented 1 year ago

Thanks @Julian ! I have raised a PR #643 could you pls review it .