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

Validation still requires data hash keys to be strings. Contrary to most recent version's stated purpose. #74

Closed
jmeirow opened this issue Sep 3, 2013 · 1 comment

Comments

@jmeirow
Copy link

jmeirow commented Sep 3, 2013

require 'json-schema'
require 'pp'

  • Validation still depends on hash keys as symbols. This is contrary to the most recent version's notes.

"Make hashes indifferent to strings and symbols when using Ruby in the schema or the data"

$ gem list | grep json => json-schema (2.1.3)

'age' is requried to be an integer

schema = {
"type" => "object",
"required" => ["first_name", "last_name", "ssn", "age"],
"properties" => {
"first_name" => { "type" => "string" },
"last_name" => { "type" => "string" },
"ssn" => { "type" => "string" },
"age" => { "type" => "integer" },
"address" => { "type" => "object" }
}
}

  • validation properly enforced when data hash has string keys

data = {'first_name' => 'Joseph', 'last_name' => 'Smith', 'age' => false, 'ssn' => '123456789', }

pp JSON::Validator.fully_validate(schema, data, :errors_as_objects => true, :validate_schema => true)

-> [{:schema=>
#<URI::Generic:0x007fa714a0c590 URL:b3506251-b386-5804-a591-d72a6b3e417d#>,
:fragment=>"#/age",
:message=>
"The property '#/age' of type FalseClass did not match the following type: integer in schema b3506251-b386-5804-a591-d72a6b3e417d#",
:failed_attribute=>"TypeV4"}]

  • validation does not catch invalid type for 'age'

data = {:first_name => 'Joseph', :last_name => 'Smith', :age => false, :ssn => '123456789', }

pp JSON::Validator.fully_validate(schema, data, :errors_as_objects => true, :validate_schema => true)

=> []

@hoxworth
Copy link
Contributor

hoxworth commented Jan 1, 2014

This should be fixed in 2.1.6. Sorry for the delay, thanks for the repot!

@hoxworth hoxworth closed this as completed Jan 1, 2014
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