json-schema 2.4.1 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/README.textile +58 -7
- data/lib/json-schema.rb +3 -1
- data/lib/json-schema/attributes/additionalitems.rb +14 -11
- data/lib/json-schema/attributes/additionalproperties.rb +33 -43
- data/lib/json-schema/attributes/anyof.rb +4 -0
- data/lib/json-schema/attributes/dependencies.rb +31 -19
- data/lib/json-schema/attributes/disallow.rb +2 -3
- data/lib/json-schema/attributes/divisibleby.rb +11 -7
- data/lib/json-schema/attributes/enum.rb +14 -16
- data/lib/json-schema/attributes/format.rb +4 -7
- data/lib/json-schema/attributes/formats/date_time_v4.rb +5 -8
- data/lib/json-schema/attributes/formats/ip.rb +41 -0
- data/lib/json-schema/attributes/formats/uri.rb +10 -8
- data/lib/json-schema/attributes/items.rb +15 -16
- data/lib/json-schema/attributes/limit.rb +179 -0
- data/lib/json-schema/attributes/maxdecimal.rb +7 -6
- data/lib/json-schema/attributes/multipleof.rb +4 -11
- data/lib/json-schema/attributes/not.rb +1 -1
- data/lib/json-schema/attributes/oneof.rb +15 -6
- data/lib/json-schema/attributes/pattern.rb +7 -6
- data/lib/json-schema/attributes/patternproperties.rb +9 -12
- data/lib/json-schema/attributes/properties.rb +55 -39
- data/lib/json-schema/attributes/properties_optional.rb +13 -12
- data/lib/json-schema/attributes/ref.rb +4 -4
- data/lib/json-schema/attributes/required.rb +16 -13
- data/lib/json-schema/attributes/type.rb +13 -18
- data/lib/json-schema/attributes/type_v4.rb +11 -18
- data/lib/json-schema/attributes/uniqueitems.rb +5 -7
- data/lib/json-schema/schema.rb +8 -8
- data/lib/json-schema/schema/#validator.rb# +37 -0
- data/lib/json-schema/schema/reader.rb +113 -0
- data/lib/json-schema/util/uri.rb +16 -0
- data/lib/json-schema/validator.rb +123 -128
- data/lib/json-schema/validators/draft1.rb +1 -1
- data/lib/json-schema/validators/draft2.rb +1 -1
- data/lib/json-schema/validators/draft3.rb +1 -1
- data/lib/json-schema/validators/draft4.rb +1 -1
- data/lib/json-schema/validators/hyper-draft4.rb +1 -1
- data/test/schemas/address_microformat.json +18 -0
- data/test/schemas/definition_schema.json +15 -0
- data/test/schemas/ref john with spaces schema.json +11 -0
- data/test/schemas/relative_definition_schema.json +8 -0
- data/test/test_all_of_ref_schema.rb +12 -15
- data/test/test_any_of_ref_schema.rb +7 -9
- data/test/test_bad_schema_ref.rb +18 -12
- data/test/test_common_test_suite.rb +45 -29
- data/test/test_custom_format.rb +2 -3
- data/test/test_definition.rb +15 -0
- data/test/test_extended_schema.rb +25 -31
- data/test/test_extends_and_additionalProperties.rb +23 -21
- data/test/test_files_v3.rb +14 -23
- data/test/test_fragment_resolution.rb +6 -7
- data/test/test_fragment_validation_with_ref.rb +2 -8
- data/test/test_full_validation.rb +2 -3
- data/test/test_helper.rb +46 -1
- data/test/test_initialize_data.rb +118 -0
- data/test/test_jsonschema_draft1.rb +48 -600
- data/test/test_jsonschema_draft2.rb +48 -699
- data/test/test_jsonschema_draft3.rb +91 -861
- data/test/test_jsonschema_draft4.rb +173 -812
- data/test/test_list_option.rb +6 -7
- data/test/{test_merge_misisng_values.rb → test_merge_missing_values.rb} +2 -3
- data/test/test_minitems.rb +2 -4
- data/test/test_one_of.rb +9 -19
- data/test/test_ruby_schema.rb +5 -14
- data/test/test_schema_loader.rb +74 -0
- data/test/test_schema_type_attribute.rb +2 -3
- data/test/test_schema_validation.rb +4 -5
- data/test/test_stringify.rb +2 -3
- data/test/test_uri_related.rb +67 -0
- data/test/test_validator.rb +53 -0
- metadata +129 -51
- data/lib/json-schema/attributes/dependencies_v4.rb +0 -27
- data/lib/json-schema/attributes/formats/ip4.rb +0 -20
- data/lib/json-schema/attributes/formats/ip6.rb +0 -20
- data/lib/json-schema/attributes/maximum.rb +0 -17
- data/lib/json-schema/attributes/maximum_inclusive.rb +0 -17
- data/lib/json-schema/attributes/maxitems.rb +0 -14
- data/lib/json-schema/attributes/maxlength.rb +0 -16
- data/lib/json-schema/attributes/maxproperties.rb +0 -14
- data/lib/json-schema/attributes/minimum.rb +0 -17
- data/lib/json-schema/attributes/minimum_inclusive.rb +0 -17
- data/lib/json-schema/attributes/minitems.rb +0 -14
- data/lib/json-schema/attributes/minlength.rb +0 -16
- data/lib/json-schema/attributes/minproperties.rb +0 -14
- data/lib/json-schema/attributes/properties_v4.rb +0 -58
- data/lib/json-schema/uri/file.rb +0 -36
@@ -33,7 +33,7 @@ module JSON
|
|
33
33
|
'uri' => UriFormat
|
34
34
|
}
|
35
35
|
@formats = @default_formats.clone
|
36
|
-
@uri = URI.parse("http://json-schema.org/draft-01/schema#")
|
36
|
+
@uri = Addressable::URI.parse("http://json-schema.org/draft-01/schema#")
|
37
37
|
@names = ["draft1"]
|
38
38
|
@metaschema_name = "draft-01.json"
|
39
39
|
end
|
@@ -34,7 +34,7 @@ module JSON
|
|
34
34
|
'uri' => UriFormat
|
35
35
|
}
|
36
36
|
@formats = @default_formats.clone
|
37
|
-
@uri = URI.parse("http://json-schema.org/draft-02/schema#")
|
37
|
+
@uri = Addressable::URI.parse("http://json-schema.org/draft-02/schema#")
|
38
38
|
@names = ["draft2"]
|
39
39
|
@metaschema_name = "draft-02.json"
|
40
40
|
end
|
@@ -38,7 +38,7 @@ module JSON
|
|
38
38
|
'uri' => UriFormat
|
39
39
|
}
|
40
40
|
@formats = @default_formats.clone
|
41
|
-
@uri = URI.parse("http://json-schema.org/draft-03/schema#")
|
41
|
+
@uri = Addressable::URI.parse("http://json-schema.org/draft-03/schema#")
|
42
42
|
@names = ["draft3", "http://json-schema.org/draft-03/schema#"]
|
43
43
|
@metaschema_name = "draft-03.json"
|
44
44
|
end
|
@@ -43,7 +43,7 @@ module JSON
|
|
43
43
|
'uri' => UriFormat
|
44
44
|
}
|
45
45
|
@formats = @default_formats.clone
|
46
|
-
@uri = URI.parse("http://json-schema.org/draft-04/schema#")
|
46
|
+
@uri = Addressable::URI.parse("http://json-schema.org/draft-04/schema#")
|
47
47
|
@names = ["draft4", "http://json-schema.org/draft-04/schema#"]
|
48
48
|
@metaschema_name = "draft-04.json"
|
49
49
|
end
|
@@ -4,7 +4,7 @@ module JSON
|
|
4
4
|
class HyperDraft4 < Draft4
|
5
5
|
def initialize
|
6
6
|
super
|
7
|
-
@uri = URI.parse("http://json-schema.org/draft-04/hyper-schema#")
|
7
|
+
@uri = Addressable::URI.parse("http://json-schema.org/draft-04/hyper-schema#")
|
8
8
|
end
|
9
9
|
|
10
10
|
JSON::Validator.register_validator(self.new)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"description": "An Address following the convention of http://microformats.org/wiki/hcard",
|
3
|
+
"type": "object",
|
4
|
+
"properties": {
|
5
|
+
"post-office-box": { "type": "string" },
|
6
|
+
"extended-address": { "type": "string" },
|
7
|
+
"street-address": { "type": "string" },
|
8
|
+
"locality":{ "type": "string" },
|
9
|
+
"region": { "type": "string" },
|
10
|
+
"postal-code": { "type": "string" },
|
11
|
+
"country-name": { "type": "string"}
|
12
|
+
},
|
13
|
+
"required": ["locality", "region", "country-name"],
|
14
|
+
"dependencies": {
|
15
|
+
"post-office-box": "street-address",
|
16
|
+
"extended-address": "street-address"
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
3
|
+
"description": "schema with definition",
|
4
|
+
"type": "object",
|
5
|
+
"properties": {
|
6
|
+
"a": {
|
7
|
+
"$ref": "#/definitions/foo"
|
8
|
+
}
|
9
|
+
},
|
10
|
+
"definitions": {
|
11
|
+
"foo": {
|
12
|
+
"type": "integer"
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
@@ -1,24 +1,23 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class AllOfRefSchemaTest < Minitest::Test
|
4
|
+
def schema
|
5
|
+
schema_fixture_path('all_of_ref_schema.json')
|
6
|
+
end
|
7
|
+
|
8
|
+
def data
|
9
|
+
data_fixture_path('all_of_ref_data.json')
|
10
|
+
end
|
3
11
|
|
4
|
-
class AllOfRefSchemaTest < Test::Unit::TestCase
|
5
12
|
def test_all_of_ref_schema_fails
|
6
|
-
schema
|
7
|
-
data = File.join(File.dirname(__FILE__),"data/all_of_ref_data.json")
|
8
|
-
errors = JSON::Validator.fully_validate(schema,data, :errors_as_objects => true)
|
9
|
-
assert(!errors.empty?, "should have failed to validate")
|
13
|
+
refute_valid schema, data
|
10
14
|
end
|
11
15
|
|
12
16
|
def test_all_of_ref_schema_succeeds
|
13
|
-
schema
|
14
|
-
data = %({"name": 42})
|
15
|
-
errors = JSON::Validator.fully_validate(schema,data, :errors_as_objects => true)
|
16
|
-
assert(errors.empty?, "should have validated")
|
17
|
+
assert_valid schema, %({"name": 42})
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_all_of_ref_subschema_errors
|
20
|
-
schema = File.join(File.dirname(__FILE__), 'schemas/all_of_ref_schema.json')
|
21
|
-
data = File.join(File.dirname(__FILE__), 'data/all_of_ref_data.json')
|
22
21
|
errors = JSON::Validator.fully_validate(schema, data, :errors_as_objects => true)
|
23
22
|
nested_errors = errors[0][:errors]
|
24
23
|
assert_equal([:allof_0], nested_errors.keys, 'should have nested errors for each allOf subschema')
|
@@ -26,8 +25,6 @@ class AllOfRefSchemaTest < Test::Unit::TestCase
|
|
26
25
|
end
|
27
26
|
|
28
27
|
def test_all_of_ref_message
|
29
|
-
schema = File.join(File.dirname(__FILE__), 'schemas/all_of_ref_schema.json')
|
30
|
-
data = File.join(File.dirname(__FILE__), 'data/all_of_ref_data.json')
|
31
28
|
errors = JSON::Validator.fully_validate(schema, data)
|
32
29
|
expected_message = """The property '#/' of type Hash did not match all of the required schemas. The schema specific errors were:
|
33
30
|
|
@@ -1,16 +1,15 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class AnyOfRefSchemaTest < Minitest::Test
|
4
|
+
def schema
|
5
|
+
schema_fixture_path('any_of_ref_schema.json')
|
6
|
+
end
|
3
7
|
|
4
|
-
class AnyOfRefSchemaTest < Test::Unit::TestCase
|
5
8
|
def test_any_of_ref_schema
|
6
|
-
schema
|
7
|
-
data = File.join(File.dirname(__FILE__),"data/any_of_ref_data.json")
|
8
|
-
errors = JSON::Validator.fully_validate(schema,data, :errors_as_objects => true)
|
9
|
-
assert(errors.empty?, errors.map{|e| e[:message] }.join("\n"))
|
9
|
+
assert_valid schema, data_fixture_path('any_of_ref_data.json')
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_any_of_ref_subschema_errors
|
13
|
-
schema = File.join(File.dirname(__FILE__),'schemas/any_of_ref_schema.json')
|
14
13
|
data = %({"names": ["jack"]})
|
15
14
|
errors = JSON::Validator.fully_validate(schema, data, :errors_as_objects => true)
|
16
15
|
nested_errors = errors[0][:errors]
|
@@ -21,7 +20,6 @@ class AnyOfRefSchemaTest < Test::Unit::TestCase
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def test_any_of_ref_message
|
24
|
-
schema = File.join(File.dirname(__FILE__),'schemas/any_of_ref_schema.json')
|
25
23
|
data = %({"names": ["jack"]})
|
26
24
|
errors = JSON::Validator.fully_validate(schema, data)
|
27
25
|
expected_message = """The property '#/names/0' of type String did not match one or more of the required schemas. The schema specific errors were:
|
data/test/test_bad_schema_ref.rb
CHANGED
@@ -1,33 +1,39 @@
|
|
1
|
-
require '
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
2
|
require 'socket'
|
3
|
-
require File.dirname(__FILE__) + '/../lib/json-schema'
|
4
3
|
|
5
|
-
|
4
|
+
|
5
|
+
class BadSchemaRefTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
WebMock.allow_net_connect!
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
WebMock.disable_net_connect!
|
12
|
+
end
|
6
13
|
|
7
14
|
def test_bad_uri_ref
|
8
15
|
schema = {
|
9
|
-
|
10
|
-
|
11
|
-
|
16
|
+
"$schema" => "http://json-schema.org/draft-04/schema#",
|
17
|
+
"type" => "array",
|
18
|
+
"items" => { "$ref" => "../google.json"}
|
12
19
|
}
|
13
20
|
|
14
21
|
data = [1,2,3]
|
15
|
-
|
22
|
+
assert_raises(Errno::ENOENT) do
|
16
23
|
JSON::Validator.validate(schema,data)
|
17
24
|
end
|
18
25
|
end
|
19
26
|
|
20
27
|
def test_bad_host_ref
|
21
28
|
schema = {
|
22
|
-
|
23
|
-
|
24
|
-
|
29
|
+
"$schema" => "http://json-schema.org/draft-04/schema#",
|
30
|
+
"type" => "array",
|
31
|
+
"items" => { "$ref" => "http://ppcheesecheseunicornnuuuurrrrr.example.invalid/json.schema"}
|
25
32
|
}
|
26
33
|
|
27
34
|
data = [1,2,3]
|
28
|
-
|
35
|
+
assert_raises(SocketError, OpenURI::HTTPError) do
|
29
36
|
JSON::Validator.validate(schema,data)
|
30
37
|
end
|
31
38
|
end
|
32
|
-
|
33
39
|
end
|
@@ -1,47 +1,63 @@
|
|
1
|
-
require '
|
2
|
-
require
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
require 'json'
|
3
3
|
|
4
|
-
class CommonTestSuiteTest < Test
|
4
|
+
class CommonTestSuiteTest < Minitest::Test
|
5
5
|
TEST_DIR = File.expand_path('../test-suite/tests', __FILE__)
|
6
6
|
|
7
|
-
# These are test files which we know fail spectacularly, either because
|
8
|
-
#
|
9
|
-
# dependencies
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
"draft3/optional/jsregex.json",
|
14
|
-
"draft3/
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
# These are test files which we know fail spectacularly, either because we
|
8
|
+
# don't support that functionality or because they require external
|
9
|
+
# dependencies. To allow finer-grained control over which tests to run,
|
10
|
+
# you can replace `:all` with an array containing the names of individual
|
11
|
+
# tests to skip.
|
12
|
+
IGNORED_TESTS = Hash.new { |h,k| h[k] = [] }.merge({
|
13
|
+
"draft3/optional/jsregex.json" => :all,
|
14
|
+
"draft3/optional/format.json" => [
|
15
|
+
"validation of regular expressions",
|
16
|
+
"validation of e-mail addresses",
|
17
|
+
"validation of URIs",
|
18
|
+
"validation of host names",
|
19
|
+
"validation of CSS colors"
|
20
|
+
],
|
21
|
+
"draft4/optional/format.json" => [
|
22
|
+
"validation of URIs",
|
23
|
+
"validation of e-mail addresses",
|
24
|
+
"validation of host names"
|
25
|
+
]
|
26
|
+
})
|
27
|
+
|
28
|
+
def setup
|
29
|
+
Dir["#{TEST_DIR}/../remotes/**/*.json"].each do |path|
|
30
|
+
schema = path.sub(%r{^.*/remotes/}, '')
|
31
|
+
stub_request(:get, "http://localhost:1234/#{schema}").
|
32
|
+
to_return(:body => File.read(path), :status => 200)
|
33
|
+
end
|
34
|
+
end
|
18
35
|
|
19
36
|
Dir["#{TEST_DIR}/*"].each do |suite|
|
20
37
|
version = File.basename(suite).to_sym
|
21
38
|
Dir["#{suite}/**/*.json"].each do |tfile|
|
22
|
-
test_list = JSON
|
39
|
+
test_list = JSON.parse(File.read(tfile))
|
23
40
|
rel_file = tfile[TEST_DIR.length+1..-1]
|
24
41
|
|
25
42
|
test_list.each do |test|
|
26
43
|
schema = test["schema"]
|
27
44
|
base_description = test["description"]
|
28
|
-
v = nil
|
29
45
|
|
30
46
|
test["tests"].each do |t|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
assert_nothing_raised("Exception raised running #{err_id}") do
|
36
|
-
v = JSON::Validator.fully_validate(schema,
|
37
|
-
t["data"],
|
38
|
-
:validate_schema => true,
|
39
|
-
:version => version
|
40
|
-
)
|
41
|
-
end
|
47
|
+
next if IGNORED_TESTS[rel_file] == :all
|
48
|
+
next if IGNORED_TESTS[rel_file].any? { |ignored|
|
49
|
+
base_description == ignored || "#{base_description}/#{t['description']}" == ignored
|
50
|
+
}
|
42
51
|
|
43
|
-
|
44
|
-
|
52
|
+
err_id = "#{rel_file}: #{base_description}/#{t['description']}"
|
53
|
+
define_method("test_#{err_id}") do
|
54
|
+
errors = JSON::Validator.fully_validate(schema,
|
55
|
+
t["data"],
|
56
|
+
:parse_data => false,
|
57
|
+
:validate_schema => true,
|
58
|
+
:version => version
|
59
|
+
)
|
60
|
+
assert_equal t["valid"], errors.empty?, "Common test suite case failed: #{err_id}"
|
45
61
|
end
|
46
62
|
end
|
47
63
|
end
|
data/test/test_custom_format.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require '
|
3
|
-
require File.dirname(__FILE__) + '/../lib/json-schema'
|
2
|
+
require File.expand_path('../test_helper', __FILE__)
|
4
3
|
|
5
|
-
class JSONSchemaCustomFormatTest < Test
|
4
|
+
class JSONSchemaCustomFormatTest < Minitest::Test
|
6
5
|
def setup
|
7
6
|
@all_versions = ['draft1', 'draft2', 'draft3', 'draft4']
|
8
7
|
@format_proc = lambda { |value| raise JSON::Schema::CustomFormatError.new("must be 42") unless value == "42" }
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class RelativeDefinitionTest < Minitest::Test
|
4
|
+
|
5
|
+
def test_definition_schema
|
6
|
+
assert_valid schema_fixture_path('definition_schema.json'), {"a" => 5}
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_relative_definition
|
10
|
+
schema = schema_fixture_path('relative_definition_schema.json')
|
11
|
+
assert_valid schema, {"a" => 5}
|
12
|
+
refute_valid schema, {"a" => "foo"}
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -1,11 +1,12 @@
|
|
1
|
-
require '
|
2
|
-
require File.dirname(__FILE__) + '/../lib/json-schema'
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
3
2
|
|
4
3
|
class BitwiseAndAttribute < JSON::Schema::Attribute
|
5
4
|
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
return unless data.is_a?(Integer)
|
6
|
+
|
7
|
+
if data & current_schema.schema['bitwise-and'].to_i == 0
|
8
|
+
message = "The property '#{build_fragment(fragments)}' did not evaluate to true when bitwise-AND'd with #{current_schema.schema['bitwise-and']}"
|
9
|
+
validation_error(processor, message, fragments, current_schema, self, options[:record_errors])
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -15,16 +16,16 @@ class ExtendedSchema < JSON::Schema::Validator
|
|
15
16
|
super
|
16
17
|
extend_schema_definition("http://json-schema.org/draft-03/schema#")
|
17
18
|
@attributes["bitwise-and"] = BitwiseAndAttribute
|
18
|
-
@uri = URI.parse("http://test.com/test.json")
|
19
|
+
@uri = Addressable::URI.parse("http://test.com/test.json")
|
19
20
|
end
|
20
|
-
|
21
|
+
|
21
22
|
JSON::Validator.register_validator(self.new)
|
22
23
|
end
|
23
24
|
|
24
|
-
class
|
25
|
-
def
|
25
|
+
class TestExtendedSchema < Minitest::Test
|
26
|
+
def test_extended_schema_validation
|
26
27
|
schema = {
|
27
|
-
"$schema" => "http://
|
28
|
+
"$schema" => "http://test.com/test.json",
|
28
29
|
"properties" => {
|
29
30
|
"a" => {
|
30
31
|
"bitwise-and" => 1
|
@@ -34,16 +35,16 @@ class JSONSchemaTestExtendedSchema < Test::Unit::TestCase
|
|
34
35
|
}
|
35
36
|
}
|
36
37
|
}
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
|
39
|
+
assert_valid schema, {"a" => 1, "b" => "taco"}
|
40
|
+
refute_valid schema, {"a" => 0, "b" => "taco"}
|
41
|
+
refute_valid schema, {"a" => 1, "b" => 5}
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_unextended_schema
|
45
|
+
# Verify that using the original schema disregards the `bitwise-and` property
|
45
46
|
schema = {
|
46
|
-
"$schema" => "http://
|
47
|
+
"$schema" => "http://json-schema.org/draft-03/schema#",
|
47
48
|
"properties" => {
|
48
49
|
"a" => {
|
49
50
|
"bitwise-and" => 1
|
@@ -53,16 +54,9 @@ class JSONSchemaTestExtendedSchema < Test::Unit::TestCase
|
|
53
54
|
}
|
54
55
|
}
|
55
56
|
}
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
}
|
60
|
-
|
61
|
-
data = {"a" => 1, "b" => "taco"}
|
62
|
-
assert(JSON::Validator.validate(schema,data))
|
63
|
-
data = {"a" => 0, "b" => "taco"}
|
64
|
-
assert(!JSON::Validator.validate(schema,data))
|
65
|
-
data = {"a" => 1, "b" => 5}
|
66
|
-
assert(!JSON::Validator.validate(schema,data))
|
57
|
+
|
58
|
+
assert_valid schema, {"a" => 0, "b" => "taco"}
|
59
|
+
assert_valid schema, {"a" => 1, "b" => "taco"}
|
60
|
+
refute_valid schema, {"a" => 1, "b" => 5}
|
67
61
|
end
|
68
|
-
end
|
62
|
+
end
|
@@ -1,47 +1,49 @@
|
|
1
|
-
require '
|
2
|
-
require File.dirname(__FILE__) + '/../lib/json-schema'
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
3
2
|
|
4
|
-
class ExtendsNestedTest < Test
|
3
|
+
class ExtendsNestedTest < Minitest::Test
|
5
4
|
|
6
|
-
def assert_validity(valid, schema_name, data, msg
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
send (valid ? :assert_equal : :assert_not_equal), [], errors, \
|
11
|
-
"Schema should be #{valid ? :valid : :invalid}#{msg ? ".\n[#{schema_name}] #{msg}" : ''}"
|
12
|
-
end
|
5
|
+
def assert_validity(valid, schema_name, data, msg)
|
6
|
+
msg = "Schema should be #{valid ? :valid : :invalid}.\n(#{schema_name}) #{msg}"
|
7
|
+
schema = schema_fixture_path("#{schema_name}.schema.json")
|
8
|
+
errors = JSON::Validator.fully_validate(schema, data)
|
13
9
|
|
14
|
-
|
15
|
-
|
10
|
+
if valid
|
11
|
+
assert_equal([], errors, msg)
|
12
|
+
else
|
13
|
+
refute_equal([], errors, msg)
|
14
|
+
end
|
15
|
+
end
|
16
16
|
|
17
17
|
%w[
|
18
|
-
extends_and_additionalProperties-1-filename
|
19
|
-
extends_and_additionalProperties-
|
18
|
+
extends_and_additionalProperties-1-filename
|
19
|
+
extends_and_additionalProperties-1-ref
|
20
|
+
extends_and_additionalProperties-2-filename
|
21
|
+
extends_and_additionalProperties-2-ref
|
20
22
|
].each do |schema_name|
|
21
|
-
test_prefix= 'test_' + schema_name.gsub('-','_')
|
22
|
-
class_eval <<-EOB
|
23
|
+
test_prefix = 'test_' + schema_name.gsub('-','_')
|
23
24
|
|
25
|
+
class_eval <<-EOB
|
24
26
|
def #{test_prefix}_valid_outer
|
25
|
-
|
27
|
+
assert_validity true, '#{schema_name}', {"outerC"=>true}, "Outer defn is broken, maybe the outer extends overrode it"
|
26
28
|
end
|
27
29
|
|
28
30
|
def #{test_prefix}_valid_outer_extended
|
29
|
-
|
31
|
+
assert_validity true, '#{schema_name}', {"innerA"=>true}, "Extends at the root level isn't working"
|
30
32
|
end
|
31
33
|
|
32
34
|
def #{test_prefix}_valid_inner
|
33
|
-
|
35
|
+
assert_validity true, '#{schema_name}', {"outerB"=>[{"innerA"=>true}]}, "Extends isn't working in the array element defn"
|
34
36
|
end
|
35
37
|
|
36
38
|
def #{test_prefix}_invalid_inner
|
37
|
-
|
39
|
+
assert_validity false, '#{schema_name}', {"outerB"=>[{"whaaaaat"=>true}]}, "Array element defn allowing anything when it should only allow what's in inner.schema"
|
38
40
|
end
|
39
41
|
EOB
|
40
42
|
|
41
43
|
if schema_name['extends_and_additionalProperties-1']
|
42
44
|
class_eval <<-EOB
|
43
45
|
def #{test_prefix}_invalid_outer
|
44
|
-
|
46
|
+
assert_validity false, '#{schema_name}', {"whaaaaat"=>true}, "Outer defn allowing anything when it shouldn't"
|
45
47
|
end
|
46
48
|
EOB
|
47
49
|
end
|