json-schema 2.2.5 → 2.3.0
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 +8 -8
- data/README.textile +1 -1
- data/lib/json-schema.rb +1 -0
- data/lib/json-schema/attribute.rb +43 -0
- data/lib/json-schema/attributes/additionalitems.rb +3 -1
- data/lib/json-schema/attributes/additionalproperties.rb +1 -0
- data/lib/json-schema/attributes/allof.rb +6 -4
- data/lib/json-schema/attributes/anyof.rb +7 -5
- data/lib/json-schema/attributes/dependencies.rb +3 -1
- data/lib/json-schema/attributes/dependencies_v4.rb +3 -1
- data/lib/json-schema/attributes/disallow.rb +3 -1
- data/lib/json-schema/attributes/divisibleby.rb +3 -1
- data/lib/json-schema/attributes/enum.rb +3 -1
- data/lib/json-schema/attributes/extends.rb +1 -0
- data/lib/json-schema/attributes/format.rb +6 -112
- data/lib/json-schema/attributes/formats/custom.rb +22 -0
- data/lib/json-schema/attributes/formats/date.rb +25 -0
- data/lib/json-schema/attributes/formats/date_time.rb +35 -0
- data/lib/json-schema/attributes/formats/ip4.rb +22 -0
- data/lib/json-schema/attributes/formats/ip6.rb +30 -0
- data/lib/json-schema/attributes/formats/time.rb +22 -0
- data/lib/json-schema/attributes/formats/uri.rb +18 -0
- data/lib/json-schema/attributes/items.rb +3 -1
- data/lib/json-schema/attributes/maxdecimal.rb +3 -1
- data/lib/json-schema/attributes/maximum.rb +3 -1
- data/lib/json-schema/attributes/maximum_inclusive.rb +2 -0
- data/lib/json-schema/attributes/maxitems.rb +2 -0
- data/lib/json-schema/attributes/maxlength.rb +3 -1
- data/lib/json-schema/attributes/maxproperties.rb +3 -1
- data/lib/json-schema/attributes/minimum.rb +3 -1
- data/lib/json-schema/attributes/minimum_inclusive.rb +3 -1
- data/lib/json-schema/attributes/minitems.rb +4 -2
- data/lib/json-schema/attributes/minlength.rb +3 -1
- data/lib/json-schema/attributes/minproperties.rb +3 -1
- data/lib/json-schema/attributes/multipleof.rb +3 -1
- data/lib/json-schema/attributes/not.rb +3 -1
- data/lib/json-schema/attributes/oneof.rb +2 -0
- data/lib/json-schema/attributes/pattern.rb +3 -1
- data/lib/json-schema/attributes/patternproperties.rb +3 -1
- data/lib/json-schema/attributes/properties.rb +4 -2
- data/lib/json-schema/attributes/properties_optional.rb +3 -1
- data/lib/json-schema/attributes/properties_v4.rb +2 -0
- data/lib/json-schema/attributes/ref.rb +3 -0
- data/lib/json-schema/attributes/required.rb +2 -0
- data/lib/json-schema/attributes/type.rb +6 -20
- data/lib/json-schema/attributes/type_v4.rb +3 -21
- data/lib/json-schema/attributes/uniqueitems.rb +3 -1
- data/lib/json-schema/errors/custom_format_error.rb +6 -0
- data/lib/json-schema/errors/json_parse_error.rb +6 -0
- data/lib/json-schema/errors/schema_error.rb +6 -0
- data/lib/json-schema/errors/validation_error.rb +46 -0
- data/lib/json-schema/schema.rb +1 -5
- data/lib/json-schema/schema/validator.rb +31 -0
- data/lib/json-schema/validator.rb +61 -126
- data/lib/json-schema/validators/draft1.rb +14 -1
- data/lib/json-schema/validators/draft2.rb +14 -1
- data/lib/json-schema/validators/draft3.rb +14 -2
- data/lib/json-schema/validators/draft4.rb +12 -1
- data/test/test_all_of_ref_schema.rb +29 -2
- data/test/test_any_of_ref_schema.rb +26 -0
- data/test/test_bad_schema_ref.rb +2 -2
- data/test/test_common_test_suite.rb +53 -0
- data/test/test_custom_format.rb +117 -0
- data/test/test_jsonschema_draft1.rb +12 -0
- data/test/test_jsonschema_draft2.rb +12 -0
- data/test/test_jsonschema_draft3.rb +31 -0
- data/test/test_jsonschema_draft4.rb +14 -48
- data/test/test_minitems.rb +18 -0
- metadata +21 -4
- data/test/test_suite.rb +0 -71
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'json-schema/schema/validator'
|
2
|
+
|
1
3
|
module JSON
|
2
4
|
class Schema
|
3
5
|
|
@@ -34,7 +36,16 @@ module JSON
|
|
34
36
|
"extends" => JSON::Schema::ExtendsAttribute,
|
35
37
|
"$ref" => JSON::Schema::RefAttribute
|
36
38
|
}
|
39
|
+
@default_formats = {
|
40
|
+
'date-time' => DateTimeFormat,
|
41
|
+
'ipv4' => IP4Format,
|
42
|
+
'ipv6' => IP6Format,
|
43
|
+
'uri' => UriFormat
|
44
|
+
}
|
45
|
+
@formats = @default_formats.clone
|
37
46
|
@uri = URI.parse("http://json-schema.org/draft-04/schema#")
|
47
|
+
@names = ["draft4", "http://json-schema.org/draft-04/schema#"]
|
48
|
+
@metaschema = File.join("resources", "draft-04.json")
|
38
49
|
end
|
39
50
|
|
40
51
|
JSON::Validator.register_validator(self.new)
|
@@ -42,4 +53,4 @@ module JSON
|
|
42
53
|
end
|
43
54
|
|
44
55
|
end
|
45
|
-
end
|
56
|
+
end
|
@@ -1,11 +1,38 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require File.dirname(__FILE__) + '/../lib/json-schema'
|
3
3
|
|
4
|
-
class
|
5
|
-
def
|
4
|
+
class AllOfRefSchemaTest < Test::Unit::TestCase
|
5
|
+
def test_all_of_ref_schema_fails
|
6
6
|
schema = File.join(File.dirname(__FILE__),"schemas/all_of_ref_schema.json")
|
7
7
|
data = File.join(File.dirname(__FILE__),"data/all_of_ref_data.json")
|
8
8
|
errors = JSON::Validator.fully_validate(schema,data, :errors_as_objects => true)
|
9
9
|
assert(!errors.empty?, "should have failed to validate")
|
10
10
|
end
|
11
|
+
|
12
|
+
def test_all_of_ref_schema_succeeds
|
13
|
+
schema = File.join(File.dirname(__FILE__),"schemas/all_of_ref_schema.json")
|
14
|
+
data = %({"name": 42})
|
15
|
+
errors = JSON::Validator.fully_validate(schema,data, :errors_as_objects => true)
|
16
|
+
assert(errors.empty?, "should have validated")
|
17
|
+
end
|
18
|
+
|
19
|
+
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
|
+
errors = JSON::Validator.fully_validate(schema, data, :errors_as_objects => true)
|
23
|
+
nested_errors = errors[0][:errors]
|
24
|
+
assert_equal([:allof_0], nested_errors.keys, 'should have nested errors for each allOf subschema')
|
25
|
+
assert_match(/the property '#\/name' of type String did not match the following type: integer/i, nested_errors[:allof_0][0][:message])
|
26
|
+
end
|
27
|
+
|
28
|
+
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
|
+
errors = JSON::Validator.fully_validate(schema, data)
|
32
|
+
expected_message = """The property '#/' of type Hash did not match all of the required schemas. The schema specific errors were:
|
33
|
+
|
34
|
+
- allOf #0:
|
35
|
+
- The property '#/name' of type String did not match the following type: integer"""
|
36
|
+
assert_equal(expected_message, errors[0])
|
37
|
+
end
|
11
38
|
end
|
@@ -8,4 +8,30 @@ class AnyOfRefSchemaTest < Test::Unit::TestCase
|
|
8
8
|
errors = JSON::Validator.fully_validate(schema,data, :errors_as_objects => true)
|
9
9
|
assert(errors.empty?, errors.map{|e| e[:message] }.join("\n"))
|
10
10
|
end
|
11
|
+
|
12
|
+
def test_any_of_ref_subschema_errors
|
13
|
+
schema = File.join(File.dirname(__FILE__),'schemas/any_of_ref_schema.json')
|
14
|
+
data = %({"names": ["jack"]})
|
15
|
+
errors = JSON::Validator.fully_validate(schema, data, :errors_as_objects => true)
|
16
|
+
nested_errors = errors[0][:errors]
|
17
|
+
assert_equal([:anyof_0, :anyof_1, :anyof_2], nested_errors.keys, 'should have nested errors for each anyOf subschema')
|
18
|
+
assert_match(/the property '#\/names\/0' value "jack" did not match the regex 'john'/i, nested_errors[:anyof_0][0][:message])
|
19
|
+
assert_match(/the property '#\/names\/0' value "jack" did not match the regex 'jane'/i, nested_errors[:anyof_1][0][:message])
|
20
|
+
assert_match(/the property '#\/names\/0' value "jack" did not match the regex 'jimmy'/i, nested_errors[:anyof_2][0][:message])
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_any_of_ref_message
|
24
|
+
schema = File.join(File.dirname(__FILE__),'schemas/any_of_ref_schema.json')
|
25
|
+
data = %({"names": ["jack"]})
|
26
|
+
errors = JSON::Validator.fully_validate(schema, data)
|
27
|
+
expected_message = """The property '#/names/0' of type String did not match one or more of the required schemas. The schema specific errors were:
|
28
|
+
|
29
|
+
- anyOf #0:
|
30
|
+
- The property '#/names/0' value \"jack\" did not match the regex 'john'
|
31
|
+
- anyOf #1:
|
32
|
+
- The property '#/names/0' value \"jack\" did not match the regex 'jane'
|
33
|
+
- anyOf #2:
|
34
|
+
- The property '#/names/0' value \"jack\" did not match the regex 'jimmy'"""
|
35
|
+
assert_equal(expected_message, errors[0])
|
36
|
+
end
|
11
37
|
end
|
data/test/test_bad_schema_ref.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.expand_path('../../lib/json-schema', __FILE__)
|
3
|
+
|
4
|
+
class CommonTestSuiteTest < Test::Unit::TestCase
|
5
|
+
TEST_DIR = File.expand_path('../test-suite/tests', __FILE__)
|
6
|
+
|
7
|
+
# These are test files which we know fail spectacularly, either because
|
8
|
+
# we don't support that functionality or because they require external
|
9
|
+
# dependencies
|
10
|
+
IGNORED_TESTS = [
|
11
|
+
"draft3/disallow.json",
|
12
|
+
"draft3/optional/format.json",
|
13
|
+
"draft3/optional/jsregex.json",
|
14
|
+
"draft3/ref.json",
|
15
|
+
"draft3/refRemote.json",
|
16
|
+
"draft4/dependencies.json",
|
17
|
+
"draft4/optional/format.json",
|
18
|
+
"draft4/ref.json",
|
19
|
+
"draft4/refRemote.json",
|
20
|
+
]
|
21
|
+
|
22
|
+
Dir["#{TEST_DIR}/*"].each do |suite|
|
23
|
+
version = File.basename(suite).to_sym
|
24
|
+
Dir["#{suite}/**/*.json"].each do |tfile|
|
25
|
+
test_list = JSON::Validator.parse(File.read(tfile))
|
26
|
+
rel_file = tfile[TEST_DIR.length+1..-1]
|
27
|
+
|
28
|
+
test_list.each do |test|
|
29
|
+
schema = test["schema"]
|
30
|
+
base_description = test["description"]
|
31
|
+
v = nil
|
32
|
+
|
33
|
+
test["tests"].each do |t|
|
34
|
+
err_id = "#{rel_file}, '#{base_description}'/'#{t['description']}'"
|
35
|
+
|
36
|
+
define_method("test_#{err_id}") do
|
37
|
+
skip "Known incompatibility with common test suite" if IGNORED_TESTS.include?(rel_file)
|
38
|
+
|
39
|
+
assert_nothing_raised("Exception raised running #{err_id}") do
|
40
|
+
v = JSON::Validator.fully_validate(schema,
|
41
|
+
t["data"],
|
42
|
+
:validate_schema => true,
|
43
|
+
:version => version
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
assert v.empty? == t["valid"], "Common test suite case failed: #{err_id}\n#{v}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../lib/json-schema'
|
4
|
+
|
5
|
+
class JSONSchemaCustomFormatTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@all_versions = ['draft1', 'draft2', 'draft3', 'draft4']
|
8
|
+
@format_proc = -> value { raise JSON::Schema::CustomFormatError.new("must be 42") unless value == "42" }
|
9
|
+
@schema_4 = {
|
10
|
+
"$schema" => "http://json-schema.org/draft-04/schema#",
|
11
|
+
"properties" => {
|
12
|
+
"a" => {
|
13
|
+
"type" => "string",
|
14
|
+
"format" => "custom",
|
15
|
+
},
|
16
|
+
}
|
17
|
+
}
|
18
|
+
@schema_3 = @schema_4.clone
|
19
|
+
@schema_3["$schema"] = "http://json-schema.org/draft-03/schema#"
|
20
|
+
@schema_2 = @schema_4.clone
|
21
|
+
@schema_2["$schema"] = "http://json-schema.org/draft-02/schema#"
|
22
|
+
@schema_1 = @schema_4.clone
|
23
|
+
@schema_1["$schema"] = "http://json-schema.org/draft-01/schema#"
|
24
|
+
@schemas = {
|
25
|
+
"draft1" => @schema_1,
|
26
|
+
"draft2" => @schema_2,
|
27
|
+
"draft3" => @schema_3,
|
28
|
+
"draft4" => @schema_4
|
29
|
+
}
|
30
|
+
JSON::Validator.restore_default_formats
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_single_registration
|
34
|
+
@all_versions.each do |version|
|
35
|
+
assert(JSON::Validator.validator_for_name(version).formats['custom'].nil?, "Format 'custom' for #{version} should be nil")
|
36
|
+
JSON::Validator.register_format_validator("custom", @format_proc, [version])
|
37
|
+
assert(JSON::Validator.validator_for_name(version).formats['custom'].is_a?(JSON::Schema::CustomFormat), "Format 'custom' should be registered for #{version}")
|
38
|
+
(@all_versions - [version]).each do |other_version|
|
39
|
+
assert(JSON::Validator.validator_for_name(other_version).formats['custom'].nil?, "Format 'custom' should still be nil for #{other_version}")
|
40
|
+
end
|
41
|
+
JSON::Validator.deregister_format_validator("custom", [version])
|
42
|
+
assert(JSON::Validator.validator_for_name(version).formats['custom'].nil?, "Format 'custom' should be deregistered for #{version}")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_register_for_all_by_default
|
47
|
+
JSON::Validator.register_format_validator("custom", @format_proc)
|
48
|
+
@all_versions.each do |version|
|
49
|
+
assert(JSON::Validator.validator_for_name(version).formats['custom'].is_a?(JSON::Schema::CustomFormat), "Format 'custom' should be registered for #{version}")
|
50
|
+
end
|
51
|
+
JSON::Validator.restore_default_formats
|
52
|
+
@all_versions.each do |version|
|
53
|
+
assert(JSON::Validator.validator_for_name(version).formats['custom'].nil?, "Format 'custom' should still be nil for #{version}")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_multi_registration
|
58
|
+
unregistered_version = @all_versions.delete("draft1")
|
59
|
+
JSON::Validator.register_format_validator("custom", @format_proc, @all_versions)
|
60
|
+
@all_versions.each do |version|
|
61
|
+
assert(JSON::Validator.validator_for_name(version).formats['custom'].is_a?(JSON::Schema::CustomFormat), "Format 'custom' should be registered for #{version}")
|
62
|
+
end
|
63
|
+
assert(JSON::Validator.validator_for_name(unregistered_version).formats['custom'].nil?, "Format 'custom' should still be nil for #{unregistered_version}")
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_format_validation
|
67
|
+
@all_versions.each do |version|
|
68
|
+
data = {
|
69
|
+
"a" => "23"
|
70
|
+
}
|
71
|
+
schema = @schemas[version]
|
72
|
+
prefix = "Validation for '#{version}'"
|
73
|
+
|
74
|
+
assert(JSON::Validator.validate(schema, data), "#{prefix} succeeds with no 'custom' format validator registered")
|
75
|
+
|
76
|
+
JSON::Validator.register_format_validator("custom", @format_proc, [version])
|
77
|
+
data["a"] = "42"
|
78
|
+
assert(JSON::Validator.validate(schema, data), "#{prefix} succeeds with 'custom' format validator and correct data")
|
79
|
+
|
80
|
+
data["a"] = "23"
|
81
|
+
assert(!JSON::Validator.validate(schema, data), "#{prefix} fails with 'custom' format validator and wrong data")
|
82
|
+
|
83
|
+
errors = JSON::Validator.fully_validate(schema, data)
|
84
|
+
assert(errors.count == 1 && errors.first.match(/The property '#\/a' must be 42 in schema/), "#{prefix} records fromat error")
|
85
|
+
|
86
|
+
data["a"] = 23
|
87
|
+
errors = JSON::Validator.fully_validate(schema, data)
|
88
|
+
assert(errors.count == 1 && errors.first.match(/The property '#\/a' of type (?:integer|Fixnum) did not match the following type: string/), "#{prefix} records no fromat error on type mismatch")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_override_default_format
|
93
|
+
@all_versions.each do |version|
|
94
|
+
data = {
|
95
|
+
"a" => "2001:db8:85a3:0:0:8a2e:370:7334"
|
96
|
+
}
|
97
|
+
schema = @schemas[version]
|
98
|
+
schema["properties"]["a"]["format"] = "ipv6"
|
99
|
+
prefix = "Validation for '#{version}'"
|
100
|
+
|
101
|
+
assert(JSON::Validator.validate(schema, data), "#{prefix} succeeds for default format with correct data")
|
102
|
+
|
103
|
+
data["a"] = "no_ip6_address"
|
104
|
+
assert(!JSON::Validator.validate(schema, data), "#{prefix} fails for default format and wrong data")
|
105
|
+
|
106
|
+
data["a"] = "42"
|
107
|
+
JSON::Validator.register_format_validator("ipv6", @format_proc, [version])
|
108
|
+
assert(JSON::Validator.validate(schema, data), "#{prefix} succeeds with overriden default format and correct data")
|
109
|
+
|
110
|
+
JSON::Validator.deregister_format_validator("ipv6", [version])
|
111
|
+
data["a"] = "2001:db8:85a3:0:0:8a2e:370:7334"
|
112
|
+
assert(JSON::Validator.validate(schema, data), "#{prefix} restores the default format on deregistration")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
|
@@ -684,6 +684,18 @@ class JSONSchemaDraft1Test < Test::Unit::TestCase
|
|
684
684
|
assert(!JSON::Validator.validate(schema,data,:version => :draft1))
|
685
685
|
end
|
686
686
|
|
687
|
+
def test_format_unknown
|
688
|
+
schema = {
|
689
|
+
"type" => "object",
|
690
|
+
"properties" => { "a" => {"type" => "string", "format" => "unknown"}}
|
691
|
+
}
|
692
|
+
|
693
|
+
data = {"a" => "I can write what I want here"}
|
694
|
+
assert(JSON::Validator.validate(schema,data,:version => :draft1))
|
695
|
+
data = {"a" => ""}
|
696
|
+
assert(JSON::Validator.validate(schema,data,:version => :draft1))
|
697
|
+
end
|
698
|
+
|
687
699
|
|
688
700
|
def test_format_union
|
689
701
|
data1 = {"a" => "boo"}
|
@@ -756,6 +756,18 @@ class JSONSchemaDraft2Test < Test::Unit::TestCase
|
|
756
756
|
assert(!JSON::Validator.validate(schema,data,:version => :draft2))
|
757
757
|
end
|
758
758
|
|
759
|
+
def test_format_unknown
|
760
|
+
schema = {
|
761
|
+
"type" => "object",
|
762
|
+
"properties" => { "a" => {"type" => "string", "format" => "unknown"}}
|
763
|
+
}
|
764
|
+
|
765
|
+
data = {"a" => "I can write what I want here"}
|
766
|
+
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
767
|
+
data = {"a" => ""}
|
768
|
+
assert(JSON::Validator.validate(schema,data,:version => :draft2))
|
769
|
+
end
|
770
|
+
|
759
771
|
|
760
772
|
def test_format_union
|
761
773
|
data1 = {"a" => "boo"}
|
@@ -503,6 +503,25 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
|
|
503
503
|
assert(!JSON::Validator.validate(schema,data,:strict => true))
|
504
504
|
end
|
505
505
|
|
506
|
+
def test_strict_properties_required_props
|
507
|
+
schema = {
|
508
|
+
"$schema" => "http://json-schema.org/draft-03/schema#",
|
509
|
+
"properties" => {
|
510
|
+
"a" => {"type" => "string", "required" => true},
|
511
|
+
"b" => {"type" => "string", "required" => false}
|
512
|
+
}
|
513
|
+
}
|
514
|
+
|
515
|
+
data = {"a" => "a"}
|
516
|
+
assert(JSON::Validator.validate(schema,data,:strict => true))
|
517
|
+
|
518
|
+
data = {"b" => "b"}
|
519
|
+
assert(!JSON::Validator.validate(schema,data,:strict => true))
|
520
|
+
|
521
|
+
data = {"a" => "a", "b" => "b"}
|
522
|
+
assert(JSON::Validator.validate(schema,data,:strict => true))
|
523
|
+
end
|
524
|
+
|
506
525
|
def test_strict_properties_additional_props
|
507
526
|
schema = {
|
508
527
|
"$schema" => "http://json-schema.org/draft-03/schema#",
|
@@ -1076,6 +1095,18 @@ class JSONSchemaDraft3Test < Test::Unit::TestCase
|
|
1076
1095
|
assert(JSON::Validator.validate(schema,data))
|
1077
1096
|
end
|
1078
1097
|
|
1098
|
+
def test_format_unknown
|
1099
|
+
schema = {
|
1100
|
+
"type" => "object",
|
1101
|
+
"properties" => { "a" => {"type" => "string", "format" => "unknown"}}
|
1102
|
+
}
|
1103
|
+
|
1104
|
+
data = {"a" => "I can write what I want here"}
|
1105
|
+
assert(JSON::Validator.validate(schema,data,:version => :draft3))
|
1106
|
+
data = {"a" => ""}
|
1107
|
+
assert(JSON::Validator.validate(schema,data,:version => :draft3))
|
1108
|
+
end
|
1109
|
+
|
1079
1110
|
|
1080
1111
|
def test_format_union
|
1081
1112
|
data1 = {"a" => "boo"}
|
@@ -887,7 +887,7 @@ class JSONSchemaDraft4Test < Test::Unit::TestCase
|
|
887
887
|
schema = {
|
888
888
|
"$schema" => "http://json-schema.org/draft-04/schema#",
|
889
889
|
"type" => "object",
|
890
|
-
"properties" => { "a" => {"type" => "string", "format" => "
|
890
|
+
"properties" => { "a" => {"type" => "string", "format" => "ipv4"}}
|
891
891
|
}
|
892
892
|
|
893
893
|
data = {"a" => "1.1.1.1"}
|
@@ -929,52 +929,6 @@ class JSONSchemaDraft4Test < Test::Unit::TestCase
|
|
929
929
|
assert(!JSON::Validator.validate(schema,data))
|
930
930
|
end
|
931
931
|
|
932
|
-
def test_format_time
|
933
|
-
schema = {
|
934
|
-
"$schema" => "http://json-schema.org/draft-04/schema#",
|
935
|
-
"type" => "object",
|
936
|
-
"properties" => { "a" => {"type" => "string", "format" => "time"}}
|
937
|
-
}
|
938
|
-
|
939
|
-
data = {"a" => "12:00:00"}
|
940
|
-
assert(JSON::Validator.validate(schema,data))
|
941
|
-
data = {"a" => "12:00"}
|
942
|
-
assert(!JSON::Validator.validate(schema,data))
|
943
|
-
data = {"a" => "12:00:60"}
|
944
|
-
assert(!JSON::Validator.validate(schema,data))
|
945
|
-
data = {"a" => "12:60:00"}
|
946
|
-
assert(!JSON::Validator.validate(schema,data))
|
947
|
-
data = {"a" => "24:00:00"}
|
948
|
-
assert(!JSON::Validator.validate(schema,data))
|
949
|
-
data = {"a" => "0:00:00"}
|
950
|
-
assert(!JSON::Validator.validate(schema,data))
|
951
|
-
data = {"a" => "-12:00:00"}
|
952
|
-
assert(!JSON::Validator.validate(schema,data))
|
953
|
-
data = {"a" => "12:00:00b"}
|
954
|
-
assert(!JSON::Validator.validate(schema,data))
|
955
|
-
end
|
956
|
-
|
957
|
-
|
958
|
-
def test_format_date
|
959
|
-
schema = {
|
960
|
-
"$schema" => "http://json-schema.org/draft-04/schema#",
|
961
|
-
"type" => "object",
|
962
|
-
"properties" => { "a" => {"type" => "string", "format" => "date"}}
|
963
|
-
}
|
964
|
-
|
965
|
-
data = {"a" => "2010-01-01"}
|
966
|
-
assert(JSON::Validator.validate(schema,data))
|
967
|
-
data = {"a" => "2010-01-32"}
|
968
|
-
assert(!JSON::Validator.validate(schema,data))
|
969
|
-
data = {"a" => "n2010-01-01"}
|
970
|
-
assert(!JSON::Validator.validate(schema,data))
|
971
|
-
data = {"a" => "2010-1-01"}
|
972
|
-
assert(!JSON::Validator.validate(schema,data))
|
973
|
-
data = {"a" => "2010-01-1"}
|
974
|
-
assert(!JSON::Validator.validate(schema,data))
|
975
|
-
data = {"a" => "2010-01-01n"}
|
976
|
-
assert(!JSON::Validator.validate(schema,data))
|
977
|
-
end
|
978
932
|
|
979
933
|
def test_format_datetime
|
980
934
|
schema = {
|
@@ -1025,6 +979,18 @@ class JSONSchemaDraft4Test < Test::Unit::TestCase
|
|
1025
979
|
assert(JSON::Validator.validate(schema,data3))
|
1026
980
|
end
|
1027
981
|
|
982
|
+
def test_format_unknown
|
983
|
+
schema = {
|
984
|
+
"type" => "object",
|
985
|
+
"properties" => { "a" => {"type" => "string", "format" => "unknown"}}
|
986
|
+
}
|
987
|
+
|
988
|
+
data = {"a" => "I can write what I want here"}
|
989
|
+
assert(JSON::Validator.validate(schema,data,:version => :draft4))
|
990
|
+
data = {"a" => ""}
|
991
|
+
assert(JSON::Validator.validate(schema,data,:version => :draft4))
|
992
|
+
end
|
993
|
+
|
1028
994
|
|
1029
995
|
def test_format_union
|
1030
996
|
data1 = {"a" => "boo"}
|
@@ -1033,7 +999,7 @@ class JSONSchemaDraft4Test < Test::Unit::TestCase
|
|
1033
999
|
schema = {
|
1034
1000
|
"$schema" => "http://json-schema.org/draft-04/schema#",
|
1035
1001
|
"type" => "object",
|
1036
|
-
"properties" => { "a" => {"type" => ["string","null"], "format" => "
|
1002
|
+
"properties" => { "a" => {"type" => ["string","null"], "format" => "ipv4"}}
|
1037
1003
|
}
|
1038
1004
|
assert(!JSON::Validator.validate(schema,data1))
|
1039
1005
|
assert(JSON::Validator.validate(schema,data2))
|