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

Fail on ruby 1.9.3, jruby 1.6.8 --1.9 #45

Closed
dekellum opened this issue Aug 31, 2012 · 5 comments
Closed

Fail on ruby 1.9.3, jruby 1.6.8 --1.9 #45

dekellum opened this issue Aug 31, 2012 · 5 comments
Labels

Comments

@dekellum
Copy link
Contributor

json-schema 1.0.9 fails to validate on 1.9 rubies with:

NoMethodError: undefined method `each' for "#":String
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/validator.rb:92:in `validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/schema.rb:38:in `validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/attributes/additionalproperties.rb:18:in `block in validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/attributes/additionalproperties.rb:15:in `each'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/attributes/additionalproperties.rb:15:in `validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/validator.rb:94:in `block in validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/validator.rb:92:in `each'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/validator.rb:92:in `validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/schema.rb:38:in `validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/attributes/properties.rb:15:in `block in validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/attributes/properties.rb:6:in `each'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/attributes/properties.rb:6:in `validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/validator.rb:94:in `block in validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/validator.rb:92:in `each'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/validator.rb:92:in `validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/schema.rb:38:in `validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/validator.rb:174:in `validate'
    ruby/1.9.1/gems/json-schema-1.0.9/lib/json-schema/validator.rb:309:in `validate!'
@hoxworth
Copy link
Contributor

hoxworth commented Jul 1, 2013

Is this still an issue? I haven't been able to reproduce on the current master release on either JRuby or MRI 1.9.3

@hoxworth hoxworth closed this as completed Jul 1, 2013
@laser
Copy link

laser commented Jul 19, 2013

Hey @hoxworth

Following an example from the docs, the following works:

schema = {
  type: 'object',
  "required" => ["a"],
  properties: {
    a: {type: "integer", default: 42},
    b: {type: "integer"}
  }
}

data = {
  b: 5
}

is_valid = JSON::Validator.validate(schema, data)

but when the "required" key is changed to use the new Hash syntax, the following fails (with a NoMethodError):

schema = {
  type: 'object',
  required: ["a"], # <----- new Hash syntax
  properties: {
    a: {type: "integer", default: 42},
    b: {type: "integer"}
  }
}

data = {
  b: 5
}

is_valid = JSON::Validator.validate(schema, data)
The specific error is:

Failure/Error: is_valid = JSON::Validator.validate(schema, data)
     NoMethodError:
       undefined method `each' for nil:NilClass

Ruby info:

ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-darwin12.3.0]

Gem info:

json-schema (2.1.1)

@hoxworth
Copy link
Contributor

Thanks @laser , will start taking a look at this soon.

@hoxworth hoxworth reopened this Jul 19, 2013
@hoxworth
Copy link
Contributor

Yeah... the library was written to assume string keys in the schema. I'll add a todo to add indifferent access; this affects other keywords, like allOf, noneOf, etc.

@hoxworth
Copy link
Contributor

Just push version 2.1.2 that should fix this issue, as well as other symbol -> string issues.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants