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

Not correctly validating: "The property did not match the following type: string in schema" #101

Closed
rringham opened this issue May 17, 2014 · 1 comment

Comments

@rringham
Copy link

Using v2.2.2, I'm unable to get the following to validate correctly:

    schema = {
        :type => 'object',
        :required => %w(anArray),
        :properties => {
            :anArray => {
                :type => 'array',
                :items => {
                    :type => 'object',
                    :required => %w(aString),
                    :properties => {
                        :aString => {
                            :type => 'string'
                        }
                    }
                }
            }
        }
    }

    data = {
        :anArray => [
           {
               :aString => 'This should validate correctly as a string'
           }
        ]
    }

    errors = JSON::Validator.fully_validate(schema, data)

The error I get back is this:

"The property '#/anArray/0/aString' of type NilClass did not match the following type: string in schema d3577c07-1a58-5f4d-98ec-f560f6b58001#"

Just to be sure that my schema & data are correct, I can get a JSON version to validate using a tool like this: http://json-schema-validator.herokuapp.com

Here is my JSON schema that I'm using:

{
    "type":"object",
    "$schema": "http://json-schema.org/draft-03/schema",
    "id": "http://jsonschema.net",
    "required":false,
    "properties":{
        "anArray": {
            "type":"array",
            "id": "http://jsonschema.net/anArray",
            "required":true,
            "items":
                {
                    "type":"object",
                    "id": "http://jsonschema.net/anArray/0",
                    "required":true,
                    "properties":{
                        "aString": {
                            "type":"string",
                            "id": "http://jsonschema.net/anArray/0/aString",
                            "required":false
                        }
                    }
                }


        }
    }
}

And the data that correctly validates with http://json-schema-validator.herokuapp.com:

{
  "anArray": [
    {
      "aString": "This should validate correctly as a string"
    }
  ]
}
jennyd added a commit to jennyd/json-schema that referenced this issue Jul 15, 2014
JSON::Schema.add_indifferent_access was only able to recurse into
hashes directly contained within another hash; as soon as it found a
value which was not a hash it stopped. This meant that hashes within
arrays were not being made indifferent to the key type, and so data
which included symbol keys in a hash in an array were failing validation
against a JSON schema when they should have been valid.

This commit adds a failing minimal test for this case and fixes voxpupuli#104.
We think that voxpupuli#104 is a duplicate of voxpupuli#101 and voxpupuli#94 so those issues are
likely to be fixed by this as well.
jennyd added a commit to jennyd/json-schema that referenced this issue Jul 16, 2014
JSON::Schema.add_indifferent_access was only able to recurse into
hashes directly contained within another hash; as soon as it found a
value which was not a hash it stopped. This meant that hashes within
arrays were not being made indifferent to the key type, and so data
which included symbol keys in a hash in an array were failing validation
against a JSON schema when they should have been valid.

This commit adds a failing minimal test for this case and fixes voxpupuli#104.
We think that voxpupuli#104 is a duplicate of voxpupuli#101 and voxpupuli#94 so those issues are
likely to be fixed by this as well.
jennyd added a commit to jennyd/json-schema that referenced this issue Jul 16, 2014
JSON::Schema.add_indifferent_access was only able to recurse into
hashes directly contained within another hash; as soon as it found a
value which was not a hash it stopped. This meant that hashes within
arrays were not being made indifferent to the key type, and so data
with symbol keys in a hash in an array were failing validation when
they should have been valid.

This commit adds a failing minimal test for this case and fixes voxpupuli#104.
We think that voxpupuli#104 is a duplicate of voxpupuli#101 and voxpupuli#94 so those issues are
likely to be fixed by this as well.
jennyd added a commit to jennyd/json-schema that referenced this issue Jul 16, 2014
JSON::Schema.add_indifferent_access was only able to recurse into
hashes directly contained within another hash; as soon as it found a
value which was not a hash it stopped. This meant that hashes within
arrays were not being made indifferent to the key type, and so data
with symbol keys in a hash in an array were failing validation when
they should have been valid.

This commit adds a minimal test for this case and fixes voxpupuli#104.
We think that voxpupuli#104 is a duplicate of voxpupuli#101 and voxpupuli#94 so those issues are
likely to be fixed by this as well.
@hoxworth
Copy link
Contributor

Should be fixed in 2.2.3 via fix from @jennyd - let me know if you still see an issue. Thanks!

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

2 participants