jsi 0.0.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.simplecov +3 -1
  3. data/CHANGELOG.md +48 -0
  4. data/LICENSE.md +613 -0
  5. data/README.md +84 -45
  6. data/jsi.gemspec +11 -14
  7. data/lib/jsi.rb +31 -12
  8. data/lib/jsi/base.rb +310 -344
  9. data/lib/jsi/base/to_rb.rb +2 -0
  10. data/lib/jsi/jsi_coder.rb +91 -0
  11. data/lib/jsi/json-schema-fragments.rb +3 -135
  12. data/lib/jsi/json.rb +3 -0
  13. data/lib/jsi/json/node.rb +72 -197
  14. data/lib/jsi/json/pointer.rb +419 -0
  15. data/lib/jsi/metaschema.rb +7 -0
  16. data/lib/jsi/metaschema_node.rb +218 -0
  17. data/lib/jsi/pathed_node.rb +118 -0
  18. data/lib/jsi/schema.rb +168 -223
  19. data/lib/jsi/schema_classes.rb +158 -0
  20. data/lib/jsi/simple_wrap.rb +12 -0
  21. data/lib/jsi/typelike_modules.rb +71 -45
  22. data/lib/jsi/util.rb +47 -57
  23. data/lib/jsi/version.rb +1 -1
  24. data/lib/schemas/json-schema.org/draft-04/schema.rb +7 -0
  25. data/lib/schemas/json-schema.org/draft-06/schema.rb +7 -0
  26. data/resources/icons/AGPL-3.0.png +0 -0
  27. data/test/base_array_test.rb +210 -84
  28. data/test/base_hash_test.rb +201 -58
  29. data/test/base_test.rb +212 -121
  30. data/test/jsi_coder_test.rb +85 -0
  31. data/test/jsi_json_arraynode_test.rb +26 -25
  32. data/test/jsi_json_hashnode_test.rb +40 -39
  33. data/test/jsi_json_node_test.rb +95 -126
  34. data/test/jsi_json_pointer_test.rb +102 -0
  35. data/test/jsi_typelike_as_json_test.rb +53 -0
  36. data/test/metaschema_node_test.rb +19 -0
  37. data/test/schema_module_test.rb +21 -0
  38. data/test/schema_test.rb +109 -97
  39. data/test/spreedly_openapi_test.rb +8 -0
  40. data/test/test_helper.rb +42 -8
  41. data/test/util_test.rb +14 -14
  42. metadata +54 -25
  43. data/LICENSE.txt +0 -21
  44. data/lib/jsi/schema_instance_json_coder.rb +0 -83
  45. data/lib/jsi/struct_json_coder.rb +0 -30
  46. data/test/schema_instance_json_coder_test.rb +0 -121
  47. data/test/struct_json_coder_test.rb +0 -130
