Skip to content

Unevaluated properties and subschemas #967

@fvanham-coveo

Description

@fvanham-coveo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions