1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
require File.expand_path('support/test_helper', __dir__)
class LoadRefSchemaTest < Minitest::Test
def load_other_schema
JSON::Validator.add_schema(JSON::Schema.new(
{
'$schema' => 'http://json-schema.org/draft-04/schema#',
'type' => 'object',
'properties' => {
'title' => {
'type' => 'string',
},
},
},
Addressable::URI.parse('http://example.com/schema#'),
))
end
def test_cached_schema
schema_url = 'http://example.com/schema#'
schema = { '$ref' => schema_url }
data = {}
load_other_schema
_validator = JSON::Validator.new(schema, data)
assert JSON::Validator.schema_loaded?(schema_url)
end
def test_cached_schema_with_fragment
schema_url = 'http://example.com/schema#'
schema = { '$ref' => "#{schema_url}/properties/title" }
data = {}
load_other_schema
_validator = JSON::Validator.new(schema, data)
assert JSON::Validator.schema_loaded?(schema_url)
end
def test_metaschema
schema = { '$ref' => 'http://json-schema.org/draft-04/schema#' }
data = {}
assert_valid schema, data
end
end
|