jschema 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jschema/json_reference.rb +1 -1
- data/lib/jschema/schema_uri.rb +6 -2
- data/lib/jschema/simple_validator.rb +3 -3
- data/lib/jschema/string_length_validator.rb +2 -2
- data/lib/jschema/validator/dependencies.rb +2 -2
- data/lib/jschema/validator/format.rb +7 -3
- data/lib/jschema/validator/items.rb +2 -2
- data/lib/jschema/validator/max_items.rb +2 -2
- data/lib/jschema/validator/max_properties.rb +2 -2
- data/lib/jschema/validator/maximum.rb +2 -2
- data/lib/jschema/validator/min_items.rb +2 -2
- data/lib/jschema/validator/min_properties.rb +2 -2
- data/lib/jschema/validator/minimum.rb +2 -2
- data/lib/jschema/validator/multiple_of.rb +2 -2
- data/lib/jschema/validator/pattern.rb +2 -2
- data/lib/jschema/validator/properties.rb +2 -2
- data/lib/jschema/validator/required.rb +2 -2
- data/lib/jschema/validator/unique_items.rb +2 -2
- metadata +4 -78
- data/test/assert_received.rb +0 -15
- data/test/string_length_validator_tests.rb +0 -18
- data/test/test_assert_received.rb +0 -39
- data/test/test_integration.rb +0 -30
- data/test/test_json_reference.rb +0 -115
- data/test/test_schema.rb +0 -132
- data/test/test_schema_ref.rb +0 -19
- data/test/test_schema_uri.rb +0 -56
- data/test/test_validator.rb +0 -29
- data/test/validator/argument_is_array_of_schemas_tests.rb +0 -22
- data/test/validator/assertions.rb +0 -56
- data/test/validator/properties_limit_tests.rb +0 -13
- data/test/validator/schema_validation_helpers.rb +0 -29
- data/test/validator/test_all_of.rb +0 -30
- data/test/validator/test_any_of.rb +0 -31
- data/test/validator/test_dependencies.rb +0 -106
- data/test/validator/test_enum.rb +0 -30
- data/test/validator/test_format.rb +0 -78
- data/test/validator/test_items.rb +0 -119
- data/test/validator/test_max_items.rb +0 -26
- data/test/validator/test_max_length.rb +0 -30
- data/test/validator/test_max_properties.rb +0 -29
- data/test/validator/test_maximum.rb +0 -58
- data/test/validator/test_min_items.rb +0 -27
- data/test/validator/test_min_length.rb +0 -30
- data/test/validator/test_min_properties.rb +0 -29
- data/test/validator/test_minimum.rb +0 -58
- data/test/validator/test_multiple_of.rb +0 -38
- data/test/validator/test_not.rb +0 -32
- data/test/validator/test_one_of.rb +0 -31
- data/test/validator/test_pattern.rb +0 -32
- data/test/validator/test_properties.rb +0 -128
- data/test/validator/test_required.rb +0 -30
- data/test/validator/test_simple_validator.rb +0 -107
- data/test/validator/test_type.rb +0 -97
- data/test/validator/test_unique_items.rb +0 -30
- data/test/validator/validation_against_schemas_tests.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5975d1ffb59b9a5adaaaa4155bfa277ee36c18d
|
4
|
+
data.tar.gz: b159e075f06114b2beebfdafd78e4e991600bd6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d363449dfdeba0d314bec5da9229c230d5d5b23d52552983218f92e9792c75cda7369fa201b80b5085d2273cf572955742b709d9d5f230bbbf7fe5312df6246
|
7
|
+
data.tar.gz: 063973f04bed0d87bd855d5111160817122c701f1465bb838bd0448881ad293aa4114df1b8d0e9767096ba175c8daf465617a6c48daac27310a9acad5d9c53cb
|
@@ -65,7 +65,7 @@ module JSchema
|
|
65
65
|
schema_data = JSON.parse download_schema(uri)
|
66
66
|
parent_schema = schema && schema.parent
|
67
67
|
Schema.build(schema_data, parent_schema, uri.to_s)
|
68
|
-
rescue JSON::ParserError, Timeout::Error
|
68
|
+
rescue JSON::ParserError, Timeout::Error, Errno::ECONNREFUSED
|
69
69
|
raise InvalidSchema, "Failed to download external schema: #{uri}"
|
70
70
|
end
|
71
71
|
|
data/lib/jschema/schema_uri.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'webrick/httputils'
|
2
|
+
|
1
3
|
module JSchema
|
2
4
|
class SchemaURI
|
3
5
|
class << self
|
@@ -29,8 +31,10 @@ module JSchema
|
|
29
31
|
|
30
32
|
def uri(uri_string)
|
31
33
|
# NOTE: We need to escape % because URI class does not allow such
|
32
|
-
# characters within URI fragment (which is wrong).
|
33
|
-
URI
|
34
|
+
# characters within URI fragment (which is wrong). Originally I used
|
35
|
+
# URI.escape(str, '%'), but this method has become obsolete.
|
36
|
+
escaped_uri = WEBrick::HTTPUtils._escape(uri_string, /([%])/)
|
37
|
+
URI(escaped_uri)
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
@@ -6,7 +6,7 @@ module JSchema
|
|
6
6
|
new(*args, parent) unless args.compact.empty?
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
private
|
10
10
|
|
11
11
|
attr_accessor :keywords
|
12
12
|
end
|
@@ -28,7 +28,7 @@ module JSchema
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def validate(instance)
|
31
|
-
if !
|
31
|
+
if !applicable_type || instance.is_a?(applicable_type)
|
32
32
|
validate_instance(instance)
|
33
33
|
end
|
34
34
|
end
|
@@ -36,7 +36,7 @@ module JSchema
|
|
36
36
|
private
|
37
37
|
|
38
38
|
# Hook method
|
39
|
-
def
|
39
|
+
def applicable_type; end
|
40
40
|
|
41
41
|
def invalid_schema(keyword, value)
|
42
42
|
fail InvalidSchema, "Invalid `#{keyword}` value: #{value.inspect}"
|
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'date'
|
1
2
|
require 'ipaddr'
|
3
|
+
require 'webrick/httputils'
|
2
4
|
|
3
5
|
module JSchema
|
4
6
|
module Validator
|
@@ -28,8 +30,8 @@ module JSchema
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
|
-
def
|
32
|
-
|
33
|
+
def applicable_type
|
34
|
+
String
|
33
35
|
end
|
34
36
|
|
35
37
|
def date_time(instance)
|
@@ -66,7 +68,9 @@ module JSchema
|
|
66
68
|
end
|
67
69
|
|
68
70
|
def uri(instance)
|
69
|
-
URI.
|
71
|
+
# NOTE: Since URI.escape is obsolete I had to use
|
72
|
+
# WEBrick::HTTPUtils.escape
|
73
|
+
URI.parse WEBrick::HTTPUtils.escape(instance)
|
70
74
|
rescue URI::InvalidURIError
|
71
75
|
false
|
72
76
|
end
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Papkovskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Implementation of JSON Schema Draft 4
|
14
14
|
email: konstantin@papkovskiy.com
|
@@ -47,43 +47,6 @@ files:
|
|
47
47
|
- lib/jschema/validator/required.rb
|
48
48
|
- lib/jschema/validator/type.rb
|
49
49
|
- lib/jschema/validator/unique_items.rb
|
50
|
-
- test/assert_received.rb
|
51
|
-
- test/string_length_validator_tests.rb
|
52
|
-
- test/test_assert_received.rb
|
53
|
-
- test/test_integration.rb
|
54
|
-
- test/test_json_reference.rb
|
55
|
-
- test/test_schema.rb
|
56
|
-
- test/test_schema_ref.rb
|
57
|
-
- test/test_schema_uri.rb
|
58
|
-
- test/test_validator.rb
|
59
|
-
- test/validator/argument_is_array_of_schemas_tests.rb
|
60
|
-
- test/validator/assertions.rb
|
61
|
-
- test/validator/properties_limit_tests.rb
|
62
|
-
- test/validator/schema_validation_helpers.rb
|
63
|
-
- test/validator/test_all_of.rb
|
64
|
-
- test/validator/test_any_of.rb
|
65
|
-
- test/validator/test_dependencies.rb
|
66
|
-
- test/validator/test_enum.rb
|
67
|
-
- test/validator/test_format.rb
|
68
|
-
- test/validator/test_items.rb
|
69
|
-
- test/validator/test_max_items.rb
|
70
|
-
- test/validator/test_max_length.rb
|
71
|
-
- test/validator/test_max_properties.rb
|
72
|
-
- test/validator/test_maximum.rb
|
73
|
-
- test/validator/test_min_items.rb
|
74
|
-
- test/validator/test_min_length.rb
|
75
|
-
- test/validator/test_min_properties.rb
|
76
|
-
- test/validator/test_minimum.rb
|
77
|
-
- test/validator/test_multiple_of.rb
|
78
|
-
- test/validator/test_not.rb
|
79
|
-
- test/validator/test_one_of.rb
|
80
|
-
- test/validator/test_pattern.rb
|
81
|
-
- test/validator/test_properties.rb
|
82
|
-
- test/validator/test_required.rb
|
83
|
-
- test/validator/test_simple_validator.rb
|
84
|
-
- test/validator/test_type.rb
|
85
|
-
- test/validator/test_unique_items.rb
|
86
|
-
- test/validator/validation_against_schemas_tests.rb
|
87
50
|
homepage: http://github.com/Soylent/jschema
|
88
51
|
licenses:
|
89
52
|
- MIT
|
@@ -104,45 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
67
|
version: '0'
|
105
68
|
requirements: []
|
106
69
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
70
|
+
rubygems_version: 2.5.0
|
108
71
|
signing_key:
|
109
72
|
specification_version: 4
|
110
73
|
summary: JSON Schema implementation
|
111
|
-
test_files:
|
112
|
-
- test/assert_received.rb
|
113
|
-
- test/string_length_validator_tests.rb
|
114
|
-
- test/test_assert_received.rb
|
115
|
-
- test/test_integration.rb
|
116
|
-
- test/test_json_reference.rb
|
117
|
-
- test/test_schema.rb
|
118
|
-
- test/test_schema_ref.rb
|
119
|
-
- test/test_schema_uri.rb
|
120
|
-
- test/test_validator.rb
|
121
|
-
- test/validator/argument_is_array_of_schemas_tests.rb
|
122
|
-
- test/validator/assertions.rb
|
123
|
-
- test/validator/properties_limit_tests.rb
|
124
|
-
- test/validator/schema_validation_helpers.rb
|
125
|
-
- test/validator/test_all_of.rb
|
126
|
-
- test/validator/test_any_of.rb
|
127
|
-
- test/validator/test_dependencies.rb
|
128
|
-
- test/validator/test_enum.rb
|
129
|
-
- test/validator/test_format.rb
|
130
|
-
- test/validator/test_items.rb
|
131
|
-
- test/validator/test_max_items.rb
|
132
|
-
- test/validator/test_max_length.rb
|
133
|
-
- test/validator/test_max_properties.rb
|
134
|
-
- test/validator/test_maximum.rb
|
135
|
-
- test/validator/test_min_items.rb
|
136
|
-
- test/validator/test_min_length.rb
|
137
|
-
- test/validator/test_min_properties.rb
|
138
|
-
- test/validator/test_minimum.rb
|
139
|
-
- test/validator/test_multiple_of.rb
|
140
|
-
- test/validator/test_not.rb
|
141
|
-
- test/validator/test_one_of.rb
|
142
|
-
- test/validator/test_pattern.rb
|
143
|
-
- test/validator/test_properties.rb
|
144
|
-
- test/validator/test_required.rb
|
145
|
-
- test/validator/test_simple_validator.rb
|
146
|
-
- test/validator/test_type.rb
|
147
|
-
- test/validator/test_unique_items.rb
|
148
|
-
- test/validator/validation_against_schemas_tests.rb
|
74
|
+
test_files: []
|
data/test/assert_received.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module MiniTest
|
2
|
-
module Assertions
|
3
|
-
def assert_received(receiver, message, args = [])
|
4
|
-
mock = MiniTest::Mock.new
|
5
|
-
mock.expect(message, nil, args)
|
6
|
-
receiver_stub = ->(*arg) { mock.__send__ message, *arg }
|
7
|
-
|
8
|
-
receiver.stub message, receiver_stub do
|
9
|
-
yield if block_given?
|
10
|
-
end
|
11
|
-
|
12
|
-
mock.verify
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module StringLengthValidatorTests
|
2
|
-
def test_that_argument_can_be_big_integer
|
3
|
-
validator(2**64)
|
4
|
-
end
|
5
|
-
|
6
|
-
def test_that_argument_is_integer
|
7
|
-
assert_raises(JSchema::InvalidSchema) { validator('invalid') }
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_that_argument_is_not_null
|
11
|
-
assert_raises(JSchema::InvalidSchema) { validator(nil) }
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_that_validation_always_passes_for_non_string_instances
|
15
|
-
assert validator(1).valid?(nil)
|
16
|
-
assert validator(1).valid?([1, 2])
|
17
|
-
end
|
18
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require_relative 'assert_received'
|
3
|
-
|
4
|
-
class TestAssertReceived < Minitest::Test
|
5
|
-
def test_message_sending_without_params
|
6
|
-
assert_received(Object, :class) do
|
7
|
-
Object.class
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_message_sending_with_params
|
12
|
-
assert_received(String, :==, [Fixnum]) do
|
13
|
-
String == Fixnum
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_assertion_failure_when_message_is_not_received
|
18
|
-
assert_raises(MockExpectationError) do
|
19
|
-
assert_received(String, :class) do
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_assertion_failure_when_unexpected_message_is_received
|
25
|
-
assert_raises(MockExpectationError) do
|
26
|
-
assert_received(String, :class) do
|
27
|
-
String.name
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_assertion_failure_when_unexpected_params_are_received
|
33
|
-
assert_raises(MockExpectationError) do
|
34
|
-
assert_received(String, :==, [Fixnum]) do
|
35
|
-
String == Bignum
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|