danielaparker / jsoncons

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
https://danielaparker.github.io/jsoncons
Other
726 stars 164 forks source link

Handling of "oneOf" statement #502

Closed roszakg closed 7 months ago

roszakg commented 7 months ago

I'm not sure if that is a bug or expected behavior, but for the following schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "/test_schema",
  "type": "object",
  "properties": {
    "One": {
      "type": "string"
    },
    "Two" : {
      "type": "string"
    }
  },
  "oneOf" : [
    {
      "required" : ["One"]
    },
    {
      "required" : ["Two"]
    }
  ],
  "unevaluatedProperties" : false
}

the validation correctly fails when checked with the following JSON file:

{
    "One" : "test",
    "Two" : "test"
}

However the error message itself does not seem right: "No schema matched, but exactly one of them is required to match"

I was expecting something more in line with what https://www.jsonschemavalidator.net/ is returning:

"JSON is valid against more than one schema from 'oneOf'. Valid schema indexes: 0, 1."

Is that a bug?

What jsoncons library version?

danielaparker commented 7 months ago

Yes, "No schema matched" is wrong, we'll fix the message.

danielaparker commented 7 months ago

Fixed on master.