voxpupuli / json-schema

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

Issues validating objects with oneOf #327

Closed danascheider closed 8 years ago

danascheider commented 8 years ago

Summary

I am writing a JSON generator and am testing it with the following schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "oneOf": [
    { "$rel": "#/definitions/californiaAddress" },
    { "$rel": "#/definitions/floridaAddress"}
  ],
  "definitions": {
    "californiaAddress": {
      "required": [ "city", "state" ],
      "properties": {
        "city": {
          "type": "string",
          "enum": [
            "San Diego",
            "Los Angeles"
          ]
        },
        "state": {
          "type": "string",
          "enum": [ "CA" ]
        }
      }
    },
    "floridaAddress": {
      "required": [ "city", "state" ],
      "properties": {
        "city": {
          "type": "string",
          "enum": [
            "Miami",
            "Orlando"
          ]
        },
        "state": {
          "type": "string",
          "enum": [ "FL" ]
        }
      }
    }
  }
}

When I call JSON::Validator.validate! with this object as the schema and pass in the output of my app, it fails saying:

JSON::Schema::ValidationError: The property '#/' of type Hash matched more than one of the required schemas in schema 11fae3df-6a4c-5dce-bd06-02c5497c9b88

Calling JSON::Validator.validate with the same arguments returns false.

The output being tested is:

{"city":"Orlando","state":"FL"}

Expected Behavior

The object being tested should pass validation when checked against the given schema, since it clearly matches one but not both of the possible schemas.

Current Behavior

When I call JSON::Validator.validate! with the data described above, the output indicates the JSON Schema gem thinks it matches both of the possible schemas. When I call JSON::Validator.validate with the same data, the result is false.

Steps to Reproduce (for bugs)

In IRB, using the schema and output given above, call JSON::Validator.validate!(schema, object). Observe it fails.

My Environment

danascheider commented 8 years ago

This was due to a typo, sorry!