diff --git a/lib/json-schema/validator.rb b/lib/json-schema/validator.rb index 571a823d..245d3e0d 100644 --- a/lib/json-schema/validator.rb +++ b/lib/json-schema/validator.rb @@ -105,6 +105,8 @@ def schema_from_fragment(base_schema, fragment) if @options[:list] base_schema.to_array_schema + elsif base_schema.is_a?(Hash) + JSON::Schema.new(base_schema, schema_uri, @options[:version]) else base_schema end diff --git a/test/test_fragment_validation_with_ref.rb b/test/test_fragment_validation_with_ref.rb index 459c541c..745422e5 100644 --- a/test/test_fragment_validation_with_ref.rb +++ b/test/test_fragment_validation_with_ref.rb @@ -27,8 +27,41 @@ def whole_schema } end + def whole_schema_with_array + { + "$schema" => "http://json-schema.org/draft-04/schema#", + "type" => "object", + "definitions" => { + "omg" => { + "links" => [ + { + "type" => "object", + "schema" => { + "properties" => { + "content" => { + "type" => "string" + }, + "author" => { + "type" => "string" + } + }, + "required" => ["content", "author"] + } + } + ] + } + } + } + end + def test_validation_of_fragment data = [{"content" => "ohai", "author" => "Bob"}] assert_valid whole_schema, data, :fragment => "#/definitions/posts" end + + def test_validation_of_fragment_with_array + data = {"content" => "ohai", "author" => "Bob"} + assert_valid(whole_schema_with_array, data, + :fragment => "#/definitions/omg/links/0/schema") + end end