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

Unevaluated properties and subschemas #967

Closed
fvanham-coveo opened this issue Feb 13, 2024 · 1 comment · Fixed by #968
Closed

Unevaluated properties and subschemas #967

fvanham-coveo opened this issue Feb 13, 2024 · 1 comment · Fixed by #968

Comments

@fvanham-coveo
Copy link

fvanham-coveo commented Feb 13, 2024

I think there's an unclarity with unevaluated properties in combination with subschemas, although I must admit that the json schema spec is not particularly clear on some of the details around unevaluatedProperties. My understanding is the following:

  • The set of unevaluatedProperties for a schema is the set of all properties in the current schema AND any referenced subschema's (through $ref or as separate schema's in e.g. allOf/anyOf) which have not passed validation.
  • As per general spec, evaluated properties are collected by annotations: "As with all annotations, if at any point validation of a subschema fails, all annotations are dropped, and only the validation failure is propagated up to the parent schema". I take this to mean that failing subschemas do no bubble up their evaluated properties.
  • Because unevaluated properties are dependent on (possibly dynamic) subschema evaluation, they need to be evaluated last.

Here's a minimal sample that illustrates my case:

{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "$defs" : {
    "subschema": {
      "type": "object",
      "required": ["group"],
      "properties": {
        "group": {
          "type": "object",
          "additionalProperties": false,
          "required": ["parentprop"],
          "properties": {
            "parentprop": {
              "type": "string"
            }
          }
        }
      }
    }
  },
  "type": "object",
  "unevaluatedProperties": false,
  "allOf": [
    {"properties": { "group" : {"type":"object"} } },
    {"$ref": "#/$defs/subschema"}
  ],
  "required": ["childprop"],
  "properties": {
    "childprop": {
      "type": "string"
    }
  }
}

This schema has a two subschemas in the allOf, one inline one via a $ref. Running a validation with the following input

{
  "childprop": "something",
  "group": {
     "parentprop":"something",
     "notallowed": false
  }
}

Produces three validation errors with the latest version (1.3.2) :

[$.group: property 'notallowed' is not defined in the schema and the schema does not allow additional properties, $: property 'childprop' must not be unevaluated, $: property 'group' must not be unevaluated]

The first validation error is correct, there is an extra property which should not be there. The next two are incorrect (I think): group should've passed validation in the first allOf schema, even though it hasn't been successfully evaluated in the second allOf schema, due to the extra property. childProp should have passed validation in the top level schema.

Looking back, earlier version (e.g. I verified with 1.1.0) do not produce the childProp validation error.

@justin-tay
Copy link
Contributor

Thanks for the explanation and example.

This is a duplicate of

The fix is already merged to master but hasn't been released yet.

Using your example the following is the only result.

$.group: property 'notallowed' is not defined in the schema and the schema does not allow additional properties

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 a pull request may close this issue.

2 participants