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

Make hashes in arrays indifferent to string/symbol keys #105

Merged
merged 1 commit into from Jul 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/json-schema/schema.rb
Expand Up @@ -56,6 +56,10 @@ def self.add_indifferent_access(schema)
schema.keys.each do |key|
add_indifferent_access(schema[key])
end
elsif schema.is_a?(Array)
schema.each do |schema_item|
add_indifferent_access(schema_item)
end
end
end

Expand Down
32 changes: 31 additions & 1 deletion test/test_ruby_schema.rb
Expand Up @@ -35,4 +35,34 @@ def test_symbol_keys

assert(JSON::Validator.validate(schema, data))
end
end

def test_symbol_keys_in_hash_within_array
schema = {
type: 'object',
properties: {
a: {
type: "array",
items: [
{
properties: {
b: {
type: "integer"
}
}
}
]
}
}
}

data = {
a: [
{
b: 1
}
]
}

assert(JSON::Validator.validate(schema, data, :validate_schema => true))
end
end