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

JSON::Validator modifies schema object #83

Closed
soylent opened this issue Oct 8, 2013 · 3 comments
Closed

JSON::Validator modifies schema object #83

soylent opened this issue Oct 8, 2013 · 3 comments

Comments

@soylent
Copy link

soylent commented Oct 8, 2013

schema = { type: "object" }.freeze
JSON::Validator.validate(schema, { })
# RuntimeError: can't modify frozen Hash

I think that this is bad behaviour for JSON::Validator.validate, it should not modify the schema param. Any thoughts?

@soylent
Copy link
Author

soylent commented Oct 8, 2013

Actually this causes the following error

schema = { type: "object" }
schema.default_proc # => nil

JSON::Validator.validate(schema, { }) # => true
schema.default_proc # => => #<Proc:0x007fe1ca5b5280@/User...>

JSON::Validator.validate(schema, { })
# TypeError: can't dump hash with default proc
    from /Users/Soilent/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/json-schema-2.1.3/lib/json-schema/validator.rb:523:in `dump'
    from /Users/Soilent/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/json-schema-2.1.3/lib/json-schema/validator.rb:523:in `block in singleton class'
    from /Users/Soilent/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/json-schema-2.1.3/lib/json-schema/validator.rb:548:in `call'
    from /Users/Soilent/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/json-schema-2.1.3/lib/json-schema/validator.rb:548:in `serialize'
    from /Users/Soilent/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/json-schema-2.1.3/lib/json-schema/validator.rb:605:in `initialize_schema'
    from /Users/Soilent/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/json-schema-2.1.3/lib/json-schema/validator.rb:160:in `block in initialize'
    from /Users/Soilent/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/json-schema-2.1.3/lib/json-schema/validator.rb:160:in `synchronize'
    from /Users/Soilent/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/json-schema-2.1.3/lib/json-schema/validator.rb:160:in `initialize'
    from /Users/Soilent/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/json-schema-2.1.3/lib/json-schema/validator.rb:365:in `new'
    from /Users/Soilent/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/json-schema-2.1.3/lib/json-schema/validator.rb:365:in `validate'

@hoxworth
Copy link
Contributor

Related to #62 - the default_proc is messing things up, because Marshal can't dump a hash with a default_proc. An immediate fix for this would be to install the multi_json gem, until a fix is in place.

@hoxworth
Copy link
Contributor

hoxworth commented Jan 1, 2014

This should be fixed in 2.1.5. Thanks!

@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