jsi 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +36 -0
  4. data/LICENSE.md +613 -0
  5. data/README.md +153 -52
  6. data/lib/jsi/base.rb +485 -338
  7. data/lib/jsi/jsi_coder.rb +24 -18
  8. data/lib/jsi/metaschema.rb +7 -0
  9. data/lib/jsi/metaschema_node/bootstrap_schema.rb +100 -0
  10. data/lib/jsi/metaschema_node.rb +245 -0
  11. data/lib/jsi/pathed_node.rb +49 -46
  12. data/lib/jsi/ptr.rb +292 -0
  13. data/lib/jsi/schema/application/child_application/contains.rb +16 -0
  14. data/lib/jsi/schema/application/child_application/draft04.rb +22 -0
  15. data/lib/jsi/schema/application/child_application/draft06.rb +29 -0
  16. data/lib/jsi/schema/application/child_application/draft07.rb +29 -0
  17. data/lib/jsi/schema/application/child_application/items.rb +18 -0
  18. data/lib/jsi/schema/application/child_application/properties.rb +25 -0
  19. data/lib/jsi/schema/application/child_application.rb +40 -0
  20. data/lib/jsi/schema/application/draft04.rb +8 -0
  21. data/lib/jsi/schema/application/draft06.rb +8 -0
  22. data/lib/jsi/schema/application/draft07.rb +8 -0
  23. data/lib/jsi/schema/application/inplace_application/dependencies.rb +28 -0
  24. data/lib/jsi/schema/application/inplace_application/draft04.rb +26 -0
  25. data/lib/jsi/schema/application/inplace_application/draft06.rb +27 -0
  26. data/lib/jsi/schema/application/inplace_application/draft07.rb +33 -0
  27. data/lib/jsi/schema/application/inplace_application/ifthenelse.rb +20 -0
  28. data/lib/jsi/schema/application/inplace_application/ref.rb +18 -0
  29. data/lib/jsi/schema/application/inplace_application/someof.rb +29 -0
  30. data/lib/jsi/schema/application/inplace_application.rb +46 -0
  31. data/lib/jsi/schema/application.rb +12 -0
  32. data/lib/jsi/schema/draft04.rb +14 -0
  33. data/lib/jsi/schema/draft06.rb +14 -0
  34. data/lib/jsi/schema/draft07.rb +14 -0
  35. data/lib/jsi/schema/issue.rb +36 -0
  36. data/lib/jsi/schema/ref.rb +159 -0
  37. data/lib/jsi/schema/schema_ancestor_node.rb +119 -0
  38. data/lib/jsi/schema/validation/array.rb +69 -0
  39. data/lib/jsi/schema/validation/const.rb +20 -0
  40. data/lib/jsi/schema/validation/contains.rb +25 -0
  41. data/lib/jsi/schema/validation/core.rb +39 -0
  42. data/lib/jsi/schema/validation/dependencies.rb +49 -0
  43. data/lib/jsi/schema/validation/draft04/minmax.rb +91 -0
  44. data/lib/jsi/schema/validation/draft04.rb +112 -0
  45. data/lib/jsi/schema/validation/draft06.rb +122 -0
  46. data/lib/jsi/schema/validation/draft07.rb +159 -0
  47. data/lib/jsi/schema/validation/enum.rb +25 -0
  48. data/lib/jsi/schema/validation/ifthenelse.rb +46 -0
  49. data/lib/jsi/schema/validation/items.rb +54 -0
  50. data/lib/jsi/schema/validation/not.rb +20 -0
  51. data/lib/jsi/schema/validation/numeric.rb +121 -0
  52. data/lib/jsi/schema/validation/object.rb +45 -0
  53. data/lib/jsi/schema/validation/pattern.rb +34 -0
  54. data/lib/jsi/schema/validation/properties.rb +101 -0
  55. data/lib/jsi/schema/validation/property_names.rb +32 -0
  56. data/lib/jsi/schema/validation/ref.rb +40 -0
  57. data/lib/jsi/schema/validation/required.rb +27 -0
  58. data/lib/jsi/schema/validation/someof.rb +90 -0
  59. data/lib/jsi/schema/validation/string.rb +47 -0
  60. data/lib/jsi/schema/validation/type.rb +49 -0
  61. data/lib/jsi/schema/validation.rb +51 -0
  62. data/lib/jsi/schema.rb +528 -233
  63. data/lib/jsi/schema_classes.rb +238 -51
  64. data/lib/jsi/schema_registry.rb +141 -0
  65. data/lib/jsi/schema_set.rb +141 -0
  66. data/lib/jsi/simple_wrap.rb +8 -3
  67. data/lib/jsi/typelike_modules.rb +75 -68
  68. data/lib/jsi/util/attr_struct.rb +106 -0
  69. data/lib/jsi/util.rb +167 -64
  70. data/lib/jsi/validation/error.rb +34 -0
  71. data/lib/jsi/validation/result.rb +210 -0
  72. data/lib/jsi/validation.rb +15 -0
  73. data/lib/jsi/version.rb +3 -1
  74. data/lib/jsi.rb +72 -9
  75. data/lib/schemas/json-schema.org/draft-04/schema.rb +12 -0
  76. data/lib/schemas/json-schema.org/draft-06/schema.rb +12 -0
  77. data/lib/schemas/json-schema.org/draft-07/schema.rb +12 -0
  78. data/readme.rb +138 -0
  79. data/{resources}/schemas/json-schema.org/draft-04/schema.json +149 -0
  80. data/{resources}/schemas/json-schema.org/draft-06/schema.json +154 -0
  81. data/{resources}/schemas/json-schema.org/draft-07/schema.json +168 -0
  82. metadata +80 -107
  83. data/.simplecov +0 -1
  84. data/LICENSE.txt +0 -21
  85. data/Rakefile.rb +0 -9
  86. data/jsi.gemspec +0 -31
  87. data/lib/jsi/base/to_rb.rb +0 -126
  88. data/lib/jsi/json/node.rb +0 -243
  89. data/lib/jsi/json/pointer.rb +0 -330
  90. data/lib/jsi/json-schema-fragments.rb +0 -59
  91. data/lib/jsi/json.rb +0 -8
  92. data/test/base_array_test.rb +0 -209
  93. data/test/base_hash_test.rb +0 -204
  94. data/test/base_test.rb +0 -422
  95. data/test/jsi_coder_test.rb +0 -85
  96. data/test/jsi_json_arraynode_test.rb +0 -150
  97. data/test/jsi_json_hashnode_test.rb +0 -132
  98. data/test/jsi_json_node_test.rb +0 -310
  99. data/test/jsi_json_pointer_test.rb +0 -106
  100. data/test/jsi_test.rb +0 -11
  101. data/test/jsi_typelike_as_json_test.rb +0 -53
  102. data/test/schema_test.rb +0 -196
  103. data/test/spreedly_openapi_test.rb +0 -8
  104. data/test/test_helper.rb +0 -63
  105. data/test/util_test.rb +0 -62
@@ -1,8 +0,0 @@
1
- require_relative 'test_helper'
2
-
3
- require 'spreedly_openapi'
4
- describe 'spreedly openapi' do
5
- it 'instantiates the spreedly openapi doc' do
6
- SpreedlyOpenAPI::Document.inspect
7
- end
8
- end
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