harrel56 / json-schema

JSON schema validation library written in Java
https://harrel.dev/json-schema
MIT License
19 stars 4 forks source link

Cross spec validation of embedded schemas #203

Open harrel56 opened 3 months ago

harrel56 commented 3 months ago

Let's consider a multi-spec (compound) schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$ref": "#/$defs/draft2019",
  "$defs": {
    "draft2019": {
      "$schema": "https://json-schema.org/draft/2019-09/schema",
      "$id": "urn:nested",
      "items": [{
        "type": "string"
      }]
    }
  }
}

items is not valid as per draft2020 but is valid for draft2019. Now it fails because the whole JSON is validated against draft2020 meta-schema + embedded schemas individually. This is not a valid behavior according to specification (https://json-schema.org/draft/2020-12/json-schema-core#name-validating).

harrel56 commented 3 months ago

Update: this can possibly be achieved by wrapping a JsonNode in a special implementation that filters out embedded schemas. To be checked