json_schema 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/lib/json_schema/schema_error.rb +25 -0
- data/lib/json_schema/validator.rb +1 -1
- data/test/json_schema/validator_test.rb +28 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbb33080285902b1c199cf2bcab85f200c0eb901
|
4
|
+
data.tar.gz: a07dd64354f889be4cd37b0aefd5b31fe504ed2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ab3e28e2872a54c2177ff6e0d6d0b47494fb2f8baad25b6e26a0aa9bba0adee5b87cc02bcc4d8689be633eb9ca8f400617205af7c156238a46f2917a363a359
|
7
|
+
data.tar.gz: 8370b05b74dcbfbb59d5d64b90d7211dcf3bc7f516f0a3dfd87b18efb04c05f92dae9abb545e763ba71ae81dbd40a9b1726222c43a1ae365530a483b41e5b3c6
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014-2015 Brandur and contributors
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -34,4 +34,29 @@ module JsonSchema
|
|
34
34
|
"#{pointer}: failed schema #{schema.pointer}: #{message}"
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
module ErrorFormatter
|
39
|
+
def to_list(list)
|
40
|
+
words_connector = ', '
|
41
|
+
two_words_connector = ' or '
|
42
|
+
last_word_connector = ', or '
|
43
|
+
|
44
|
+
length = list.length
|
45
|
+
joined_list = case length
|
46
|
+
when 1
|
47
|
+
list[0]
|
48
|
+
when 2
|
49
|
+
"#{list[0]}#{two_words_connector}#{list[1]}"
|
50
|
+
else
|
51
|
+
"#{list[0...-1].join(words_connector)}#{last_word_connector}#{list[-1]}"
|
52
|
+
end
|
53
|
+
|
54
|
+
if joined_list[0] =~ /^[aeiou]/
|
55
|
+
"an #{joined_list}"
|
56
|
+
else
|
57
|
+
"a #{joined_list}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
module_function :to_list
|
61
|
+
end
|
37
62
|
end
|
@@ -506,7 +506,7 @@ module JsonSchema
|
|
506
506
|
if valid_types.any? { |t| data.is_a?(t) }
|
507
507
|
true
|
508
508
|
else
|
509
|
-
message = %{#{data.inspect} is not
|
509
|
+
message = %{#{data.inspect} is not #{ErrorFormatter.to_list(schema.type)}.}
|
510
510
|
errors << ValidationError.new(schema, path, message, :invalid_type)
|
511
511
|
false
|
512
512
|
end
|
@@ -40,7 +40,33 @@ describe JsonSchema::Validator do
|
|
40
40
|
)
|
41
41
|
@data_sample = 4
|
42
42
|
refute validate
|
43
|
-
assert_includes error_messages, %{4 is not
|
43
|
+
assert_includes error_messages, %{4 is not an object.}
|
44
|
+
assert_includes error_types, :invalid_type
|
45
|
+
end
|
46
|
+
|
47
|
+
it "provides accurate error messages for multiple type errors" do
|
48
|
+
pointer("#/definitions/app").merge!(
|
49
|
+
"type" => ["string"]
|
50
|
+
)
|
51
|
+
@data_sample = 4
|
52
|
+
refute validate
|
53
|
+
assert_includes error_messages, %{4 is not a string.}
|
54
|
+
assert_includes error_types, :invalid_type
|
55
|
+
|
56
|
+
pointer("#/definitions/app").merge!(
|
57
|
+
"type" => ["string", "null"]
|
58
|
+
)
|
59
|
+
@data_sample = 4
|
60
|
+
refute validate
|
61
|
+
assert_includes error_messages, %{4 is not a string or null.}
|
62
|
+
assert_includes error_types, :invalid_type
|
63
|
+
|
64
|
+
pointer("#/definitions/app").merge!(
|
65
|
+
"type" => ["object", "null", "string"]
|
66
|
+
)
|
67
|
+
@data_sample = 4
|
68
|
+
refute validate
|
69
|
+
assert_includes error_messages, %{4 is not an object, null, or string.}
|
44
70
|
assert_includes error_types, :invalid_type
|
45
71
|
end
|
46
72
|
|
@@ -420,7 +446,7 @@ describe JsonSchema::Validator do
|
|
420
446
|
"KEY" => 456
|
421
447
|
}
|
422
448
|
refute validate
|
423
|
-
assert_includes error_messages, %{456 is not a null
|
449
|
+
assert_includes error_messages, %{456 is not a null or string.}
|
424
450
|
assert_includes error_types, :invalid_type
|
425
451
|
end
|
426
452
|
|
@@ -774,7 +800,6 @@ describe JsonSchema::Validator do
|
|
774
800
|
|
775
801
|
def validate
|
776
802
|
@schema = JsonSchema.parse!(schema_sample)
|
777
|
-
puts @schema.inspect
|
778
803
|
@schema.expand_references!
|
779
804
|
@schema = @schema.definitions["app"]
|
780
805
|
@validator = JsonSchema::Validator.new(@schema)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ecma-re-validator
|
@@ -60,6 +60,7 @@ executables:
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
+
- LICENSE
|
63
64
|
- README.md
|
64
65
|
- bin/validate-schema
|
65
66
|
- lib/commands/validate_schema.rb
|
@@ -111,4 +112,3 @@ signing_key:
|
|
111
112
|
specification_version: 4
|
112
113
|
summary: A JSON Schema V4 and Hyperschema V4 parser and validator.
|
113
114
|
test_files: []
|
114
|
-
has_rdoc:
|