Skip to content
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 for unevaluatedProperties peering inside an allOf #310

Closed
gregsdennis opened this issue Nov 26, 2019 · 5 comments
Closed

Test for unevaluatedProperties peering inside an allOf #310

gregsdennis opened this issue Nov 26, 2019 · 5 comments
Labels
missing test A request to add a test to the suite that is currently not covered elsewhere.

Comments

@gregsdennis
Copy link
Member

gregsdennis commented Nov 26, 2019

This question was brought up in the Slack workspace.

(The schema was originally in YAML, but I've translated to JSON for the issue.)


Given a schema

{
  "unevaluatedProperties": false,
  "allOf": [
    {
      "properties": {
        "foo": { "type": ["string", "null"] },
        "bar": { "type": ["string", "null"] }
      }
    },
    {
      "additionalProperties": {
        "not": { "enum": [ null ] }
      }
    }
  ]
}

should the instance

{"bar": "foo", "bob": "who?"}

pass validation?

The thing to note here is that additionalProperties, regardless of the subschema that's in it, visits all of the properties of any object instance that's given to it. This means that unevaluatedProperties is effectively a no-op.

The evaluation proceeds as follows:

  1. /unevaluatedProperties must be run last, so we save it for later.
  2. /allOf/properties/foo isn't found. Pass ✔️
  3. /allOf/properties/bar is found, and it's a string. Pass ✔️
  4. /additionalProperties evaluates all properties not defined by properties as:
    1. /additionalProperties/not/enum
      1. instance /bar was evaluated by properties skip. Pass ✔️
      2. instance /bob is not null. Pass ✔️
  5. Return to /unevaluatedProperties
    1. instance /bar and instance /bob were both evaluated within the allOf so unevaluatedProperties has nothing to do. Pass ✔️

All paths pass validation.

I'll write a test for this and create a PR. Just wanted to get an issue going for it.

@Julian
Copy link
Member

Julian commented Nov 26, 2019

Awesome, looks reasonable certainly -- we don't yet have any unevaluatedProperties tests :/ but yeah definitely looks worth adding.

@Julian Julian added draft support missing test A request to add a test to the suite that is currently not covered elsewhere. labels Nov 26, 2019
@handrews
Copy link
Contributor

See als #305 #294 and #290

gregsdennis added a commit that referenced this issue Nov 27, 2019
added unevaluatedProperties test file; resolves #310
@ssilverman
Copy link
Member

ssilverman commented Apr 23, 2020

Step 4.i.a. certainly passes, but I disagree on the reason. I thought "additionalProperties" only looks at properties in the same schema? In this example, all the properties are defined in a different schema than "additionalProperties". How can instance /bar already have been evaluated? My understanding tells me that it passes only because it's not null.

@Relequestual
Copy link
Member

@ssilverman You're correct.

In the provided schema, the additionalProperties subschema is applied to all object values.

It's a tricky one to reason about because not doesn't create an annotations, but the resulting assertion evaluation of additionalProperties DOES create an annotation, and therefore all properties are consider "evaulated [to be valid]".

@handrews
Copy link
Contributor

@ssilverman yeah in this case, there aren't any other properties defined in the same schema object as additionalProperties, so it behaves more like and allProperties keyword would be expected to behave. This is useful for the common case of a generic dictionary type (mapping of string to some other type with no special case properties).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing test A request to add a test to the suite that is currently not covered elsewhere.
Projects
None yet
Development

No branches or pull requests

5 participants