voxpupuli/json-schema

MultiJSON receives filepath instead of its content

Closed this issue · 3 comments

Calling
JSON::Validator.fully_validate_schema( {"$schema"=>"http://json-schema.org/draft-03/schema#", "type"=>"object", "properties"=>{}} )
Leads to JSON::ParserError: invalid comment format at line 1, column 1 [parse.c:96]

But the same result even with JSON::Validator.fully_validate_schema( {} )

This is happening because the first arg of MultiJSON.load is
"/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/json-schema-2.5.2/resources/draft-04.json", not the content of file itself

Backtrace:

/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/multi_json-1.11.2/lib/multi_json/adapters/json_common.rb:19:in `parse'
/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/multi_json-1.11.2/lib/multi_json/adapters/json_common.rb:19:in `load'
/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/multi_json-1.11.2/lib/multi_json/adapter.rb:21:in `load'
/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/multi_json-1.11.2/lib/multi_json.rb:119:in `load'
/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/json-schema-2.6.1/lib/json-schema/validator.rb:417:in `parse'
/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/json-schema-2.6.1/lib/json-schema/validator.rb:537:in `initialize_schema'
/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/json-schema-2.6.1/lib/json-schema/validator.rb:53:in `block in initialize'
/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/json-schema-2.6.1/lib/json-schema/validator.rb:53:in `synchronize'
/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/json-schema-2.6.1/lib/json-schema/validator.rb:53:in `initialize'
/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/json-schema-2.6.1/lib/json-schema/validator.rb:276:in `new'
/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/json-schema-2.6.1/lib/json-schema/validator.rb:276:in `fully_validate'
/Users/Smelkov/.rvm/gems/ruby-2.2.3@ege-fcc-ash/gems/json-schema-2.6.1/lib/json-schema/validator.rb:283:in `fully_validate_schema'

I can reproduce this by doing the following:

require 'json-schema'
MultiJson.use :json_common
JSON::Validator.fully_validate_schema( {} ) # => raises a NameError

Unfortunately this is a bug with the :json_common adapter in MultiJson, rather than a problem with json-schema itself. I've raised an issue on the MultiJson repository for it.

A workaround for now would be to not use the :json_common MultiJson adapter (for example, use :json_gem) or not to use MultiJson with json-schema

@rwz has informed me that :json_common isn't an adapter you should be using - perhaps changing the MultiJson adapter for your app will resolve the issue

I actually just downgraded to v2.5.2 and that's fixed the issue. That's why I suspected json-schema. Anyway, thank you for your investigation.