@@ -0,0 +1,102 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe JSI::JSON::Pointer do
4
+ # For example, given the document
5
+ let(:document) do
6
+ {
7
+ "foo" => ["bar", "baz"],
8
+ "" => 0,
9
+ "a/b" => 1,
10
+ "c%d" => 2,
11
+ "e^f" => 3,
12
+ "g|h" => 4,
13
+ "i\\j" => 5,
14
+ "k\"l" => 6,
15
+ " " => 7,
16
+ "m~n" => 8,
17
+ }
18
+ end
19
+
20
+ describe 'initialize from pointer' do
21
+ it 'parses' do
22
+ # The following strings evaluate to the accompanying values:
23
+ evaluations = [
24
+ "" , document,
25
+ "/foo" , ["bar", "baz"],
26
+ "/foo/0", "bar",
27
+ "/" , 0,
28
+ "/a~1b" , 1,
29
+ "/c%d" , 2,
30
+ "/e^f" , 3,
31
+ "/g|h" , 4,
32
+ "/i\\j" , 5,
33
+ "/k\"l" , 6,
34
+ "/ " , 7,
35
+ "/m~0n" , 8,
36
+ ]
37
+ evaluations.each_slice(2) do |pointer, value|
38
+ assert_equal(value, JSI::JSON::Pointer.from_pointer(pointer).evaluate(document))
39
+ end
40
+ end
41
+
42
+ it 'raises for invalid syntax' do
43
+ err = assert_raises(JSI::JSON::Pointer::PointerSyntaxError) do
44
+ JSI::JSON::Pointer.from_pointer("this does not begin with slash").evaluate(document)
45
+ end
46
+ assert_equal("Invalid pointer syntax in \"this does not begin with slash\": pointer must begin with /", err.message)
47
+ end
48
+ end
49
+ describe 'initialize from fragment' do
50
+ # For example, given the document
51
+ let(:document) do
52
+ {
53
+ "foo" => ["bar", "baz"],
54
+ "" => 0,
55
+ "a/b" => 1,
56
+ "c%d" => 2,
57
+ "e^f" => 3,
58
+ "g|h" => 4,
59
+ "i\\j" => 5,
60
+ "k\"l" => 6,
61
+ " " => 7,
62
+ "m~n" => 8,
63
+ }
64
+ end
65
+
66
+ it 'parses' do
67
+ # the following URI fragment identifiers evaluate to the accompanying values:
68
+ evaluations = [
69
+ '#', document,
70
+ '#/foo', ["bar", "baz"],
71
+ '#/foo/0', "bar",
72
+ '#/', 0,
73
+ '#/a~1b', 1,
74
+ '#/c%25d', 2,
75
+ '#/e%5Ef', 3,
76
+ '#/g%7Ch', 4,
77
+ '#/i%5Cj', 5,
78
+ '#/k%22l', 6,
79
+ '#/%20', 7,
80
+ '#/m~0n', 8,
81
+ ]
82
+ evaluations.each_slice(2) do |uri, value|
83
+ assert_equal(value, JSI::JSON::Pointer.from_fragment(Addressable::URI.parse(uri).fragment).evaluate(document))
84
+ end
85
+ end
86
+
87
+ it 'raises for invalid syntax' do
88
+ err = assert_raises(JSI::JSON::Pointer::PointerSyntaxError) do
89
+ JSI::JSON::Pointer.from_fragment("this does not begin with slash").evaluate(document)
90
+ end
91
+ assert_equal("Invalid pointer syntax in \"this does not begin with slash\": pointer must begin with /", err.message)
92
+ end
93
+ end
94
+ describe 'initialize' do
95
+ describe 'invalid reference_tokens' do
96
+ it 'raises' do
97
+ err = assert_raises(TypeError) { JSI::JSON::Pointer.new({}) }
98
+ assert_equal("reference_tokens must be an array. got: {}", err.message)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,53 @@
1
+ require_relative 'test_helper'
2
+
3
+ class JSONifiable
4
+ def initialize(object)
5
+ @object = object
6
+ end
7
+ def as_json
8
+ @object
9
+ end
10
+ end
11
+
12
+ describe JSI::Typelike do
13
+ describe 'as_json' do
14
+ it 'expresses as json' do
15
+ assert_equal({}, JSI::Typelike.as_json({}))
16
+ assert_equal([], JSI::Typelike.as_json([]))
17
+
18
+ # symbols to string
19
+ assert_equal(['a'], JSI::Typelike.as_json([:a]))
20
+
21
+ # set
22
+ assert_equal(['a'], JSI::Typelike.as_json(Set.new(['a'])))
23
+
24
+ # responds to #to_hash / #to_ary but naught else
25
+ assert_equal({'a' => 'b'}, JSI::Typelike.as_json(SortOfHash.new({'a' => 'b'})))
26
+ assert_equal(['a'], JSI::Typelike.as_json(SortOfArray.new(['a'])))
27
+
28
+ # symbol keys to string
29
+ assert_equal({'a' => 'b'}, JSI::Typelike.as_json({a: 'b'}))
30
+ # non string/symbol key
31
+ err = assert_raises(TypeError) { JSI::Typelike.as_json({nil => 0}) }
32
+ assert_equal('json object (hash) cannot be keyed with: nil', err.message)
33
+
34
+ # schema
35
+ schema = JSI::Schema.from_object({'type' => 'array'})
36
+ assert_equal({'type' => 'array'}, JSI::Typelike.as_json(schema))
37
+
38
+ # JSI
39
+ assert_equal(['a'], JSI::Typelike.as_json(schema.new_jsi(['a'])))
40
+
41
+ # JSON::Node
42
+ assert_equal(['a'], JSI::Typelike.as_json(JSI::JSON::Node.new_doc(['a'])))
43
+
44
+ # #as_json
45
+ assert_equal(['a'], JSI::Typelike.as_json(JSONifiable.new(['a'])))
46
+
47
+ # not jsonifiable
48
+ object = Object.new
49
+ err = assert_raises(TypeError) { JSI::Typelike.as_json(object) }
50
+ assert_equal("cannot express object as json: #{object.pretty_inspect.chomp}", err.message)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe JSI::MetaschemaNode do
4
+ let(:node_document) { {'properties' => {'properties' => {'additionalProperties' => {'$ref' => '#'}}}} }
5
+ let(:node_ptr) { JSI::JSON::Pointer[] }
6
+ let(:metaschema_root_ptr) { JSI::JSON::Pointer[] }
7
+ let(:root_schema_ptr) { JSI::JSON::Pointer[] }
8
+ let(:subject) { JSI::MetaschemaNode.new(node_document, node_ptr: node_ptr, metaschema_root_ptr: node_ptr, root_schema_ptr: node_ptr) }
9
+ describe 'initialization' do
10
+ it 'initializes' do
11
+ subject
12
+ end
13
+ end
14
+ describe 'json schema draft' do
15
+ it 'type has a schema' do
16
+ assert(JSI::JSONSchemaOrgDraft06.schema.type.jsi_schemas.any?)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe 'JSI::SchemaModule' do
4
+ let(:schema_content) { {'properties' => {'foo' => {'items' => {'type' => 'string'}}}} }
5
+ let(:schema) { JSI::Schema.new(schema_content) }
6
+ let(:schema_module) { schema.jsi_schema_module }
7
+ describe 'accessors and subscripts' do
8
+ it 'returns schemas using accessors and subscripts' do
9
+ assert_equal(schema.properties, schema_module.properties.possibly_schema_node)
10
+ assert_equal(schema.properties['foo'], schema_module.properties['foo'].possibly_schema_node)
11
+ assert_equal(schema.properties['foo'].jsi_schema_module, schema_module.properties['foo'])
12
+ assert_equal(schema.properties['foo'].items, schema_module.properties['foo'].items.possibly_schema_node)
13
+ assert_equal(schema.properties['foo'].items.jsi_schema_module, schema_module.properties['foo'].items)
14
+ assert_equal('string', schema_module.properties['foo'].items.type)
15
+ end
16
+ it 'accessors and subscripts with a metaschema' do
17
+ assert_equal(JSI::JSONSchemaOrgDraft06.schema.properties, JSI::JSONSchemaOrgDraft06.properties.possibly_schema_node)
18
+ assert_equal(JSI::JSONSchemaOrgDraft06.schema.properties['properties'].additionalProperties.jsi_schema_module, JSI::JSONSchemaOrgDraft06.properties['properties'].additionalProperties)
19
+ end
20
+ end
21
+ end
@@ -1,149 +1,163 @@
1
1
  require_relative 'test_helper'
