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

Nested oneOf gives incorrect validation error under very specific circumstances #383

Closed
JonasProgrammer opened this issue Mar 13, 2021 · 1 comment

Comments

@JonasProgrammer
Copy link
Contributor

Hi,

first of all thank you for the effort to provide a Jackson-compatible JSONSchema validator.

I have recently encountered an error where both IntelliJ's integrated JSONSchema validator and an online validator accept a given input, but json-schema-validator rejects it.
The issue is related to state handling within OneOfValidator, but I was only able to trigger it by reducing my specific inputs -- just nesting oneOf did not do the job.

At its core this seems to be related to the parent still holding a reference to the once-pointed-to validatorState, even after .remove() is called on it and nodeMatches is false for that instance.

The following was the most reduced I could come up with that still triggers the issue; I'm aware that it is still verbose, so sorry for that.

{
  "validation": {
    "all": [
      {
        "notEmpty": {
          "field": "test"
        }
      }
    ]
  }
}
{
  "type": "object",
  "properties": {
    "validation": {
      "$ref": "#/definitions/predicateOrNull"
    }
  },
  "definitions": {
    "fieldRef": {
      "type": "object",
      "properties": {
        "field": {
          "type": "string"
        },
        "set": {
          "type": "string"
        }
      },
      "required": [
        "field"
      ]
    },
    "patternPredicate": {
      "type": "object",
      "oneOf": [
        {
          "properties": {
            "notEmpty": {
              "$ref": "#/definitions/fieldRef"
            }
          },
          "required": [
            "notEmpty"
          ]
        },
        {
          "properties": {
            "notBlank": {
              "$ref": "#/definitions/fieldRef"
            }
          },
          "required": [
            "notBlank"
          ]
        }
      ]
    },
    "allPredicate": {
      "type": "object",
      "properties": {
        "all": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/definitions/predicate"
          }
        }
      },
      "required": [
        "all"
      ]
    },
    "predicate": {
      "type": "object",
      "oneOf": [
        {
          "$ref": "#/definitions/patternPredicate"
        },
        {
          "$ref": "#/definitions/allPredicate"
        }
      ]
    },
    "predicateOrNull": {
      "oneOf": [
        {
          "$ref": "#/definitions/predicate"
        },
        {
          "type": "null"
        }
      ]
    }
  }
}
JonasProgrammer added a commit to JonasProgrammer/json-schema-validator that referenced this issue Mar 13, 2021
- signal nodeMatch to parent handler in OneOfValidator
stevehu pushed a commit that referenced this issue Mar 14, 2021
- signal nodeMatch to parent handler in OneOfValidator
@JonasProgrammer
Copy link
Contributor Author

Fixed in #384

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

No branches or pull requests

1 participant