jschema 0.1.0 → 0.1.1
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/lib/jschema/simple_validator.rb +1 -1
- data/lib/jschema/validator/maximum.rb +1 -1
- data/lib/jschema/validator/minimum.rb +1 -1
- data/lib/jschema/validator/multiple_of.rb +1 -1
- data/lib/jschema/validator/required.rb +5 -5
- data/lib/jschema/validator/type.rb +13 -5
- data/test/test_schema.rb +10 -0
- data/test/validator/test_simple_validator.rb +8 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d590fc0ec0125af0eddda1de53da9dacae3531ed
|
4
|
+
data.tar.gz: fac78348f9d9bc7a044b109e1c0402a6b572cf78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3622b6dca13c53afe5454d08fead0af4aebcb3103f86f6d75c9119f79131ea2f6a7704d8f85f9da111adaa3b8d27328383a0663082d844073aaa7497bc4aed10
|
7
|
+
data.tar.gz: 744703a630e62f1aae528778c01332709fb83ea8383f4fbfe0a6c8346d6d5346a24c47eac6e45130b5a0eec3245a5d153bcc0e14793964ba3d593c3fc7f68c30
|
@@ -18,11 +18,11 @@ module JSchema
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def validate_instance(instance)
|
21
|
-
@required
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
21
|
+
missing_keys = @required - instance.keys
|
22
|
+
unless missing_keys.empty?
|
23
|
+
keys = missing_keys.map(&:inspect).join(', ')
|
24
|
+
"#{instance} must contain #{keys}"
|
25
|
+
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def valid_required?(required)
|
@@ -17,11 +17,11 @@ module JSchema
|
|
17
17
|
@json_types = Array(type)
|
18
18
|
@ruby_classes = @json_types.map do |json_type|
|
19
19
|
json_type_to_ruby_class(json_type)
|
20
|
-
end
|
20
|
+
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def validate_instance(instance)
|
24
|
-
unless @ruby_classes.one? { |type|
|
24
|
+
unless @ruby_classes.one? { |type| type === instance }
|
25
25
|
error_message(instance)
|
26
26
|
end
|
27
27
|
end
|
@@ -31,10 +31,10 @@ module JSchema
|
|
31
31
|
when 'object' then Hash
|
32
32
|
when 'null' then NilClass
|
33
33
|
when 'string' then String
|
34
|
-
when 'integer' then
|
34
|
+
when 'integer' then Integer
|
35
35
|
when 'array' then Array
|
36
|
-
when 'boolean' then
|
37
|
-
when 'number' then
|
36
|
+
when 'boolean' then Boolean
|
37
|
+
when 'number' then Numeric
|
38
38
|
else invalid_schema('type', json_type)
|
39
39
|
end
|
40
40
|
end
|
@@ -52,6 +52,14 @@ module JSchema
|
|
52
52
|
|
53
53
|
"#{instance.inspect} must be a #{types}"
|
54
54
|
end
|
55
|
+
|
56
|
+
module Boolean
|
57
|
+
class << self
|
58
|
+
def ===(other)
|
59
|
+
other == true || other == false || super
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
55
63
|
end
|
56
64
|
end
|
57
65
|
end
|
data/test/test_schema.rb
CHANGED
@@ -82,6 +82,16 @@ class TestSchema < Minitest::Test
|
|
82
82
|
assert_equal schema_def_uri, definition.uri
|
83
83
|
end
|
84
84
|
|
85
|
+
# TODO: Make it isolated.
|
86
|
+
def test_definitions
|
87
|
+
schema = JSchema::Schema.build(
|
88
|
+
'definitions' => { 'schema1' => {} },
|
89
|
+
'$ref' => '#/definitions/schema1'
|
90
|
+
)
|
91
|
+
|
92
|
+
schema.valid?('')
|
93
|
+
end
|
94
|
+
|
85
95
|
def test_that_exception_is_raised_when_schema_version_is_not_supported
|
86
96
|
assert_raises(JSchema::InvalidSchema) do
|
87
97
|
JSchema::Schema.build('$schema' => 'unsupported')
|
@@ -76,12 +76,19 @@ class TestSimpleValidator < Minitest::Test
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
def
|
79
|
+
def test_failing_validation_when_validator_is_applicable
|
80
80
|
stub_validator [Fixnum], false do |vdr|
|
81
81
|
refute vdr.valid?(0)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
def test_failing_validation_when_instance_is_descendant_of_applicable_types
|
86
|
+
stub_validator [Hash], false do |vdr|
|
87
|
+
descendant_type = Class.new(Hash)
|
88
|
+
refute vdr.valid?(descendant_type.new)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
85
92
|
private
|
86
93
|
|
87
94
|
def stub_validator(applicable_types, valid)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jschema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Papkovskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Implementation of JSON Schema Draft 4
|
14
14
|
email: konstantin@papkovskiy.com
|