Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/json-schema/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions test/test_fragment_validation_with_ref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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