voxpupuli / json-schema

Ruby JSON Schema Validator
MIT License
1.52k stars 241 forks source link

allOf confusing error message #474

Closed MiguelSavignano closed 12 months ago

MiguelSavignano commented 1 year ago

user.json

{
  "type": "object",
  "required": ["user"],
  "properties": {
    "user": {
      "allOf": [
        {
          "type": "object",
          "properties": {
            "name": { "type": "string" }
          }
        },
        {
          "type": "object",
          "properties": {
            "age": { "type": "integer" }
          }
        }
      ]
    }
  }
}

Example:

require "json-schema"

JSON::Validator.validate!("./user.json", user: {  name: "Jhon",  age: "1"  })

Should raise an exception because the age is not an integer, but the current message is:

 The property '#/user' of type object did not match all of the required schemas (JSON::Schema::ValidationError)

and should be an explicit messages like:

The property '#/user/age' of type string did not match the following type: integer (JSON::Schema::ValidationError)
anupama-kumari commented 12 months ago

@MiguelSavignano I have tried addressing this above issue in this PR https://github.com/voxpupuli/json-schema/pull/495 Could you please check and help me get it merged.