hoxworth/json-schema — pull request #178 by gabrielg (2014-11-07 00:50:07+00:00)
Title: Fix id handling

This introduces a few refactors and changes which fixes handling of what validates as a valid Draft 4 schema:

```
{
"id": "#/example",
"type": "integer",
"oneOf": [
{"$ref": "#/definitions/foo"},
{"$ref": "#/definitions/bar"}],
"definitions": {
"foo": {
"type": "integer",
"maximum": 1000
},
"bar": {
"type": "integer",
"minimum": 2000,
"maximum": 3000
}
}
}
```

`json-schema` validation:

```
irb(main):005:0> require 'json-schema'
=> true
irb(main):006:0> puts valid_schema
{
"id": "#/example",
"type": "integer",
"oneOf": [
{"$ref": "#/definitions/foo"},
{"$ref": "#/definitions/bar"}],
"definitions": {
"foo": {
"type": "integer",
"maximum": 1000
},
"bar": {
"type": "integer",
"minimum": 2000,
"maximum": 3000
}
}
}
=> nil
irb(main):007:0> JSON::Validator.fully_validate_schema(valid_schema, version: :draft4)
=> []
```

It also validates against the Java [`json-schema-validator`](http://json-schema-validator.herokuapp.com/index.jsp).

Before these changes, trying to use the provided example schema would result in an exception:

```
/usr/local/opt/rbenv/versions/2.1.2/lib/ruby/2.1.0/uri/common.rb:176:in `split': bad URI(is not URI?): {"id"=>"#/example", "type"=>"integer", "oneOf"=>[{"$ref"=>"#/definitions/foo"}, {"$ref"=>"#/definitions/bar"}], "definitions"=>{"foo"=>{"type"=>"integer", "maximum"=>1000}, "bar"=>{"type"=>"integer", "minimum"=>2000, "maximum"=>3000}}} (URI::InvalidURIError)
from /usr/local/opt/rbenv/versions/2.1.2/lib/ruby/2.1.0/uri/common.rb:211:in `parse'
from /usr/local/opt/rbenv/versions/2.1.2/lib/ruby/2.1.0/uri/common.rb:747:in `parse'
from /usr/local/opt/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/json-schema-2.4.1/lib/json-schema/validator.rb:584:in `normalized_uri'
from /usr/local/opt/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/json-schema-2.4.1/lib/json-schema/validator.rb:528:in `rescue in initialize_schema'
from /usr/local/opt/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/json-schema-2.4.1/lib/json-schema/validator.rb:517:in `initialize_schema'
from /usr/local/opt/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/json-schema-2.4.1/lib/json-schema/validator.rb:47:in `block in initialize'
from /usr/local/opt/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/json-schema-2.4.1/lib/json-schema/validator.rb:47:in `synchronize'
from /usr/local/opt/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/json-schema-2.4.1/lib/json-schema/validator.rb:47:in `initialize'
from /usr/local/opt/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/json-schema-2.4.1/lib/json-schema/validator.rb:294:in `new'
from /usr/local/opt/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/json-schema-2.4.1/lib/json-schema/validator.rb:294:in `fully_validate'
from ./bin/json-validator:19:in `

'
```