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

Conversation

jennyd
Copy link
Contributor

@jennyd jennyd commented 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 #104.
We think that #104 is a duplicate of #101 and #94 so those issues are
likely to be fixed by this as well.

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

Looks good, thanks a ton for adding this! Always never have time to keep up with this library :)

hoxworth added a commit that referenced this pull request Jul 16, 2014
Make hashes in arrays indifferent to string/symbol keys
@hoxworth hoxworth merged commit 4860a52 into voxpupuli:master Jul 16, 2014
jennyd added a commit to alphagov/hmrc-manuals-api that referenced this pull request Jul 17, 2014
This is to pick up our fix to the gem for symbol keys in hashes in
arrays:

    voxpupuli/json-schema#105

This means that we can write our test data more idiomatically as ruby
hashes with symbol keys. While working on the schema we had found a
workaround to this which involved calling .to_json on the data before
validating it, but the fix makes this unnecessary.
@apsoto
Copy link
Contributor

apsoto commented Jul 17, 2014

@hoxworth thanks. To help spread the work load how about adopting a policy that anyone that provides a merged PR gets collaborator access?

@hoxworth
Copy link
Contributor

@apsoto Yeah, I have been meaning to open up the contribution a bit more anyway. I'll get started on this ASAP.

@hoxworth
Copy link
Contributor

Done and done.

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

Successfully merging this pull request may close these issues.

Symbol keys are not supported in objects within arrays
3 participants