Skip to content

Issue with unevaluatedProperties and allOf and arrays #1026

Open
@silversurfer34

Description

@silversurfer34

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs SimplificationAn issue which is in need of simplifying the example or issue being demonstrated for diagnosis.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions