networknt / json-schema-validator

A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12
Apache License 2.0
860 stars 325 forks source link

`oneOf` for empty array. #1098

Closed juancki closed 3 months ago

juancki commented 3 months ago

First of all thanks for your great work.

I was bumping from the version 1.0.69 to 1.5.1 and found that I'm getting the following errors in my tests.

Error:

$: must be valid to one and only one schema, but 0 are valid
{
  "$schema": "https://json-schema.org/draft-07/schema",
  "$id": "https://example.com/example.schema.json",
  "title": "Flink-collection-sdk JsonDocumentSerdeSchemaTest ExampleClass v1",
  "description": "pte-examples",
  "type": "object",
  "properties": {
    "integer": {
      "type": "integer"
    },
    "str": {
      "type": "string"
    }
  },
  "additionalProperties": false,
  "required": [],
  "oneOf": []
}

Payload:

{"integer":1,"str":""}

When I remove the oneOf field completely I'm no longer getting errors.

This change was introduced around version 1.0.80 - 1.081.

  1. Is this the expected behavior for an empty array of oneOf?
justin-tay commented 3 months ago

The specification says

This keyword's value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.