2
2
 
3
- SomeMetaschema = JSI.class_for_schema({id: 'https://schemas.jsi.unth.net/test/somemetaschema', type: 'object'})
4
-
5
3
  describe JSI::Schema do
6
4
  describe 'new' do
7
5
  it 'initializes from a hash' do
8
6
  schema = JSI::Schema.new({'type' => 'object'})
9
- assert_equal(JSI::JSON::Node.new_doc({'type' => 'object'}), schema.schema_node)
7
+ assert_equal({'type' => 'object'}, schema.jsi_instance)
10
8
  end
11
9
  it 'initializes from a Node' do
12
10
  schema_node = JSI::JSON::Node.new_doc({'type' => 'object'})
13
11
  schema = JSI::Schema.new(schema_node)
14
- assert_equal(schema_node, schema.schema_node)
15
- assert_equal(schema_node, schema.schema_object)
16
- end
17
- it 'initializes from a JSI' do
18
- schema_jsi = SomeMetaschema.new('type' => 'object')
19
- schema = JSI::Schema.new(schema_jsi)
20
- assert_equal(schema_jsi.instance, schema.schema_node)
21
- assert_equal(schema_jsi, schema.schema_object)
12
+ assert_equal(schema_node, schema.jsi_instance)
22
13
  end
23
14
  it 'cannot instantiate from some unknown object' do
