python-jsonschema / python-jsonschema/jsonschema

Issue with unevaluatedProperties and allOf and arrays

Open
#1,026 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Simplification
Dominant language
Python
Stars
5k
Forks
671
Avg merge
1d 1h
Merged PRs (30d)
10

Description

I need to have a schema allowing extra fields only under one specific node (ExtensionProperties).
It works well using "additionalProperties": false with simple schemas:

{
    "$schema": "https://json-schema.org/draft/2019-09/schema#",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "rootppty": {
            "type": "string"
        },
        "ExtensionProperties": {
            "type": "object"          
        }
    }
}

This data is ok

{
  "rootppty": "ad",
   "ExtensionProperties": {
      "whatever": "you want"
    }
}

and this one fails validation as expected

{
  "rootppty": "ok",
  "other": "fail",
   "ExtensionProperties": {
      "whatever": "you want"
    }
}

But when I have some allOf, I need to use "unevaluatedProperties": false as explained in the documentation
It works well with simple schemas

{
    "$schema": "https://json-schema.org/draft/2019-09/schema#",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "rootppty": {
            "type": "string"
        },
        "data": {
          "unevaluatedProperties": false,
          "allOf": [{
            "type": "object",
            "title": "IndividualProperties",
            "properties": {
              "Nestedppty": {
                "type": "string"
              }
            }
          }
         ]
        },
        "ExtensionProperties": {
            "type": "object"          
        }
    }
}

This data fails the validation as expected (on rootppty2 and Nestedppty2)

{
  "rootppty": "ok",
  "rootppty2": "fail",
  "data": {
    "Nestedppty": "ok",
    "Nestedppty2": "fail"
  },
   "ExtensionProperties": {
      "whatever": "you want"
    }
}

But when I am adding array in the allOf part I am facing issues
This schema does not fail validation on additional fields in the array

{
    "$schema": "https://json-schema.org/draft/2019-09/schema#",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "rootppty": {
            "type": "string"
        },
        "data": {
            "unevaluatedProperties": false,
            "allOf": [{
                    "type": "object",
                    "title": "IndividualProperties",
                    "properties": {
                        "Nestedppty": {
                            "type": "string"
                        },
                        "Nestedarray": {
                            "type": "array",
                            "items": {
                                "unevaluatedProperties": false,
                                "type": "object",
                                "properties": {
                                    "additionalProperties": false,
                                    "nestedarrayInternalpty": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                }
            ]
        },
        "ExtensionProperties": {
            "type": "object"
        }
    }
}

for example this data should fail validation on nestedarrayInternalpty2

{
  "rootppty": "ok",
  "data": {
    "Nestedppty": "ok",
    "Nestedarray": [
      {"nestedarrayInternalpty": "ok"},
      {"nestedarrayInternalpty2": "should fail"}
    ]
  },
   "ExtensionProperties": {
      "whatever": "you want"
    }
}

but it fails also on Nestedppty, which should be ok
Am I doing something wrong or is there an issue when several "unevaluatedProperties": false are nested ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository files, tests, or entry points are mentioned. Start by running the provided schemas and instance data through the validator, then isolate how unevaluatedProperties behaves inside the allOf array items. Done means determining whether the reported rejection of Nestedppty is expected or a validator defect, with a focused regression test if it is a defect.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.