Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues validating objects with oneOf #327

Closed
danascheider opened this issue May 27, 2016 · 1 comment
Closed

Issues validating objects with oneOf #327

danascheider opened this issue May 27, 2016 · 1 comment

Comments

@danascheider
Copy link

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
Copy link
Author

This was due to a typo, sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant