jsi 0.2.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/CHANGELOG.md +36 -0
- data/LICENSE.md +613 -0
- data/README.md +153 -52
- data/lib/jsi/base.rb +485 -338
- data/lib/jsi/jsi_coder.rb +24 -18
- data/lib/jsi/metaschema.rb +7 -0
- data/lib/jsi/metaschema_node/bootstrap_schema.rb +100 -0
- data/lib/jsi/metaschema_node.rb +245 -0
- data/lib/jsi/pathed_node.rb +49 -46
- data/lib/jsi/ptr.rb +292 -0
- data/lib/jsi/schema/application/child_application/contains.rb +16 -0
- data/lib/jsi/schema/application/child_application/draft04.rb +22 -0
- data/lib/jsi/schema/application/child_application/draft06.rb +29 -0
- data/lib/jsi/schema/application/child_application/draft07.rb +29 -0
- data/lib/jsi/schema/application/child_application/items.rb +18 -0
- data/lib/jsi/schema/application/child_application/properties.rb +25 -0
- data/lib/jsi/schema/application/child_application.rb +40 -0
- data/lib/jsi/schema/application/draft04.rb +8 -0
- data/lib/jsi/schema/application/draft06.rb +8 -0
- data/lib/jsi/schema/application/draft07.rb +8 -0
- data/lib/jsi/schema/application/inplace_application/dependencies.rb +28 -0
- data/lib/jsi/schema/application/inplace_application/draft04.rb +26 -0
- data/lib/jsi/schema/application/inplace_application/draft06.rb +27 -0
- data/lib/jsi/schema/application/inplace_application/draft07.rb +33 -0
- data/lib/jsi/schema/application/inplace_application/ifthenelse.rb +20 -0
- data/lib/jsi/schema/application/inplace_application/ref.rb +18 -0
- data/lib/jsi/schema/application/inplace_application/someof.rb +29 -0
- data/lib/jsi/schema/application/inplace_application.rb +46 -0
- data/lib/jsi/schema/application.rb +12 -0
- data/lib/jsi/schema/draft04.rb +14 -0
- data/lib/jsi/schema/draft06.rb +14 -0
- data/lib/jsi/schema/draft07.rb +14 -0
- data/lib/jsi/schema/issue.rb +36 -0
- data/lib/jsi/schema/ref.rb +159 -0
- data/lib/jsi/schema/schema_ancestor_node.rb +119 -0
- data/lib/jsi/schema/validation/array.rb +69 -0
- data/lib/jsi/schema/validation/const.rb +20 -0
- data/lib/jsi/schema/validation/contains.rb +25 -0
- data/lib/jsi/schema/validation/core.rb +39 -0
- data/lib/jsi/schema/validation/dependencies.rb +49 -0
- data/lib/jsi/schema/validation/draft04/minmax.rb +91 -0
- data/lib/jsi/schema/validation/draft04.rb +112 -0
- data/lib/jsi/schema/validation/draft06.rb +122 -0
- data/lib/jsi/schema/validation/draft07.rb +159 -0
- data/lib/jsi/schema/validation/enum.rb +25 -0
- data/lib/jsi/schema/validation/ifthenelse.rb +46 -0
- data/lib/jsi/schema/validation/items.rb +54 -0
- data/lib/jsi/schema/validation/not.rb +20 -0
- data/lib/jsi/schema/validation/numeric.rb +121 -0
- data/lib/jsi/schema/validation/object.rb +45 -0
- data/lib/jsi/schema/validation/pattern.rb +34 -0
- data/lib/jsi/schema/validation/properties.rb +101 -0
- data/lib/jsi/schema/validation/property_names.rb +32 -0
- data/lib/jsi/schema/validation/ref.rb +40 -0
- data/lib/jsi/schema/validation/required.rb +27 -0
- data/lib/jsi/schema/validation/someof.rb +90 -0
- data/lib/jsi/schema/validation/string.rb +47 -0
- data/lib/jsi/schema/validation/type.rb +49 -0
- data/lib/jsi/schema/validation.rb +51 -0
- data/lib/jsi/schema.rb +528 -233
- data/lib/jsi/schema_classes.rb +238 -51
- data/lib/jsi/schema_registry.rb +141 -0
- data/lib/jsi/schema_set.rb +141 -0
- data/lib/jsi/simple_wrap.rb +8 -3
- data/lib/jsi/typelike_modules.rb +75 -68
- data/lib/jsi/util/attr_struct.rb +106 -0
- data/lib/jsi/util.rb +167 -64
- data/lib/jsi/validation/error.rb +34 -0
- data/lib/jsi/validation/result.rb +210 -0
- data/lib/jsi/validation.rb +15 -0
- data/lib/jsi/version.rb +3 -1
- data/lib/jsi.rb +72 -9
- data/lib/schemas/json-schema.org/draft-04/schema.rb +12 -0
- data/lib/schemas/json-schema.org/draft-06/schema.rb +12 -0
- data/lib/schemas/json-schema.org/draft-07/schema.rb +12 -0
- data/readme.rb +138 -0
- data/{resources}/schemas/json-schema.org/draft-04/schema.json +149 -0
- data/{resources}/schemas/json-schema.org/draft-06/schema.json +154 -0
- data/{resources}/schemas/json-schema.org/draft-07/schema.json +168 -0
- metadata +80 -107
- data/.simplecov +0 -1
- data/LICENSE.txt +0 -21
- data/Rakefile.rb +0 -9
- data/jsi.gemspec +0 -31
- data/lib/jsi/base/to_rb.rb +0 -126
- data/lib/jsi/json/node.rb +0 -243
- data/lib/jsi/json/pointer.rb +0 -330
- data/lib/jsi/json-schema-fragments.rb +0 -59
- data/lib/jsi/json.rb +0 -8
- data/test/base_array_test.rb +0 -209
- data/test/base_hash_test.rb +0 -204
- data/test/base_test.rb +0 -422
- data/test/jsi_coder_test.rb +0 -85
- data/test/jsi_json_arraynode_test.rb +0 -150
- data/test/jsi_json_hashnode_test.rb +0 -132
- data/test/jsi_json_node_test.rb +0 -310
- data/test/jsi_json_pointer_test.rb +0 -106
- data/test/jsi_test.rb +0 -11
- data/test/jsi_typelike_as_json_test.rb +0 -53
- data/test/schema_test.rb +0 -196
- data/test/spreedly_openapi_test.rb +0 -8
- data/test/test_helper.rb +0 -63
- data/test/util_test.rb +0 -62
data/test/test_helper.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'coveralls'
|
2
|
-
if Coveralls.will_run?
|
3
|
-
Coveralls.wear!
|
4
|
-
end
|
5
|
-
require 'simplecov'
|
6
|
-
|
7
|
-
require 'byebug'
|
8
|
-
|
9
|
-
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
10
|
-
require 'jsi'
|
11
|
-
|
12
|
-
# NO EXPECTATIONS
|
13
|
-
ENV["MT_NO_EXPECTATIONS"] = ''
|
14
|
-
|
15
|
-
require 'minitest/autorun'
|
16
|
-
require 'minitest/around/spec'
|
17
|
-
require 'minitest/reporters'
|
18
|
-
|
19
|
-
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
20
|
-
|
21
|
-
class JSISpec < Minitest::Spec
|
22
|
-
if ENV['JSI_TEST_ALPHA']
|
23
|
-
# :nocov:
|
24
|
-
define_singleton_method(:test_order) { :alpha }
|
25
|
-
# :nocov:
|
26
|
-
end
|
27
|
-
|
28
|
-
def assert_equal exp, act, msg = nil
|
29
|
-
msg = message(msg, E) { diff exp, act }
|
30
|
-
assert exp == act, msg
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# register this to be the base class for specs instead of Minitest::Spec
|
35
|
-
Minitest::Spec.register_spec_type(//, JSISpec)
|
36
|
-
|
37
|
-
# tests support of things that duck-type #to_hash
|
38
|
-
class SortOfHash
|
39
|
-
def initialize(hash)
|
40
|
-
@hash = hash
|
41
|
-
end
|
42
|
-
def to_hash
|
43
|
-
@hash
|
44
|
-
end
|
45
|
-
include JSI::FingerprintHash
|
46
|
-
def fingerprint
|
47
|
-
{class: self.class, hash: @hash}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# tests support of things that duck-type #to_ary
|
52
|
-
class SortOfArray
|
53
|
-
def initialize(ary)
|
54
|
-
@ary = ary
|
55
|
-
end
|
56
|
-
def to_ary
|
57
|
-
@ary
|
58
|
-
end
|
59
|
-
include JSI::FingerprintHash
|
60
|
-
def fingerprint
|
61
|
-
{class: self.class, ary: @ary}
|
62
|
-
end
|
63
|
-
end
|
data/test/util_test.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
|
3
|
-
describe JSI::Util do
|
4
|
-
describe '.stringify_symbol_keys' do
|
5
|
-
it 'stringifies symbol hash keys' do
|
6
|
-
assert_equal({'a' => 'b', 'c' => 'd', nil => 3}, JSI.stringify_symbol_keys({a: 'b', 'c' => 'd', nil => 3}))
|
7
|
-
end
|
8
|
-
it 'stringifies HashNode keys' do
|
9
|
-
actual = JSI.stringify_symbol_keys(JSI::JSON::Node.new_doc({a: 'b', 'c' => 'd', nil => 3}))
|
10
|
-
expected = JSI::JSON::Node.new_doc({'a' => 'b', 'c' => 'd', nil => 3})
|
11
|
-
assert_equal(expected, actual)
|
12
|
-
end
|
13
|
-
it 'stringifies JSI hash keys' do
|
14
|
-
klass = JSI.class_for_schema(type: 'object')
|
15
|
-
expected = JSI.stringify_symbol_keys(klass.new(JSI::JSON::Node.new_doc({a: 'b', 'c' => 'd', nil => 3})))
|
16
|
-
actual = klass.new(JSI::JSON::Node.new_doc({'a' => 'b', 'c' => 'd', nil => 3}))
|
17
|
-
assert_equal(expected, actual)
|
18
|
-
end
|
19
|
-
describe 'non-hash-like argument' do
|
20
|
-
it 'errors' do
|
21
|
-
err = assert_raises(ArgumentError) { JSI.stringify_symbol_keys(nil) }
|
22
|
-
assert_equal("expected argument to be a hash; got NilClass: nil", err.message)
|
23
|
-
err = assert_raises(ArgumentError) { JSI.stringify_symbol_keys(JSI::JSON::Node.new_doc(3)) }
|
24
|
-
assert_equal("expected argument to be a hash; got JSI::JSON::Node: #<JSI::JSON::Node fragment=\"#\" 3>", err.message)
|
25
|
-
err = assert_raises(ArgumentError) { JSI.stringify_symbol_keys(JSI.class_for_schema({}).new(JSI::JSON::Node.new_doc(3))) }
|
26
|
-
assert_match(%r(\Aexpected argument to be a hash; got JSI::SchemaClasses\["[^"]+#"\]: #<JSI::SchemaClasses\["[^"]+#"\]\n #<JSI::JSON::Node fragment="#" 3>\n>\z)m, err.message)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
describe '.deep_stringify_symbol_keys' do
|
31
|
-
it 'stringifies symbol hash keys' do
|
32
|
-
actual = JSI.deep_stringify_symbol_keys({
|
33
|
-
a: 'b',
|
34
|
-
'c' => [
|
35
|
-
{d: true},
|
36
|
-
[{'e' => 0}],
|
37
|
-
],
|
38
|
-
nil => 3,
|
39
|
-
})
|
40
|
-
expected = {
|
41
|
-
'a' => 'b',
|
42
|
-
'c' => [
|
43
|
-
{'d' => true},
|
44
|
-
[{'e' => 0}],
|
45
|
-
],
|
46
|
-
nil => 3,
|
47
|
-
}
|
48
|
-
assert_equal(expected, actual)
|
49
|
-
end
|
50
|
-
it 'deep stringifies HashNode keys' do
|
51
|
-
actual = JSI.deep_stringify_symbol_keys(JSI::JSON::Node.new_doc({a: 'b', 'c' => {d: 0}, nil => 3}))
|
52
|
-
expected = JSI::JSON::Node.new_doc({'a' => 'b', 'c' => {'d' => 0}, nil => 3})
|
53
|
-
assert_equal(expected, actual)
|
54
|
-
end
|
55
|
-
it 'deep stringifies JSI instance' do
|
56
|
-
klass = JSI.class_for_schema(type: 'object')
|
57
|
-
actual = JSI.deep_stringify_symbol_keys(klass.new(JSI::JSON::Node.new_doc({a: 'b', 'c' => {d: 0}, nil => 3})))
|
58
|
-
expected = klass.new(JSI::JSON::Node.new_doc({'a' => 'b', 'c' => {'d' => 0}, nil => 3}))
|
59
|
-
assert_equal(expected, actual)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|