Skip to content

Add tests for unevaluatedItems interaction with contains #474

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

Merged
merged 5 commits into from
Apr 14, 2021
Merged

Add tests for unevaluatedItems interaction with contains #474

merged 5 commits into from
Apr 14, 2021

Conversation

marksparkza
Copy link
Contributor

ref #293

@gregsdennis
Copy link
Member

gregsdennis commented Apr 10, 2021

I believe there's some discussion around additionalItems and contains where it was decided that contains doesn't affect that evaluation. It's likely that unevaluatedItems follows suit.

I'll see if I can dig that up.


Found it: it's the issue that your issue references: json-schema-org/json-schema-spec#810

There's a lot of discussion in there, and it's worth reading.

@marksparkza
Copy link
Contributor Author

Thanks - I have seen that discussion, and have just read the followup PR: json-schema-org/json-schema-spec#925

I disagree that contains shouldn't affect evaluation. In my view, it is perfectly reasonable to build use cases around the interaction of unevaluatedItems and contains, and I think the 2020-12 spec has it completely right.

Consider the following scenario (I will add this as another test case to this PR). This is a contrived example, but it illustrates how the (non)evaluation of contains may be used to control an item dependency relationship.

An array may contain any sequence of a's, b's and c's, but it may only contain b's if there is at least one a, and it may only contain c's if there is at least one b. Here is the schema:

{
    "if": {
        "contains": {"const": "a"}
    },
    "then": {
        "if": {
            "contains": {"const": "b"}
        },
        "then": {
            "if": {
                "contains": {"const": "c"}
            }
        }
    },
    "unevaluatedItems": false
}

Valid examples:

[]
[ "a", "a" ]
[ "a", "b", "a", "b", "a" ]
[ "c", "a", "c", "c", "b", "a" ]

Invalid examples:

[ "b", "b" ]
[ "c", "c" ]
[ "c", "b", "c", "b", "c" ]
[ "c", "a", "c", "a", "c" ]

We use contains and unevaluatedItems to define a dependency relationship over the array items. The array may contain any sequence of a's, b's and c's, but b's may only be present if there is at least one a, and c's may only be present if there is at least one b.
@jdesrosiers
Copy link
Member

@gregsdennis

there's some discussion around additionalItems and contains where it was decided that contains doesn't affect that evaluation.

Unfortunately, that's not how that ended up. The change got pushed through despite continued strong disagreement.

@jdesrosiers jdesrosiers merged commit dff69dc into json-schema-org:master Apr 14, 2021
@marksparkza marksparkza deleted the unevaluatedItems-depends-on-contains branch April 16, 2021 06:01
@marksparkza marksparkza restored the unevaluatedItems-depends-on-contains branch May 3, 2021 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants