Skip to content

Issue with unevaluatedProperties with patternProperties and type union #582

@jkevan

Description

@jkevan

Hello, first of all thx for the great work on this library !

I discover the following issue recently using this schema:

{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "title": "Test unevaluated properties on patternProperties",
  "type": "object",
  "patternProperties": {
    "^valid_": {
      "type": ["array", "string"],
      "items": {
        "type": "string"
      }
    }
  },
  "unevaluatedProperties": false
}

And trying to validate this data:

{
  "valid_array": ["array1_value", "array2_value"],
  "valid_string": "string_value"
}

The validation is failing due to unevaluated properties. But it should be valid.

This is mostly due to the fact that the Type validator is collecting the evaluated properties too late:

In current case due to Union of type we dont reach the code in charge of collecting (previous link):

return unionTypeValidator.validate(node, rootNode, at);

(due to the return statement).

But anyway I found it strange to make the TypeValidator collecting for evaluated properties, shouldn't be the responsibility of the PatternPropertiesValidator like the PropertiesValidator is doing ?

Disclaimer:

  • we dont have the issue in case the type is using single value and not Union, so it confirms the previous analysis.
  • I tested the exact same schema and data against: https://www.jsonschemavalidator.net/ and it's correctly valid

I will try to provide unit tests scenario and a fix.

Kind regards,
Kevan.

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