json-schema 2.5.1 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.textile +2 -2
- data/lib/json-schema/attributes/properties.rb +1 -1
- data/lib/json-schema/validator.rb +14 -6
- metadata +6 -121
- data/test/data/all_of_ref_data.json +0 -3
- data/test/data/any_of_ref_data.json +0 -7
- data/test/data/bad_data_1.json +0 -3
- data/test/data/good_data_1.json +0 -3
- data/test/data/one_of_ref_links_data.json +0 -5
- data/test/schemas/address_microformat.json +0 -18
- data/test/schemas/all_of_ref_base_schema.json +0 -6
- data/test/schemas/all_of_ref_schema.json +0 -7
- data/test/schemas/any_of_ref_jane_schema.json +0 -4
- data/test/schemas/any_of_ref_jimmy_schema.json +0 -4
- data/test/schemas/any_of_ref_john_schema.json +0 -4
- data/test/schemas/any_of_ref_schema.json +0 -15
- data/test/schemas/definition_schema.json +0 -15
- data/test/schemas/extends_and_additionalProperties-1-filename.schema.json +0 -34
- data/test/schemas/extends_and_additionalProperties-1-ref.schema.json +0 -34
- data/test/schemas/extends_and_additionalProperties-2-filename.schema.json +0 -33
- data/test/schemas/extends_and_additionalProperties-2-ref.schema.json +0 -33
- data/test/schemas/good_schema_1.json +0 -10
- data/test/schemas/good_schema_2.json +0 -10
- data/test/schemas/good_schema_extends1.json +0 -10
- data/test/schemas/good_schema_extends2.json +0 -13
- data/test/schemas/inner.schema.json +0 -21
- data/test/schemas/one_of_ref_links_schema.json +0 -16
- data/test/schemas/ref john with spaces schema.json +0 -11
- data/test/schemas/relative_definition_schema.json +0 -8
- data/test/schemas/self_link_schema.json +0 -17
- data/test/schemas/up_link_schema.json +0 -17
- data/test/test_all_of_ref_schema.rb +0 -35
- data/test/test_any_of_ref_schema.rb +0 -35
- data/test/test_bad_schema_ref.rb +0 -39
- data/test/test_common_test_suite.rb +0 -66
- data/test/test_custom_format.rb +0 -116
- data/test/test_definition.rb +0 -15
- data/test/test_extended_schema.rb +0 -62
- data/test/test_extends_and_additionalProperties.rb +0 -52
- data/test/test_files_v3.rb +0 -43
- data/test/test_fragment_resolution.rb +0 -30
- data/test/test_fragment_validation_with_ref.rb +0 -34
- data/test/test_full_validation.rb +0 -208
- data/test/test_helper.rb +0 -47
- data/test/test_initialize_data.rb +0 -118
- data/test/test_jsonschema_draft1.rb +0 -141
- data/test/test_jsonschema_draft2.rb +0 -113
- data/test/test_jsonschema_draft3.rb +0 -450
- data/test/test_jsonschema_draft4.rb +0 -657
- data/test/test_list_option.rb +0 -21
- data/test/test_load_ref_schema.rb +0 -40
- data/test/test_merge_missing_values.rb +0 -45
- data/test/test_minitems.rb +0 -16
- data/test/test_one_of.rb +0 -85
- data/test/test_ruby_schema.rb +0 -59
- data/test/test_schema_loader.rb +0 -74
- data/test/test_schema_type_attribute.rb +0 -20
- data/test/test_schema_validation.rb +0 -185
- data/test/test_stringify.rb +0 -48
- data/test/test_uri_related.rb +0 -67
- data/test/test_validator.rb +0 -53
data/test/test_list_option.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class ListOptionTest < Minitest::Test
|
4
|
-
def test_list_option_reusing_schemas
|
5
|
-
schema_hash = {
|
6
|
-
"$schema" => "http://json-schema.org/draft-04/schema#",
|
7
|
-
"type" => "object",
|
8
|
-
"properties" => { "a" => { "type" => "integer" } }
|
9
|
-
}
|
10
|
-
|
11
|
-
uri = Addressable::URI.parse('http://example.com/item')
|
12
|
-
schema = JSON::Schema.new(schema_hash, uri)
|
13
|
-
JSON::Validator.add_schema(schema)
|
14
|
-
|
15
|
-
data = {"a" => 1}
|
16
|
-
assert_valid uri.to_s, data
|
17
|
-
|
18
|
-
data = [{"a" => 1}]
|
19
|
-
assert_valid uri.to_s, data, :list => true
|
20
|
-
end
|
21
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class LoadRefSchemaTests < Minitest::Test
|
4
|
-
def load_other_schema
|
5
|
-
JSON::Validator.add_schema(JSON::Schema.new(
|
6
|
-
{
|
7
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
8
|
-
'type' => 'object',
|
9
|
-
'properties' => {
|
10
|
-
"title" => {
|
11
|
-
"type" => "string"
|
12
|
-
}
|
13
|
-
}
|
14
|
-
},
|
15
|
-
Addressable::URI.parse("http://example.com/schema#")
|
16
|
-
))
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_cached_schema
|
20
|
-
schema_url = "http://example.com/schema#"
|
21
|
-
schema = {
|
22
|
-
"$ref" => schema_url
|
23
|
-
}
|
24
|
-
data = {}
|
25
|
-
load_other_schema
|
26
|
-
validator = JSON::Validator.new(schema, data)
|
27
|
-
assert JSON::Validator.schema_loaded?(schema_url)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_cached_schema_with_fragment
|
31
|
-
schema_url = "http://example.com/schema#"
|
32
|
-
schema = {
|
33
|
-
"$ref" => "#{schema_url}/properties/title"
|
34
|
-
}
|
35
|
-
data = {}
|
36
|
-
load_other_schema
|
37
|
-
validator = JSON::Validator.new(schema, data)
|
38
|
-
assert JSON::Validator.schema_loaded?(schema_url)
|
39
|
-
end
|
40
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class MergeMissingValuesTest < Minitest::Test
|
4
|
-
def test_merge_missing_values_for_string
|
5
|
-
original = 'foo'
|
6
|
-
updated = 'foo'
|
7
|
-
JSON::Validator.merge_missing_values(updated, original)
|
8
|
-
assert_equal('foo', original)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_merge_missing_values_for_empty_array
|
12
|
-
original = []
|
13
|
-
updated = []
|
14
|
-
JSON::Validator.merge_missing_values(updated, original)
|
15
|
-
assert_equal([], original)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_merge_missing_values_for_empty_hash
|
19
|
-
original = {}
|
20
|
-
updated = {}
|
21
|
-
JSON::Validator.merge_missing_values(updated, original)
|
22
|
-
assert_equal({}, original)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_merge_missing_values_for_new_values
|
26
|
-
original = {:hello => 'world'}
|
27
|
-
updated = {'hello' => 'world', 'foo' => 'bar'}
|
28
|
-
JSON::Validator.merge_missing_values(updated, original)
|
29
|
-
assert_equal({:hello => 'world', 'foo' => 'bar'}, original)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_merge_missing_values_for_nested_array
|
33
|
-
original = [:hello, 'world', 1, 2, 3, {:foo => :bar, 'baz' => 'qux'}]
|
34
|
-
updated = ['hello', 'world', 1, 2, 3, {'foo' => 'bar', 'baz' => 'qux', 'this_is' => 'new'}]
|
35
|
-
JSON::Validator.merge_missing_values(updated, original)
|
36
|
-
assert_equal([:hello, 'world', 1, 2, 3, {:foo => :bar, 'baz' => 'qux', 'this_is' => 'new'}], original)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_merge_missing_values_for_nested_hash
|
40
|
-
original = {:hello => 'world', :foo => ['bar', :baz, {:uno => {:due => 3}}]}
|
41
|
-
updated = {'hello' => 'world', 'foo' => ['bar', 'baz', {'uno' => {'due' => 3, 'this_is' => 'new'}}], 'ack' => 'sed'}
|
42
|
-
JSON::Validator.merge_missing_values(updated, original)
|
43
|
-
assert_equal({:hello => 'world', :foo => ['bar', :baz, {:uno => {:due => 3, 'this_is' => 'new'}}], 'ack' => 'sed'}, original)
|
44
|
-
end
|
45
|
-
end
|
data/test/test_minitems.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class MinItemsTest < Minitest::Test
|
4
|
-
def test_minitems_nils
|
5
|
-
schema = {
|
6
|
-
"type" => "array",
|
7
|
-
"minItems" => 1,
|
8
|
-
"items" => { "type" => "object" }
|
9
|
-
}
|
10
|
-
|
11
|
-
errors = JSON::Validator.fully_validate(schema, [nil])
|
12
|
-
assert_equal(errors.length, 1)
|
13
|
-
assert(errors[0] !~ /minimum/)
|
14
|
-
assert(errors[0] =~ /NilClass/)
|
15
|
-
end
|
16
|
-
end
|
data/test/test_one_of.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class OneOfTest < Minitest::Test
|
4
|
-
def test_one_of_links_schema
|
5
|
-
schema = schema_fixture_path('one_of_ref_links_schema.json')
|
6
|
-
data = data_fixture_path('one_of_ref_links_data.json')
|
7
|
-
assert_valid schema, data
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_one_of_with_string_patterns
|
11
|
-
schema = {
|
12
|
-
"$schema" => "http://json-schema.org/draft-04/schema#",
|
13
|
-
"oneOf" => [
|
14
|
-
{
|
15
|
-
"properties" => {"a" => {"type" => "string", "pattern" => "foo"}},
|
16
|
-
},
|
17
|
-
{
|
18
|
-
"properties" => {"a" => {"type" => "string", "pattern" => "bar"}},
|
19
|
-
},
|
20
|
-
{
|
21
|
-
"properties" => {"a" => {"type" => "string", "pattern" => "baz"}},
|
22
|
-
}
|
23
|
-
]
|
24
|
-
}
|
25
|
-
|
26
|
-
assert_valid schema, { "a" => "foo" }
|
27
|
-
refute_valid schema, { "a" => "foobar" }
|
28
|
-
assert_valid schema, { "a" => "baz" }
|
29
|
-
refute_valid schema, { "a" => 5 }
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_one_of_sub_errors
|
33
|
-
schema = {
|
34
|
-
"$schema" => "http://json-schema.org/draft-04/schema#",
|
35
|
-
"oneOf" => [
|
36
|
-
{
|
37
|
-
"properties" => {"a" => {"type" => "string", "pattern" => "foo"}},
|
38
|
-
},
|
39
|
-
{
|
40
|
-
"properties" => {"a" => {"type" => "string", "pattern" => "bar"}},
|
41
|
-
},
|
42
|
-
{
|
43
|
-
"properties" => {"a" => {"type" => "number", "minimum" => 10}},
|
44
|
-
}
|
45
|
-
]
|
46
|
-
}
|
47
|
-
|
48
|
-
errors = JSON::Validator.fully_validate(schema, { "a" => 5 }, :errors_as_objects => true)
|
49
|
-
nested_errors = errors[0][:errors]
|
50
|
-
assert_equal([:oneof_0,:oneof_1,:oneof_2], nested_errors.keys, 'should have nested errors for each allOf subschema')
|
51
|
-
assert_match(/the property '#\/a' of type Fixnum did not match the following type: string/i, nested_errors[:oneof_0][0][:message])
|
52
|
-
assert_match(/the property '#\/a' did not have a minimum value of 10, inclusively/i, nested_errors[:oneof_2][0][:message])
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_one_of_sub_errors_message
|
56
|
-
schema = {
|
57
|
-
"$schema" => "http://json-schema.org/draft-04/schema#",
|
58
|
-
"oneOf" => [
|
59
|
-
{
|
60
|
-
"properties" => {"a" => {"type" => "string", "pattern" => "foo"}},
|
61
|
-
},
|
62
|
-
{
|
63
|
-
"properties" => {"a" => {"type" => "string", "pattern" => "bar"}},
|
64
|
-
},
|
65
|
-
{
|
66
|
-
"properties" => {"a" => {"type" => "number", "minimum" => 10}},
|
67
|
-
}
|
68
|
-
]
|
69
|
-
}
|
70
|
-
|
71
|
-
errors = JSON::Validator.fully_validate(schema, { "a" => 5 })
|
72
|
-
expected_message = """The property '#/' of type Hash did not match any of the required schemas. The schema specific errors were:
|
73
|
-
|
74
|
-
- oneOf #0:
|
75
|
-
- The property '#/a' of type Fixnum did not match the following type: string
|
76
|
-
- oneOf #1:
|
77
|
-
- The property '#/a' of type Fixnum did not match the following type: string
|
78
|
-
- oneOf #2:
|
79
|
-
- The property '#/a' did not have a minimum value of 10, inclusively"""
|
80
|
-
|
81
|
-
assert_equal(expected_message, errors[0])
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
data/test/test_ruby_schema.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class RubySchemaTest < Minitest::Test
|
4
|
-
def test_string_keys
|
5
|
-
schema = {
|
6
|
-
"type" => 'object',
|
7
|
-
"required" => ["a"],
|
8
|
-
"properties" => {
|
9
|
-
"a" => {"type" => "integer", "default" => 42},
|
10
|
-
"b" => {"type" => "integer"}
|
11
|
-
}
|
12
|
-
}
|
13
|
-
|
14
|
-
assert_valid schema, { "a" => 5 }
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_symbol_keys
|
18
|
-
schema = {
|
19
|
-
:type => 'object',
|
20
|
-
:required => ["a"],
|
21
|
-
:properties => {
|
22
|
-
:a => {:type => "integer", :default => 42},
|
23
|
-
:b => {:type => "integer"}
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
assert_valid schema, { :a => 5 }
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_symbol_keys_in_hash_within_array
|
31
|
-
schema = {
|
32
|
-
:type => 'object',
|
33
|
-
:properties => {
|
34
|
-
:a => {
|
35
|
-
:type => "array",
|
36
|
-
:items => [
|
37
|
-
{
|
38
|
-
:properties => {
|
39
|
-
:b => {
|
40
|
-
:type => "integer"
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
]
|
45
|
-
}
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
data = {
|
50
|
-
:a => [
|
51
|
-
{
|
52
|
-
:b => 1
|
53
|
-
}
|
54
|
-
]
|
55
|
-
}
|
56
|
-
|
57
|
-
assert_valid schema, data, :validate_schema => true
|
58
|
-
end
|
59
|
-
end
|
data/test/test_schema_loader.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class TestSchemaReader < Minitest::Test
|
4
|
-
ADDRESS_SCHEMA_URI = 'http://json-schema.org/address'
|
5
|
-
ADDRESS_SCHEMA_PATH = File.expand_path('../schemas/address_microformat.json', __FILE__)
|
6
|
-
|
7
|
-
def stub_address_request(body = File.read(ADDRESS_SCHEMA_PATH))
|
8
|
-
stub_request(:get, ADDRESS_SCHEMA_URI).
|
9
|
-
to_return(:body => body, :status => 200)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_accept_all_uris
|
13
|
-
stub_address_request
|
14
|
-
|
15
|
-
reader = JSON::Schema::Reader.new
|
16
|
-
schema = reader.read(ADDRESS_SCHEMA_URI)
|
17
|
-
|
18
|
-
assert_equal schema.uri, Addressable::URI.parse("#{ADDRESS_SCHEMA_URI}#")
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_accept_all_files
|
22
|
-
reader = JSON::Schema::Reader.new
|
23
|
-
schema = reader.read(ADDRESS_SCHEMA_PATH)
|
24
|
-
|
25
|
-
assert_equal schema.uri, Addressable::URI.convert_path(ADDRESS_SCHEMA_PATH + '#')
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_refuse_all_uris
|
29
|
-
reader = JSON::Schema::Reader.new(:accept_uri => false)
|
30
|
-
refute reader.accept_uri?(Addressable::URI.parse('http://foo.com'))
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_refuse_all_files
|
34
|
-
reader = JSON::Schema::Reader.new(:accept_file => false)
|
35
|
-
refute reader.accept_file?(Pathname.new('/foo/bar/baz'))
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_accept_uri_proc
|
39
|
-
reader = JSON::Schema::Reader.new(
|
40
|
-
:accept_uri => proc { |uri| uri.host == 'json-schema.org' }
|
41
|
-
)
|
42
|
-
|
43
|
-
assert reader.accept_uri?(Addressable::URI.parse('http://json-schema.org/address'))
|
44
|
-
refute reader.accept_uri?(Addressable::URI.parse('http://sub.json-schema.org/address'))
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_accept_file_proc
|
48
|
-
test_root = Pathname.new(__FILE__).expand_path.dirname
|
49
|
-
|
50
|
-
reader = JSON::Schema::Reader.new(
|
51
|
-
:accept_file => proc { |path| path.to_s.start_with?(test_root.to_s) }
|
52
|
-
)
|
53
|
-
|
54
|
-
assert reader.accept_file?(test_root.join('anything.json'))
|
55
|
-
refute reader.accept_file?(test_root.join('..', 'anything.json'))
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_file_scheme
|
59
|
-
reader = JSON::Schema::Reader.new(:accept_uri => true, :accept_file => false)
|
60
|
-
assert_raises(JSON::Schema::ReadRefused) do
|
61
|
-
reader.read('file://' + ADDRESS_SCHEMA_PATH)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_parse_error
|
66
|
-
stub_address_request('this is totally not valid JSON!')
|
67
|
-
|
68
|
-
reader = JSON::Schema::Reader.new
|
69
|
-
|
70
|
-
assert_raises(parser_error) do
|
71
|
-
reader.read(ADDRESS_SCHEMA_URI)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class TestSchemaTypeAttribute < Minitest::Test
|
4
|
-
def test_type_of_data
|
5
|
-
assert_equal(type_of_data(String.new), 'string')
|
6
|
-
assert_equal(type_of_data(Numeric.new), 'number')
|
7
|
-
assert_equal(type_of_data(1), 'integer')
|
8
|
-
assert_equal(type_of_data(true), 'boolean')
|
9
|
-
assert_equal(type_of_data(false), 'boolean')
|
10
|
-
assert_equal(type_of_data(Hash.new), 'object')
|
11
|
-
assert_equal(type_of_data(nil), 'null')
|
12
|
-
assert_equal(type_of_data(Object.new), 'any')
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def type_of_data(data)
|
18
|
-
JSON::Schema::TypeAttribute.type_of_data(data)
|
19
|
-
end
|
20
|
-
end
|
@@ -1,185 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
require 'tmpdir'
|
3
|
-
|
4
|
-
class JSONSchemaValidation < Minitest::Test
|
5
|
-
def valid_schema_v3
|
6
|
-
{
|
7
|
-
"$schema" => "http://json-schema.org/draft-03/schema#",
|
8
|
-
"type" => "object",
|
9
|
-
"properties" => {
|
10
|
-
"b" => {
|
11
|
-
"required" => true
|
12
|
-
}
|
13
|
-
}
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
def invalid_schema_v3
|
18
|
-
{
|
19
|
-
"$schema" => "http://json-schema.org/draft-03/schema#",
|
20
|
-
"type" => "object",
|
21
|
-
"properties" => {
|
22
|
-
"b" => {
|
23
|
-
"required" => "true"
|
24
|
-
}
|
25
|
-
}
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
def valid_schema_v4
|
30
|
-
{
|
31
|
-
"$schema" => "http://json-schema.org/draft-04/schema#",
|
32
|
-
"type" => "object",
|
33
|
-
"required" => ["b"],
|
34
|
-
"properties" => {
|
35
|
-
}
|
36
|
-
}
|
37
|
-
end
|
38
|
-
|
39
|
-
def invalid_schema_v4
|
40
|
-
{
|
41
|
-
"$schema" => "http://json-schema.org/draft-04/schema#",
|
42
|
-
"type" => "object",
|
43
|
-
"required" => "b",
|
44
|
-
"properties" => {
|
45
|
-
}
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
def symbolized_schema
|
50
|
-
{
|
51
|
-
:type => :object,
|
52
|
-
:required => [
|
53
|
-
:id,
|
54
|
-
:name,
|
55
|
-
:real_name,
|
56
|
-
:role,
|
57
|
-
:website,
|
58
|
-
:biography,
|
59
|
-
:created_at,
|
60
|
-
:demographic
|
61
|
-
],
|
62
|
-
:properties => {
|
63
|
-
:id => {
|
64
|
-
:type => [
|
65
|
-
:integer
|
66
|
-
]
|
67
|
-
},
|
68
|
-
:name => {
|
69
|
-
:type => [
|
70
|
-
:string
|
71
|
-
]
|
72
|
-
},
|
73
|
-
:real_name => {
|
74
|
-
:type => [
|
75
|
-
:string
|
76
|
-
]
|
77
|
-
},
|
78
|
-
:role => {
|
79
|
-
:type => [
|
80
|
-
:string
|
81
|
-
]
|
82
|
-
},
|
83
|
-
:website => {
|
84
|
-
:type => [
|
85
|
-
:string,
|
86
|
-
:null
|
87
|
-
]
|
88
|
-
},
|
89
|
-
:created_at => {
|
90
|
-
:type => [
|
91
|
-
:string
|
92
|
-
]
|
93
|
-
},
|
94
|
-
:biography => {
|
95
|
-
:type => [
|
96
|
-
:string,
|
97
|
-
:null
|
98
|
-
]
|
99
|
-
}
|
100
|
-
},
|
101
|
-
:relationships => {
|
102
|
-
:demographic => {
|
103
|
-
:type => :object,
|
104
|
-
:required => [
|
105
|
-
:id,
|
106
|
-
:gender
|
107
|
-
],
|
108
|
-
:properties => {
|
109
|
-
:id => {
|
110
|
-
:type => [
|
111
|
-
:integer
|
112
|
-
]
|
113
|
-
},
|
114
|
-
:gender => {
|
115
|
-
:type => [
|
116
|
-
:string
|
117
|
-
]
|
118
|
-
}
|
119
|
-
}
|
120
|
-
}
|
121
|
-
}
|
122
|
-
}
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_draft03_validation
|
126
|
-
data = {"b" => {"a" => 5}}
|
127
|
-
assert(JSON::Validator.validate(valid_schema_v3,data,:validate_schema => true, :version => :draft3))
|
128
|
-
assert(!JSON::Validator.validate(invalid_schema_v3,data,:validate_schema => true, :version => :draft3))
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_validate_just_schema_draft03
|
132
|
-
errors = JSON::Validator.fully_validate_schema(valid_schema_v3, :version => :draft3)
|
133
|
-
assert_equal [], errors
|
134
|
-
|
135
|
-
errors = JSON::Validator.fully_validate_schema(invalid_schema_v3, :version => :draft3)
|
136
|
-
assert_equal 1, errors.size
|
137
|
-
assert_match(/the property .*required.*did not match/i, errors.first)
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
|
-
def test_draft04_validation
|
142
|
-
data = {"b" => {"a" => 5}}
|
143
|
-
assert(JSON::Validator.validate(valid_schema_v4,data,:validate_schema => true, :version => :draft4))
|
144
|
-
assert(!JSON::Validator.validate(invalid_schema_v4,data,:validate_schema => true, :version => :draft4))
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_validate_just_schema_draft04
|
148
|
-
errors = JSON::Validator.fully_validate_schema(valid_schema_v4, :version => :draft4)
|
149
|
-
assert_equal [], errors
|
150
|
-
|
151
|
-
errors = JSON::Validator.fully_validate_schema(invalid_schema_v4, :version => :draft4)
|
152
|
-
assert_equal 1, errors.size
|
153
|
-
assert_match(/the property .*required.*did not match/i, errors.first)
|
154
|
-
end
|
155
|
-
|
156
|
-
def test_validate_schema_3_without_version_option
|
157
|
-
data = {"b" => {"a" => 5}}
|
158
|
-
assert(JSON::Validator.validate(valid_schema_v3,data,:validate_schema => true))
|
159
|
-
assert(!JSON::Validator.validate(invalid_schema_v3,data,:validate_schema => true))
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_schema_validation_from_different_directory
|
163
|
-
Dir.mktmpdir do |tmpdir|
|
164
|
-
Dir.chdir(tmpdir) do
|
165
|
-
data = {"b" => {"a" => 5}}
|
166
|
-
assert(JSON::Validator.validate(valid_schema_v4,data,:validate_schema => true, :version => :draft4))
|
167
|
-
assert(!JSON::Validator.validate(invalid_schema_v4,data,:validate_schema => true, :version => :draft4))
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_validate_schema_with_symbol_keys
|
173
|
-
data = {
|
174
|
-
"created_at" => "2014-01-25T00:58:33-08:00",
|
175
|
-
"id" => 8517194300913402149003,
|
176
|
-
"name" => "chelsey",
|
177
|
-
"real_name" => "Mekhi Hegmann",
|
178
|
-
"website" => nil,
|
179
|
-
"role" => "user",
|
180
|
-
"biography" => nil,
|
181
|
-
"demographic" => nil
|
182
|
-
}
|
183
|
-
assert(JSON::Validator.validate!(symbolized_schema, data, :validate_schema => true))
|
184
|
-
end
|
185
|
-
end
|