24
15
  err = assert_raises(TypeError) { JSI::Schema.new(Object.new) }
25
16
  assert_match(/\Acannot instantiate Schema from: #<Object:.*>\z/m, err.message)
26
17
  end
27
- it 'makes no sense to instantiate schema from schema' do
28
- err = assert_raises(TypeError) { JSI::Schema.new(JSI::Schema.new({})) }
29
- assert_match(/\Awill not instantiate Schema from another Schema: #<JSI::Schema schema_id=.*>\z/m, err.message)
18
+ it 'instantiating a schema from schema returns that schema' do
19
+ # this is kinda dumb, but Schema.new now just aliases Schema.from_object, so this is the behavior
20
+ assert_equal(JSI::Schema.new({}), JSI::Schema.new(JSI::Schema.new({})))
30
21
  end
31
22
  end
32
23
  describe 'as an instance of metaschema' do
33
- let(:default_metaschema) do
34
- validator = ::JSON::Validator.default_validator
35
- metaschema_file = validator.metaschema
36
- JSI::Schema.new(::JSON.parse(File.read(metaschema_file)))
37
- end
38
- let(:metaschema_jsi_class) { JSI.class_for_schema(default_metaschema) }
39
- let(:schema_object) { {'type' => 'array', 'items' => {'description' => 'items!'}} }
40
- let(:schema_jsi) { metaschema_jsi_class.new(schema_object) }
41
- let(:schema) { JSI::Schema.new(schema_jsi) }
24
+ let(:metaschema_jsi_module) { JSI::JSONSchemaOrgDraft04 }
25
+ let(:schema_content) { {'type' => 'array', 'items' => {'description' => 'items!'}} }
26
+ let(:schema) { metaschema_jsi_module.new_jsi(schema_content) }
42
27
  it '#[]' do
43
28
  schema_items = schema['items']
44
- assert_instance_of(metaschema_jsi_class, schema_items)
29
+ assert_is_a(metaschema_jsi_module, schema_items)
45
30
  assert_equal({'description' => 'items!'}, schema_items.as_json)
46
31
  end
47
32
  end
48
33
  describe '#schema_id' do
49
- it 'generates one' do
50
- assert_match(/\A[0-9a-f\-]+#\z/, JSI::Schema.new({}).schema_id)
34
+ it "hasn't got one" do
35
+ assert_nil(JSI::Schema.new({}).schema_id)
51
36
  end
52
37
  it 'uses a given id with a fragment' do
53
- schema = JSI::Schema.new({id: 'https://schemas.jsi.unth.net/test/given_id#'})
54
- assert_equal('https://schemas.jsi.unth.net/test/given_id#', schema.schema_id)
38
+ schema = JSI::Schema.new({'id' => 'https://schemas.jsi.unth.net/test/given_id_with_fragment#'})
39
+ assert_equal('https://schemas.jsi.unth.net/test/given_id_with_fragment#', schema.schema_id)
55
40
  end
56
41
  it 'uses a given id (adding a fragment)' do
57
42
  schema = JSI::Schema.new({id: 'https://schemas.jsi.unth.net/test/given_id'})
58
43
  assert_equal('https://schemas.jsi.unth.net/test/given_id#', schema.schema_id)
59
44
  end
60
45
  it 'uses a pointer in the fragment' do
61
- schema_node = JSI::JSON::Node.new_doc({
62
- 'id' => 'https://schemas.jsi.unth.net/test/given_id#',
46
+ schema = JSI::Schema.new({
47
+ 'id' => 'https://schemas.jsi.unth.net/test/uses_pointer_in_fragment#',
63
48
  'properties' => {'foo' => {'type' => 'object'}},
64
49
  })
65
- schema = JSI::Schema.new(schema_node['properties']['foo'])
66
- assert_equal('https://schemas.jsi.unth.net/test/given_id#/properties/foo', schema.schema_id)
50
+ subschema = schema['properties']['foo']
51
+ assert_equal('https://schemas.jsi.unth.net/test/uses_pointer_in_fragment#/properties/foo', subschema.schema_id)
67
52
  end
68
53
  it 'uses a pointer in the fragment relative to the fragment of the root' do
69
- schema_node = JSI::JSON::Node.new_doc({
70
- 'id' => 'https://schemas.jsi.unth.net/test/given_id#/notroot',
54
+ schema = JSI::Schema.new({
55
+ 'id' => 'https://schemas.jsi.unth.net/test/id_has_pointer#/notroot',
71
56
  'properties' => {'foo' => {'type' => 'object'}},
72
57
  })
73
- schema = JSI::Schema.new(schema_node['properties']['foo'])
74
- assert_equal('https://schemas.jsi.unth.net/test/given_id#/notroot/properties/foo', schema.schema_id)
58
+ subschema = schema['properties']['foo']
59
+ assert_equal('https://schemas.jsi.unth.net/test/id_has_pointer#/notroot/properties/foo', subschema.schema_id)
75
60
  end
76
61
  end
77
- describe '#schema_class' do
62
+ describe '#jsi_schema_module' do
63
+ it 'returns the module for the schema' do
64
+ schema = JSI::Schema.new({'id' => 'https://schemas.jsi.unth.net/test/jsi_schema_module'})
65
+ assert_is_a(JSI::SchemaModule, schema.jsi_schema_module)
66
+ assert_equal(schema, schema.jsi_schema_module.schema)
67
+ end
68
+ end
69
+ describe '#jsi_schema_class' do
78
70
  it 'returns the class for the schema' do
79
- schema_node = JSI::JSON::Node.new_doc({'id' => 'https://schemas.jsi.unth.net/test/schema_schema_class'})
80
- assert_equal(JSI.class_for_schema(schema_node), JSI::Schema.new(schema_node).schema_class)
71
+ schema = JSI::Schema.new({'id' => 'https://schemas.jsi.unth.net/test/schema_schema_class'})
72
+ assert_equal(JSI.class_for_schemas([schema]), schema.jsi_schema_class)
81
73
  end
82
74
  end
83
- describe '#subschema_for_property' do
75
+ describe '#subschemas_for_property_name' do
84
76
  let(:schema) do
85
77
  JSI::Schema.new({
86
- properties: {foo: {description: 'foo'}},
87
- patternProperties: {"^ba" => {description: 'ba*'}},
78
+ properties: {
79
+ foo: {description: 'foo'},
80
+ baz: {description: 'baz'},
81
+ },
82
+ patternProperties: {
83
+ "^b" => {description: 'ba*'},
84
+ },
88
85
  additionalProperties: {description: 'whatever'},
89
86
  })
90
87
  end
91
- it 'has no subschema' do
92
- assert_equal(nil, JSI::Schema.new({}).subschema_for_property('no'))
88
+ it 'has no subschemas' do
89
+ assert_empty(JSI::Schema.new({}).subschemas_for_property_name('no'))
93
90
  end
94
91
  it 'has a subschema by property' do
95
- subschema = schema.subschema_for_property('foo')
96
- assert_instance_of(JSI::Schema, subschema)
97
- assert_equal('foo', subschema['description'])
98
- end
99
- it 'has a subschema by pattern property' do
100
- subschema = schema.subschema_for_property('bar')
101
- assert_instance_of(JSI::Schema, subschema)
102
- assert_equal('ba*', subschema['description'])
103
- end
104
- it 'has a subschema by additional properties' do
105
- subschema = schema.subschema_for_property('anything')
106
- assert_instance_of(JSI::Schema, subschema)
107
- assert_equal('whatever', subschema['description'])
92
+ subschemas = schema.subschemas_for_property_name('foo').to_a
93
+ assert_equal(1, subschemas.size)
94
+ assert_is_a(JSI::Schema.default_metaschema.jsi_schema_module, subschemas[0])
95
+ assert_equal('foo', subschemas[0].description)
96
+ end
97
+ it 'has subschemas by patternProperties' do
98
+ subschemas = schema.subschemas_for_property_name('bar').to_a
99
+ assert_equal(1, subschemas.size)
100
+ assert_is_a(JSI::Schema.default_metaschema.jsi_schema_module, subschemas[0])
101
+ assert_equal('ba*', subschemas[0].description)
102
+ end
103
+ it 'has subschemas by properties, patternProperties' do
104
+ subschemas = schema.subschemas_for_property_name('baz').to_a
105
+ assert_equal(2, subschemas.size)
106
+ assert_is_a(JSI::Schema.default_metaschema.jsi_schema_module, subschemas[0])
107
+ assert_equal('baz', subschemas[0].description)
108
+ assert_is_a(JSI::Schema.default_metaschema.jsi_schema_module, subschemas[1])
109
+ assert_equal('ba*', subschemas[1].description)
110
+ end
111
+ it 'has subschemas by additional properties' do
112
+ subschemas = schema.subschemas_for_property_name('anything').to_a
113
+ assert_equal(1, subschemas.size)
114
+ assert_is_a(JSI::Schema.default_metaschema.jsi_schema_module, subschemas[0])
115
+ assert_equal('whatever', subschemas[0].description)
108
116
  end
109
117
  end
110
- describe '#subschema_for_index' do
111
- it 'has no subschema' do
112
- assert_equal(nil, JSI::Schema.new({}).subschema_for_index(0))
118
+ describe '#subschemas_for_index' do
119
+ it 'has no subschemas' do
120
+ assert_empty(JSI::Schema.new({}).subschemas_for_index(0))
113
121
  end
114
122
  it 'has a subschema for items' do
115
123
  schema = JSI::Schema.new({
116
124
  items: {description: 'items!'}
117
125
  })
118
- first_subschema = schema.subschema_for_index(0)
119
- assert_instance_of(JSI::Schema, first_subschema)
120
- assert_equal('items!', first_subschema['description'])
121
- last_subschema = schema.subschema_for_index(1)
122
- assert_instance_of(JSI::Schema, last_subschema)
123
- assert_equal('items!', last_subschema['description'])
126
+ first_subschemas = schema.subschemas_for_index(0).to_a
127
+ assert_equal(1, first_subschemas.size)
128
+ assert_is_a(JSI::Schema.default_metaschema.jsi_schema_module, first_subschemas[0])
129
+ assert_equal('items!', first_subschemas[0].description)
130
+ last_subschemas = schema.subschemas_for_index(1).to_a
131
+ assert_equal(1, last_subschemas.size)
132
+ assert_is_a(JSI::Schema.default_metaschema.jsi_schema_module, last_subschemas[0])
133
+ assert_equal('items!', last_subschemas[0].description)
124
134
  end
125
135
  it 'has a subschema for each item by index' do
126
136
  schema = JSI::Schema.new({
127
137
  items: [{description: 'item one'}, {description: 'item two'}]
128
138
  })
129
- first_subschema = schema.subschema_for_index(0)
130
- assert_instance_of(JSI::Schema, first_subschema)
131
- assert_equal('item one', first_subschema['description'])
132
- last_subschema = schema.subschema_for_index(1)
133
- assert_instance_of(JSI::Schema, last_subschema)
134
- assert_equal('item two', last_subschema['description'])
139
+ first_subschemas = schema.subschemas_for_index(0).to_a
140
+ assert_equal(1, first_subschemas.size)
141
+ assert_is_a(JSI::Schema.default_metaschema.jsi_schema_module, first_subschemas[0])
142
+ assert_equal('item one', first_subschemas[0].description)
143
+ last_subschemas = schema.subschemas_for_index(1).to_a
144
+ assert_equal(1, last_subschemas.size)
145
+ assert_is_a(JSI::Schema.default_metaschema.jsi_schema_module, last_subschemas[0])
146
+ assert_equal('item two', last_subschemas[0].description)
135
147
  end
136
148
  it 'has a subschema by additional items' do
137
149
  schema = JSI::Schema.new({
138
150
  items: [{description: 'item one'}],
139
151
  additionalItems: {description: "mo' crap"},
140
152
  })
141
- first_subschema = schema.subschema_for_index(0)
142
- assert_instance_of(JSI::Schema, first_subschema)
143
- assert_equal('item one', first_subschema['description'])
144
- last_subschema = schema.subschema_for_index(1)
145
- assert_instance_of(JSI::Schema, last_subschema)
146
- assert_equal("mo' crap", last_subschema['description'])
153
+ first_subschemas = schema.subschemas_for_index(0).to_a
154
+ assert_equal(1, first_subschemas.size)
155
+ assert_is_a(JSI::Schema.default_metaschema.jsi_schema_module, first_subschemas[0])
156
+ assert_equal('item one', first_subschemas[0].description)
157
+ last_subschemas = schema.subschemas_for_index(1).to_a
158
+ assert_equal(1, last_subschemas.size)
159
+ assert_is_a(JSI::Schema.default_metaschema.jsi_schema_module, last_subschemas[0])
160
+ assert_equal("mo' crap", last_subschemas[0].description)
147
161
  end
148
162
  end
149
163
  describe 'stringification' do
@@ -152,42 +166,40 @@ describe JSI::Schema do
152
166
  end
153
167
 
154
168
  it '#inspect' do
155
- assert_equal(%q(#<JSI::Schema schema_id=https://schemas.jsi.unth.net/test/stringification# #{<JSI::JSON::HashNode fragment="#"> "id" => "https://schemas.jsi.unth.net/test/stringification", "type" => "object"}>), schema.inspect)
169
+ assert_equal("\#{<JSI (JSI::JSONSchemaOrgDraft06) Schema> \"id\" => \"https://schemas.jsi.unth.net/test/stringification\", \"type\" => \"object\"}", schema.inspect)
156
170
  end
157
171
  it '#pretty_print' do
158
- assert_equal(%q(#<JSI::Schema schema_id=https://schemas.jsi.unth.net/test/stringification#
159
- #{<JSI::JSON::HashNode fragment="#">
160
- "id" => "https://schemas.jsi.unth.net/test/stringification",
161
- "type" => "object"
162
- }
163
- >).gsub(/^ /, ''), schema.pretty_inspect.chomp)
172
+ assert_equal("\#{<JSI (JSI::JSONSchemaOrgDraft06) Schema>
173
+ \"id\" => \"https://schemas.jsi.unth.net/test/stringification\",
174
+ \"type\" => \"object\"
175
+ }".gsub(/^ /, ''), schema.pretty_inspect.chomp)
164
176
  end
165
177
  end
166
178
  describe 'validation' do
167
179
  let(:schema) { JSI::Schema.new({id: 'https://schemas.jsi.unth.net/test/validation', type: 'object'}) }
168
180
  describe 'without errors' do
169
181
  let(:instance) { {'foo' => 'bar'} }
170
- it '#fully_validate' do
171
- assert_equal([], schema.fully_validate(instance))
182
+ it '#fully_validate_instance' do
183
+ assert_equal([], schema.fully_validate_instance(instance))
172
184
  end
173
- it '#validate' do
174
- assert_equal(true, schema.validate(instance))
185
+ it '#validate_instance' do
186
+ assert_equal(true, schema.validate_instance(instance))
175
187
  end
176
- it '#validate!' do
177
- assert_equal(true, schema.validate!(instance))
188
+ it '#validate_instance!' do
189
+ assert_equal(true, schema.validate_instance!(instance))
178
190
  end
179
191
  end
180
192
  describe 'with errors' do
181
193
  let(:instance) { ['no'] }
182
- it '#fully_validate' do
183
- assert_equal(["The property '#/' of type array did not match the following type: object in schema https://schemas.jsi.unth.net/test/validation"], schema.fully_validate(instance))
194
+ it '#fully_validate_instance' do
195
+ assert_equal(["The property '#/' of type array did not match the following type: object in schema https://schemas.jsi.unth.net/test/validation"], schema.fully_validate_instance(instance))
184
196
  end
185
- it '#validate' do
186
- assert_equal(false, schema.validate(instance))
197
+ it '#validate_instance' do
198
+ assert_equal(false, schema.validate_instance(instance))
187
199
  end
188
- it '#validate!' do
200
+ it '#validate_instance!' do
189
201
  err = assert_raises(JSON::Schema::ValidationError) do
190
- schema.validate!(instance)
202
+ schema.validate_instance!(instance)
191
203
  end
192
204
  assert_equal("The property '#/' of type array did not match the following type: object", err.message)
193
205
  end