• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

notEthan / jsi / 9708111060

24 Jun 2024 04:43AM UTC coverage: 98.097% (+0.7%) from 97.348%
9708111060

push

github

notEthan
v0.8.0

5877 of 5991 relevant lines covered (98.1%)

148855.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.72
/test/schema_test.rb
1
require_relative 'test_helper'
14✔
2

3
describe JSI::Schema do
14✔
4
  describe 'new_schema' do
14✔
5
    it 'initializes from a hash' do
14✔
6
      schema = JSI.new_schema({'type' => 'object'}, default_metaschema: JSI::JSONSchemaDraft07)
14✔
7
      assert_equal({'type' => 'object'}, schema.jsi_instance)
14✔
8
    end
9

10
    it 'cannot instantiate from a non-string $schema' do
14✔
11
      err = assert_raises(ArgumentError) { JSI.new_schema({'$schema' => Object.new}) }
28✔
12
      assert_equal("given schema_content keyword `$schema` is not a string", err.message)
14✔
13
    end
14

15
    it '$schema resolves but does not describe schemas' do
14✔
16
      JSI.new_schema({"$schema": "http://json-schema.org/draft-07/schema#", "$id": "tag:guqh"})
14✔
17
      e = assert_raises(TypeError) { JSI.new_schema({"$schema": "tag:guqh"}) }
28✔
18
      assert_equal(%q($schema URI indicates a schema that is not a meta-schema: "tag:guqh"), e.message)
14✔
19
    end
20

21
    it 'cannot instantiate from a JSI Schema' do
14✔
22
      err = assert_raises(TypeError) { JSI.new_schema(JSI::JSONSchemaDraft07.new_schema({}), default_metaschema: JSI::JSONSchemaDraft07) }
28✔
23
      assert_equal("Given schema_content is already a JSI::Schema. It cannot be instantiated as the content of a schema.\ngiven: \#{<JSI (JSI::JSONSchemaDraft07) Schema>}", err.message)
14✔
24
    end
25

26
    it 'cannot instantiate from a JSI' do
14✔
27
      err = assert_raises(TypeError) { JSI.new_schema(JSI::JSONSchemaDraft07.new_schema({}).new_jsi({}), default_metaschema: JSI::JSONSchemaDraft07) }
28✔
28
      assert_equal("Given schema_content is a JSI::Base. It cannot be instantiated as the content of a schema.\ngiven: \#{<JSI>}", err.message)
14✔
29
    end
30

31
    it 'instantiates using default_metaschema' do
14✔
32
      # URI
33
      schema = JSI.new_schema({}, default_metaschema: "http://json-schema.org/draft-07/schema#")
14✔
34
      assert_schemas([JSI::JSONSchemaDraft07.schema], schema)
14✔
35

36
      # JSI::Schema
37
      schema = JSI.new_schema({}, default_metaschema: JSI::JSONSchemaDraft07.schema)
14✔
38
      assert_schemas([JSI::JSONSchemaDraft07.schema], schema)
14✔
39

40
      # invalid: wrong type
41
      e = assert_raises(TypeError) { JSI.new_schema({}, default_metaschema: 1) }
28✔
42
      assert_match(/default_metaschema.* 1/, e.message)
14✔
43

44
      # invalid: URI resolves but it's not a meta-schema
45
      JSI.new_schema({"$schema": "http://json-schema.org/draft-07/schema#", "$id": "tag:l3bu"})
14✔
46
      e = assert_raises(TypeError) { JSI.new_schema({}, default_metaschema: "tag:l3bu") }
28✔
47
      assert_match(/default_metaschema URI.* "tag:l3bu"/, e.message)
14✔
48
    end
49
  end
50
  describe('as an instance of meta-schema') do
14✔
51
    let(:metaschema_jsi_module) { JSI::JSONSchemaDraft04 }
28✔
52
    let(:schema_content) { {'type' => 'array', 'items' => {'description' => 'items!'}} }
28✔
53
    let(:schema) { metaschema_jsi_module.new_jsi(schema_content) }
28✔
54
    it '#[]' do
14✔
55
      schema_items = schema['items']
14✔
56
      assert_is_a(metaschema_jsi_module, schema_items)
14✔
57
      assert_equal({'description' => 'items!'}, schema_items.jsi_instance)
14✔
58
    end
59
  end
60
  describe '#schema_uri' do
14✔
61
    it "hasn't got one" do
14✔
62
      assert_nil(JSI::JSONSchemaDraft07.new_schema({}).schema_uri)
14✔
63
    end
64
    it 'uses a given id ignoring an empty fragment' do
14✔
65
      schema = JSI::JSONSchemaDraft07.new_schema({'$id' => 'http://jsi/schema/given_id_with_fragment#'})
14✔
66
      assert_uri('http://jsi/schema/given_id_with_fragment', schema.schema_uri)
14✔
67
    end
68
    it 'uses a given id with no fragment' do
14✔
69
      schema = JSI::JSONSchemaDraft07.new_schema({'$id' => 'http://jsi/schema/given_id'})
14✔
70
      assert_uri('http://jsi/schema/given_id', schema.schema_uri)
14✔
71
    end
72
    it 'uses a pointer in the fragment' do
14✔
73
      schema = JSI::JSONSchemaDraft07.new_schema({
14✔
74
        '$id' => 'http://jsi/schema/uses_pointer_in_fragment#',
75
        'properties' => {'foo' => {'type' => 'object'}},
76
      })
77
      subschema = schema['properties']['foo']
14✔
78
      assert_uri('http://jsi/schema/uses_pointer_in_fragment#/properties/foo', subschema.schema_uri)
14✔
79
    end
80
    it 'uses a pointer in the fragment, ignoring a pointer in the fragment of the root id' do
14✔
81
      schema = JSI::JSONSchemaDraft07.new_schema({
14✔
82
        '$id' => 'http://jsi/schema/id_has_pointer#/notroot',
83
        'properties' => {'foo' => {'type' => 'object'}},
84
      })
85
      subschema = schema['properties']['foo']
14✔
86
      assert_uri('http://jsi/schema/id_has_pointer#/properties/foo', subschema.schema_uri)
14✔
87
    end
88
  end
89
  describe '#schema_uris' do
14✔
90
    let(:schema) { JSI.new_schema(schema_content, default_metaschema: JSI::JSONSchemaDraft07) }
28✔
91
    describe 'two ids' do
14✔
92
      let(:schema_content) do
14✔
93
        {
4✔
94
          "$id": "https://example.com/foo",
6✔
95
          "items": {
96
            "$id": "https://example.com/bar",
97
            "additionalProperties": { }
98
          }
99
        }
2✔
100
      end
101
      it 'has its absolute URI and both by pointer fragment' do
14✔
102
        assert_equal([
16✔
103
          "https://example.com/bar",
104
          "https://example.com/bar#",
105
          "https://example.com/foo#/items",
106
        ], schema.items.schema_uris.map(&:to_s))
107
      end
108
    end
109
    describe 'conflicting anchors' do
14✔
110
      let(:schema) do
14✔
111
        JSI::JSONSchemaDraft06.new_schema(JSON.parse(%q({
14✔
112
          "$id": "http://jsi/schema_uris/q0wo",
113
          "definitions": {
114
            "sibling1": {"$id": "#collide"},
115
            "sibling2": {"$id": "#collide"},
116
            "child": {
117
              "$id": "#X",
118
              "definitions": {
119
                "rel": {
120
                  "$id": "z268",
121
                  "definitions": {
122
                    "x": {"$id": "#X"}
123
                  }
124
                }
125
              }
126
            }
127
          }
128
        })))
129
      end
130

131
      it 'has the specified uris' do
14✔
132
        all_exp_uris = {
8✔
133
          "#" => [
6✔
134
            "http://jsi/schema_uris/q0wo",
135
            "http://jsi/schema_uris/q0wo#",
136
          ],
137
          "#/definitions/sibling1" => [
138
            "http://jsi/schema_uris/q0wo#/definitions/sibling1",
139
            # no #collide
140
          ],
141
          "#/definitions/sibling2" => [
142
            "http://jsi/schema_uris/q0wo#/definitions/sibling2",
143
            # no #collide
144
          ],
145
          "#/definitions/child" => [
146
            # #X collides with anchor in different descendent resource
147
            "http://jsi/schema_uris/q0wo#/definitions/child",
148
          ],
149
          "#/definitions/child/definitions/rel" => [
150
            "http://jsi/schema_uris/z268",
151
            "http://jsi/schema_uris/z268#",
152
            "http://jsi/schema_uris/q0wo#/definitions/child/definitions/rel",
153
          ],
154
          "#/definitions/child/definitions/rel/definitions/x" => [
155
            "http://jsi/schema_uris/z268#X",
156
            "http://jsi/schema_uris/z268#/definitions/x",
157
            # no "http://jsi/schema_uris/q0wo#X"; we detect that the anchor no longer
158
            # refers to self in the parent resource (it becomes ambiguous)
159
            "http://jsi/schema_uris/q0wo#/definitions/child/definitions/rel/definitions/x",
160
          ],
161
        }
162
        all_act_uris = all_exp_uris.keys.map do |uri|
14✔
163
          subschema = JSI::Ptr.from_fragment(Addressable::URI.parse(uri).fragment).evaluate(schema)
84✔
164
          {uri => subschema.schema_uris.map(&:to_s)}
84✔
165
        end.inject({}, &:update)
166
        assert_equal(all_exp_uris, all_act_uris)
14✔
167
      end
168
    end
169

170
    describe 'draft4 example' do
14✔
171
      let(:schema) do
14✔
172
        # adapted from https://datatracker.ietf.org/doc/html/draft-zyp-json-schema-04#section-7.2.2
173
        # but changed so only schemas use ids
174
        JSI::JSONSchemaDraft04.new_schema(JSON.parse(%q({
14✔
175
          "id": "http://x.y.z/rootschema.json#",
176
          "definitions": {
177
            "schema1": {
178
              "id": "#foo"
179
            },
180
            "schema2": {
181
              "id": "otherschema.json",
182
              "definitions": {
183
                "nested": {
184
                  "id": "#bar"
185
                },
186
                "alsonested": {
187
                  "id": "t/inner.json#a"
188
                }
189
              }
190
            },
191
            "schema3": {
192
              "id": "some://where.else/completely#"
193
            }
194
          }
195
        })))
196
      end
197

198
      it 'has the specified uris' do
14✔
199
        all_exp_uris = {
8✔
200
          '#' => [
6✔
201
            "http://x.y.z/rootschema.json",
202
            "http://x.y.z/rootschema.json#",
203
          ],
204
          '#/definitions/schema1' => [
205
            "http://x.y.z/rootschema.json#foo",
206
            "http://x.y.z/rootschema.json#/definitions/schema1",
207
          ],
208
          '#/definitions/schema2' => [
209
            'http://x.y.z/otherschema.json',
210
            'http://x.y.z/otherschema.json#',
211
            'http://x.y.z/rootschema.json#/definitions/schema2',
212
          ],
213
          '#/definitions/schema2/definitions/nested' => [
214
            "http://x.y.z/otherschema.json#bar",
215
            "http://x.y.z/otherschema.json#/definitions/nested",
216
            "http://x.y.z/rootschema.json#bar",
217
            "http://x.y.z/rootschema.json#/definitions/schema2/definitions/nested",
218
          ],
219
          '#/definitions/schema2/definitions/alsonested' => [
220
            "http://x.y.z/t/inner.json",
221
            "http://x.y.z/t/inner.json#a",
222
            "http://x.y.z/t/inner.json#",
223
            "http://x.y.z/otherschema.json#a",
224
            "http://x.y.z/otherschema.json#/definitions/alsonested",
225
            "http://x.y.z/rootschema.json#a",
226
            "http://x.y.z/rootschema.json#/definitions/schema2/definitions/alsonested",
227
          ],
228
          '#/definitions/schema3' => [
229
            "some://where.else/completely",
230
            "some://where.else/completely#",
231
            "http://x.y.z/rootschema.json#/definitions/schema3",
232
          ],
233
        }
234
        all_act_uris = all_exp_uris.keys.map do |uri|
14✔
235
          subschema = JSI::Ptr.from_fragment(Addressable::URI.parse(uri).fragment).evaluate(schema)
84✔
236
          {uri => subschema.schema_uris.map(&:to_s)}
84✔
237
        end.inject({}, &:update)
238
        assert_equal(all_exp_uris, all_act_uris)
14✔
239
      end
240
    end
241

242
    describe 'draft6 example' do
14✔
243
      let(:schema) do
14✔
244
        # from https://datatracker.ietf.org/doc/html/draft-wright-json-schema-01#section-9.2
245
        JSI::JSONSchemaDraft06.new_schema(JSON.parse(%q({
14✔
246
          "$id": "http://example.com/root.json",
247
          "definitions": {
248
            "A": { "$id": "#foo" },
249
            "B": {
250
              "$id": "other.json",
251
              "definitions": {
252
                "X": { "$id": "#bar" },
253
                "Y": { "$id": "t/inner.json" }
254
              }
255
            },
256
            "C": {
257
              "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
258
            }
259
          }
260
        })))
261
      end
262

263
      it 'has the specified uris' do
14✔
264
        all_exp_uris = {
8✔
265
          '#' => [
6✔
266
            "http://example.com/root.json",
267
            "http://example.com/root.json#",
268
          ],
269
          '#/definitions/A' => [
270
            "http://example.com/root.json#foo",
271
            "http://example.com/root.json#/definitions/A",
272
          ],
273
          '#/definitions/B' => [
274
            'http://example.com/other.json',
275
            'http://example.com/other.json#',
276
            'http://example.com/root.json#/definitions/B',
277
          ],
278
          '#/definitions/B/definitions/X' => [
279
            "http://example.com/other.json#bar",
280
            "http://example.com/other.json#/definitions/X",
281
            "http://example.com/root.json#bar",
282
            "http://example.com/root.json#/definitions/B/definitions/X",
283
          ],
284
          '#/definitions/B/definitions/Y' => [
285
            "http://example.com/t/inner.json",
286
            "http://example.com/t/inner.json#",
287
            "http://example.com/other.json#/definitions/Y",
288
            "http://example.com/root.json#/definitions/B/definitions/Y",
289
          ],
290
          '#/definitions/C' => [
291
            "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f",
292
            "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f#",
293
            "http://example.com/root.json#/definitions/C",
294
          ],
295
        }
296
        all_act_uris = all_exp_uris.keys.map do |uri|
14✔
297
          subschema = JSI::Ptr.from_fragment(Addressable::URI.parse(uri).fragment).evaluate(schema)
84✔
298
          {uri => subschema.schema_uris.map(&:to_s)}
84✔
299
        end.inject({}, &:update)
300
        assert_equal(all_exp_uris, all_act_uris)
14✔
301
      end
302
    end
303
  end
304
  describe '#schema_absolute_uri, #anchor' do
14✔
305
    describe 'draft 4' do
14✔
306
      let(:metaschema) { JSI::JSONSchemaDraft04 }
224✔
307
      it "hasn't got one" do
14✔
308
        schema = metaschema.new_schema({})
14✔
309
        assert_nil(schema.schema_absolute_uri)
14✔
310
        assert_nil(schema.anchor)
14✔
311
      end
312
      it 'uses a given id with an empty fragment' do
14✔
313
        schema = metaschema.new_schema({'id' => 'http://jsi/test/schema_absolute_uri/d4/empty_fragment#'})
14✔
314
        assert_uri('http://jsi/test/schema_absolute_uri/d4/empty_fragment', schema.schema_absolute_uri)
14✔
315
        assert_nil(schema.anchor)
14✔
316
      end
317
      it 'uses a given id without a fragment' do
14✔
318
        schema = metaschema.new_schema({'id' => 'http://jsi/test/schema_absolute_uri/d4/given_id'})
14✔
319
        assert_uri('http://jsi/test/schema_absolute_uri/d4/given_id', schema.schema_absolute_uri)
14✔
320
        assert_nil(schema.anchor)
14✔
321
      end
322
      it 'nested schema without id' do
14✔
323
        schema = metaschema.new_schema({
14✔
324
          'id' => 'http://jsi/test/schema_absolute_uri/d4/nested_no_id',
325
          'items' => {},
326
        })
327
        assert_nil(schema.items.schema_absolute_uri)
14✔
328
        assert_nil(schema.items.anchor)
14✔
329
      end
330
      it 'nested schema with absolute id' do
14✔
331
        schema = metaschema.new_schema({
14✔
332
          'id' => 'http://jsi/test/schema_absolute_uri/d4/nested_w_abs_id_base',
333
          'items' => {'id' => 'http://jsi/test/schema_absolute_uri/d4/nested_w_abs_id'},
334
        })
335
        assert_uri('http://jsi/test/schema_absolute_uri/d4/nested_w_abs_id', schema.items.schema_absolute_uri)
14✔
336
        assert_nil(schema.items.anchor)
14✔
337
      end
338
      it 'nested schema with relative id' do
14✔
339
        schema = metaschema.new_schema({
14✔
340
          'id' => 'http://jsi/test/schema_absolute_uri/d4/nested_w_rel_id_base',
341
          'items' => {'id' => 'nested_w_rel_id'},
342
        })
343
        assert_uri('http://jsi/test/schema_absolute_uri/d4/nested_w_rel_id', schema.items.schema_absolute_uri)
14✔
344
        assert_nil(schema.items.anchor)
14✔
345
      end
346
      it 'nested schema with anchor id' do
14✔
347
        schema = metaschema.new_schema({
14✔
348
          'id' => 'http://jsi/test/schema_absolute_uri/d4/nested_w_anchor_id_base',
349
          'items' => {'id' => '#nested_anchor'},
350
        })
351
        assert_nil(schema.items.schema_absolute_uri)
14✔
352
        assert_equal('nested_anchor', schema.items.anchor)
14✔
353
      end
354
      it 'nested schema with anchor id on the base' do
14✔
355
        schema = metaschema.new_schema({
14✔
356
          'id' => 'http://jsi/test/schema_absolute_uri/d4/nested_w_anchor_on_base',
357
          'items' => {'id' => 'http://jsi/test/schema_absolute_uri/d4/nested_w_anchor_on_base#nested_anchor'},
358
        })
359
        assert_nil(schema.items.schema_absolute_uri)
14✔
360
        assert_equal('nested_anchor', schema.items.anchor)
14✔
361
      end
362
      it 'nested schema with anchor id on the base after resolution' do
14✔
363
        schema = metaschema.new_schema({
14✔
364
          'id' => 'http://jsi/test/schema_absolute_uri/d4/nested_w_anchor_on_base_rel',
365
          'items' => {'id' => 'nested_w_anchor_on_base_rel#nested_anchor'},
366
        })
367
        assert_nil(schema.items.schema_absolute_uri)
14✔
368
        assert_equal('nested_anchor', schema.items.anchor)
14✔
369
      end
370
      it 'nested schema with id and fragment' do
14✔
371
        schema = metaschema.new_schema({
14✔
372
          'id' => 'http://jsi/test/schema_absolute_uri/d4/nested_w_id_frag_base',
373
          'items' => {'id' => 'http://jsi/test/schema_absolute_uri/d4/nested_w_id_frag#nested_anchor'},
374
        })
375
        assert_uri('http://jsi/test/schema_absolute_uri/d4/nested_w_id_frag', schema.items.schema_absolute_uri)
14✔
376
        assert_equal('nested_anchor', schema.items.anchor)
14✔
377
      end
378
      it 'nested schema with id with empty fragment' do
14✔
379
        schema = metaschema.new_schema({
14✔
380
          'id' => 'http://jsi/test/schema_absolute_uri/d4/nested_w_id_empty_frag_base',
381
          'items' => {'id' => '#'},
382
        })
383
        assert_nil(schema.items.schema_absolute_uri)
14✔
384
        assert_nil(schema.items.anchor)
14✔
385
      end
386
      it 'nested schema with empty id' do
14✔
387
        schema = metaschema.new_schema({
14✔
388
          'id' => 'http://jsi/test/schema_absolute_uri/d4/nested_w_empty_id_base',
389
          'items' => {'id' => ''},
390
        })
391
        assert_nil(schema.items.schema_absolute_uri)
14✔
392
        assert_nil(schema.items.anchor)
14✔
393
      end
394
      describe 'externally supplied uri' do
14✔
395
        it 'schema with relative ids' do
14✔
396
          schema = metaschema.new_schema({
14✔
397
            'id' => 'root_relative',
398
            'properties' => {
399
              'relative' => {'id' => 'nested_relative'},
400
              'absolute' => {'id' => 'http://jsi/test/d4/ignore_external_uri/nested_absolute'},
401
              'none' => {},
402
            },
403
          }, uri: 'http://jsi/test/d4/external_uri/1')
404
          assert_uri('http://jsi/test/d4/external_uri/root_relative', schema.schema_absolute_uri)
14✔
405
          assert_uri('http://jsi/test/d4/external_uri/nested_relative', schema.properties['relative'].schema_absolute_uri)
14✔
406
          assert_uri('http://jsi/test/d4/ignore_external_uri/nested_absolute', schema.properties['absolute'].schema_absolute_uri)
14✔
407
          assert_nil(schema.properties['none'].schema_absolute_uri)
14✔
408
        end
409
      end
410
      describe 'relative id uri with no base' do
14✔
411
        it 'has no schema_absolute_uri' do
14✔
412
          schema = metaschema.new_schema({
14✔
413
            'id' => 'test/d4/relative_uri',
414
          })
415
          assert_nil(schema.schema_absolute_uri)
14✔
416
          assert_nil(schema.anchor)
14✔
417
        end
418
        it 'has no schema_absolute_uri but has an anchor' do
14✔
419
          schema = metaschema.new_schema({
14✔
420
            'id' => 'test/d4/relative_uri_w_anchor#anchor',
421
          })
422
          assert_nil(schema.schema_absolute_uri)
14✔
423
          assert_equal('anchor', schema.anchor)
14✔
424
        end
425
      end
426
    end
427
    describe 'draft 6' do
14✔
428
      let(:metaschema) { JSI::JSONSchemaDraft06 }
224✔
429
      it "hasn't got one" do
14✔
430
        schema = metaschema.new_schema({})
14✔
431
        assert_nil(schema.schema_absolute_uri)
14✔
432
        assert_nil(schema.anchor)
14✔
433
      end
434
      it 'uses a given id with an empty fragment' do
14✔
435
        schema = metaschema.new_schema({'$id' => 'http://jsi/test/schema_absolute_uri/d6/empty_fragment#'})
14✔
436
        assert_uri('http://jsi/test/schema_absolute_uri/d6/empty_fragment', schema.schema_absolute_uri)
14✔
437
        assert_nil(schema.anchor)
14✔
438
      end
439
      it 'uses a given id without a fragment' do
14✔
440
        schema = metaschema.new_schema({'$id' => 'http://jsi/test/schema_absolute_uri/d6/given_id'})
14✔
441
        assert_uri('http://jsi/test/schema_absolute_uri/d6/given_id', schema.schema_absolute_uri)
14✔
442
        assert_nil(schema.anchor)
14✔
443
      end
444
      it 'nested schema without id' do
14✔
445
        schema = metaschema.new_schema({
14✔
446
          '$id' => 'http://jsi/test/schema_absolute_uri/d6/nested_no_id',
447
          'items' => {},
448
        })
449
        assert_nil(schema.items.schema_absolute_uri)
14✔
450
        assert_nil(schema.items.anchor)
14✔
451
      end
452
      it 'nested schema with absolute id' do
14✔
453
        schema = metaschema.new_schema({
14✔
454
          '$id' => 'http://jsi/test/schema_absolute_uri/d6/nested_w_abs_id_base',
455
          'items' => {'$id' => 'http://jsi/test/schema_absolute_uri/d6/nested_w_abs_id'},
456
        })
457
        assert_uri('http://jsi/test/schema_absolute_uri/d6/nested_w_abs_id', schema.items.schema_absolute_uri)
14✔
458
        assert_nil(schema.items.anchor)
14✔
459
      end
460
      it 'nested schema with relative id' do
14✔
461
        schema = metaschema.new_schema({
14✔
462
          '$id' => 'http://jsi/test/schema_absolute_uri/d6/nested_w_rel_id_base',
463
          'items' => {'$id' => 'nested_w_rel_id'},
464
        })
465
        assert_uri('http://jsi/test/schema_absolute_uri/d6/nested_w_rel_id', schema.items.schema_absolute_uri)
14✔
466
        assert_nil(schema.items.anchor)
14✔
467
      end
468
      it 'nested schema with anchor id' do
14✔
469
        schema = metaschema.new_schema({
14✔
470
          '$id' => 'http://jsi/test/schema_absolute_uri/d6/nested_w_anchor_id_base',
471
          'items' => {'$id' => '#nested_anchor'},
472
        })
473
        assert_nil(schema.items.schema_absolute_uri)
14✔
474
        assert_equal('nested_anchor', schema.items.anchor)
14✔
475
      end
476
      it 'nested schema with anchor id on the base' do
14✔
477
        schema = metaschema.new_schema({
14✔
478
          '$id' => 'http://jsi/test/schema_absolute_uri/d6/nested_w_anchor_on_base',
479
          'items' => {'$id' => 'http://jsi/test/schema_absolute_uri/d6/nested_w_anchor_on_base#nested_anchor'},
480
        })
481
        assert_nil(schema.items.schema_absolute_uri)
14✔
482
        assert_equal('nested_anchor', schema.items.anchor)
14✔
483
      end
484
      it 'nested schema with anchor id on the base after resolution' do
14✔
485
        schema = metaschema.new_schema({
14✔
486
          '$id' => 'http://jsi/test/schema_absolute_uri/d6/nested_w_anchor_on_base_rel',
487
          'items' => {'$id' => 'nested_w_anchor_on_base_rel#nested_anchor'},
488
        })
489
        assert_nil(schema.items.schema_absolute_uri)
14✔
490
        assert_equal('nested_anchor', schema.items.anchor)
14✔
491
      end
492
      it 'nested schema with id and fragment' do
14✔
493
        schema = metaschema.new_schema({
14✔
494
          '$id' => 'http://jsi/test/schema_absolute_uri/d6/nested_w_id_frag_base',
495
          'items' => {'$id' => 'http://jsi/test/schema_absolute_uri/d6/nested_w_id_frag#nested_anchor'},
496
        })
497
        assert_uri('http://jsi/test/schema_absolute_uri/d6/nested_w_id_frag', schema.items.schema_absolute_uri)
14✔
498
        assert_equal('nested_anchor', schema.items.anchor)
14✔
499
      end
500
      it 'nested schema with id with empty fragment' do
14✔
501
        schema = metaschema.new_schema({
14✔
502
          '$id' => 'http://jsi/test/schema_absolute_uri/d6/nested_w_id_empty_frag_base',
503
          'items' => {'$id' => '#'},
504
        })
505
        assert_nil(schema.items.schema_absolute_uri)
14✔
506
        assert_nil(schema.items.anchor)
14✔
507
      end
508
      it 'nested schema with empty id' do
14✔
509
        schema = metaschema.new_schema({
14✔
510
          '$id' => 'http://jsi/test/schema_absolute_uri/d6/nested_w_empty_id_base',
511
          'items' => {'$id' => ''},
512
        })
513
        assert_nil(schema.items.schema_absolute_uri)
14✔
514
        assert_nil(schema.items.anchor)
14✔
515
      end
516
      describe 'externally supplied uri' do
14✔
517
        it 'schema with relative ids' do
14✔
518
          schema = metaschema.new_schema({
14✔
519
            '$id' => 'root_relative',
520
            'properties' => {
521
              'relative' => {'$id' => 'nested_relative'},
522
              'absolute' => {'$id' => 'http://jsi/test/d6/ignore_external_uri/nested_absolute'},
523
              'none' => {},
524
            },
525
          }, uri: 'http://jsi/test/d6/external_uri/0')
526
          assert_uri('http://jsi/test/d6/external_uri/root_relative', schema.schema_absolute_uri)
14✔
527
          assert_uri('http://jsi/test/d6/external_uri/nested_relative', schema.properties['relative'].schema_absolute_uri)
14✔
528
          assert_uri('http://jsi/test/d6/ignore_external_uri/nested_absolute', schema.properties['absolute'].schema_absolute_uri)
14✔
529
          assert_nil(schema.properties['none'].schema_absolute_uri)
14✔
530
        end
531
      end
532
      describe 'relative id uri with no base' do
14✔
533
        it 'has no schema_absolute_uri' do
14✔
534
          schema = metaschema.new_schema({
14✔
535
            '$id' => 'test/d6/relative_uri',
536
          })
537
          assert_nil(schema.schema_absolute_uri)
14✔
538
          assert_nil(schema.anchor)
14✔
539
        end
540
        it 'has no schema_absolute_uri but has an anchor' do
14✔
541
          schema = metaschema.new_schema({
14✔
542
            '$id' => 'test/d6/relative_uri_w_anchor#anchor',
543
          })
544
          assert_nil(schema.schema_absolute_uri)
14✔
545
          assert_equal('anchor', schema.anchor)
14✔
546
        end
547
      end
548
    end
549
    describe 'externally supplied uri with JSI.new_schema' do
14✔
550
      it 'resolves' do
14✔
551
        schema = JSI.new_schema(
14✔
552
          {'$schema' => 'http://json-schema.org/draft-07/schema#', '$id' => 'tehschema'},
553
          uri: 'http://jsi/test/schema_absolute_uri/schema.new_base/0',
554
        )
555
        assert_uri('http://jsi/test/schema_absolute_uri/schema.new_base/tehschema', schema.schema_absolute_uri)
14✔
556
      end
557
    end
558
  end
559
  describe '#jsi_schema_module' do
14✔
560
    it 'returns the module for the schema' do
14✔
561
      schema = JSI::JSONSchemaDraft07.new_schema({'$id' => 'http://jsi/schema/jsi_schema_module'})
14✔
562
      assert_is_a(JSI::SchemaModule, schema.jsi_schema_module)
14✔
563
      assert_equal(schema, schema.jsi_schema_module.schema)
14✔
564
    end
565

566
    it 'returns the same module for equal schemas' do
14✔
567
      schema = JSI::JSONSchemaDraft07.new_schema({'$id' => 'http://jsi/schema/jsi_schema_module_eq'})
14✔
568
      schema_again = JSI::JSONSchemaDraft07.new_schema({'$id' => 'http://jsi/schema/jsi_schema_module_eq'})
14✔
569
      assert_equal(schema.jsi_schema_module, schema_again.jsi_schema_module)
14✔
570
    end
571
  end
572

573
  describe '#jsi_schema_module_exec' do
14✔
574
    it 'evaluates the block on the schema module' do
14✔
575
      schema = JSI::JSONSchemaDraft07.new_schema({'id' => 'https://schemas.jsi.unth.net/test/jsi_schema_module_exec'})
14✔
576
      schema.jsi_schema_module_exec(foo: 'foo') { |foo: | define_method(:foo) { foo } }
42✔
577
      assert_equal('foo', schema.new_jsi({}).foo)
14✔
578
    end
579
  end
580

581
  describe '#subschema error conditions' do
14✔
582
    describe 'the subschema is not a schema' do
14✔
583
      it 'errors with a Base - subschema key is not described' do
14✔
584
        schema = JSI::JSONSchemaDraft07.new_schema({
14✔
585
          'foo' => {},
586
        })
587
        err = assert_raises(JSI::Schema::NotASchemaError) do
14✔
588
          schema.subschema(['foo'])
14✔
589
        end
590
        msg = <<~MSG
14✔
591
          subschema is not a schema at pointer: /foo
592
          \#{<JSI>}
593
          MSG
594
        assert_equal(msg.chomp, err.message)
14✔
595
      end
596

597
      it 'errors with a Base - subschema key is described, not a schema' do
14✔
598
        schema = JSI::JSONSchemaDraft07.new_schema({
14✔
599
          'properties' => {},
600
        })
601
        err = assert_raises(JSI::Schema::NotASchemaError) do
14✔
602
          schema.subschema(['properties'])
14✔
603
        end
604
        msg = <<~MSG
14✔
605
          subschema is not a schema at pointer: /properties
606
          \#{<JSI (JSI::JSONSchemaDraft07::Properties)>}
607
          MSG
608
        assert_equal(msg.chomp, err.message)
14✔
609
      end
610
    end
611
  end
612

613
  describe '#child_applicator_schemas with an object' do
14✔
614
    let(:schema) do
14✔
615
      JSI::JSONSchemaDraft07.new_schema({
56✔
616
        properties: {
617
          foo: {description: 'foo'},
618
          baz: {description: 'baz'},
619
        },
620
        patternProperties: {
621
          "^b" => {description: 'b*'},
622
        },
623
        additionalProperties: {description: 'whatever'},
624
      })
625
    end
626
    it 'has no subschemas' do
14✔
627
      assert_empty(JSI::JSONSchemaDraft07.new_schema({}).child_applicator_schemas('no', {}))
14✔
628
    end
629
    it 'has a subschema by property' do
14✔
630
      subschemas = schema.child_applicator_schemas('foo', {}).to_a
14✔
631
      assert_equal(1, subschemas.size)
14✔
632
      assert_is_a(JSI::JSONSchemaDraft07, subschemas[0])
14✔
633
      assert_equal('foo', subschemas[0].description)
14✔
634
    end
635
    it 'has subschemas by patternProperties' do
14✔
636
      subschemas = schema.child_applicator_schemas('bar', {}).to_a
14✔
637
      assert_equal(1, subschemas.size)
14✔
638
      assert_is_a(JSI::JSONSchemaDraft07, subschemas[0])
14✔
639
      assert_equal('b*', subschemas[0].description)
14✔
640
    end
641
    it 'has subschemas by properties, patternProperties' do
14✔
642
      subschemas = schema.child_applicator_schemas('baz', {}).to_a
14✔
643
      assert_equal(2, subschemas.size)
14✔
644
      assert_is_a(JSI::JSONSchemaDraft07, subschemas[0])
14✔
645
      assert_equal('baz', subschemas[0].description)
14✔
646
      assert_is_a(JSI::JSONSchemaDraft07, subschemas[1])
14✔
647
      assert_equal('b*', subschemas[1].description)
14✔
648
    end
649
    it 'has subschemas by additional properties' do
14✔
650
      subschemas = schema.child_applicator_schemas('anything', {}).to_a
14✔
651
      assert_equal(1, subschemas.size)
14✔
652
      assert_is_a(JSI::JSONSchemaDraft07, subschemas[0])
14✔
653
      assert_equal('whatever', subschemas[0].description)
14✔
654
    end
655
  end
656
  describe '#child_applicator_schemas with an array instance' do
14✔
657
    it 'has no subschemas' do
14✔
658
      assert_empty(JSI::JSONSchemaDraft07.new_schema({}).child_applicator_schemas(0, []))
14✔
659
    end
660
    it 'has a subschema for items' do
14✔
661
      schema = JSI::JSONSchemaDraft07.new_schema({
14✔
662
        items: {description: 'items!'}
663
      })
664
      first_subschemas = schema.child_applicator_schemas(0, []).to_a
14✔
665
      assert_equal(1, first_subschemas.size)
14✔
666
      assert_is_a(JSI::JSONSchemaDraft07, first_subschemas[0])
14✔
667
      assert_equal('items!', first_subschemas[0].description)
14✔
668
      last_subschemas = schema.child_applicator_schemas(1, []).to_a
14✔
669
      assert_equal(1, last_subschemas.size)
14✔
670
      assert_is_a(JSI::JSONSchemaDraft07, last_subschemas[0])
14✔
671
      assert_equal('items!', last_subschemas[0].description)
14✔
672
    end
673
    it 'has a subschema for each item by index' do
14✔
674
      schema = JSI::JSONSchemaDraft07.new_schema({
14✔
675
        items: [{description: 'item one'}, {description: 'item two'}]
676
      })
677
      first_subschemas = schema.child_applicator_schemas(0, []).to_a
14✔
678
      assert_equal(1, first_subschemas.size)
14✔
679
      assert_is_a(JSI::JSONSchemaDraft07, first_subschemas[0])
14✔
680
      assert_equal('item one', first_subschemas[0].description)
14✔
681
      last_subschemas = schema.child_applicator_schemas(1, []).to_a
14✔
682
      assert_equal(1, last_subschemas.size)
14✔
683
      assert_is_a(JSI::JSONSchemaDraft07, last_subschemas[0])
14✔
684
      assert_equal('item two', last_subschemas[0].description)
14✔
685
    end
686
    it 'has a subschema by additional items' do
14✔
687
      schema = JSI::JSONSchemaDraft07.new_schema({
14✔
688
        items: [{description: 'item one'}],
689
        additionalItems: {description: "mo' crap"},
690
      })
691
      first_subschemas = schema.child_applicator_schemas(0, []).to_a
14✔
692
      assert_equal(1, first_subschemas.size)
14✔
693
      assert_is_a(JSI::JSONSchemaDraft07, first_subschemas[0])
14✔
694
      assert_equal('item one', first_subschemas[0].description)
14✔
695
      last_subschemas = schema.child_applicator_schemas(1, []).to_a
14✔
696
      assert_equal(1, last_subschemas.size)
14✔
697
      assert_is_a(JSI::JSONSchemaDraft07, last_subschemas[0])
14✔
698
      assert_equal("mo' crap", last_subschemas[0].description)
14✔
699
    end
700
  end
701
  describe 'stringification' do
14✔
702
    let(:schema) do
14✔
703
      JSI.new_schema({
28✔
704
        "$schema": "http://json-schema.org/draft-06/schema",
705
        "$id": "http://jsi/schema/stringification",
706
        "type": ["object", "array"],
707
        "properties": {
708
          "foo": {
709
            "items": {"$ref": "#/definitions/no"}
710
          },
711
        },
712
        "items": [
713
          {"dependencies": {"a": ["b"]}},
714
          {"dependencies": {"a": {}}},
715
        ],
716
        "definitions": {
717
          "no": {"enum": []}
718
        }
719
      })
720
    end
721

722
    it '#inspect' do
14✔
723
      assert_equal(%q(#{<JSI (JSI::JSONSchemaDraft06) Schema> "$schema" => "http://json-schema.org/draft-06/schema", "$id" => "http://jsi/schema/stringification", "type" => #[<JSI (JSI::JSONSchemaDraft06::Type, JSI::JSONSchemaDraft06::Type::Array)> "object", "array"], "properties" => #{<JSI (JSI::JSONSchemaDraft06::Properties)> "foo" => #{<JSI (JSI::JSONSchemaDraft06) Schema> "items" => #{<JSI (JSI::JSONSchemaDraft06::Items, JSI::JSONSchemaDraft06) Schema> "$ref" => "#/definitions/no"}}}, "items" => #[<JSI (JSI::JSONSchemaDraft06::Items, JSI::JSONSchemaDraft06::SchemaArray)> #{<JSI (JSI::JSONSchemaDraft06) Schema> "dependencies" => #{<JSI (JSI::JSONSchemaDraft06::Dependencies)> "a" => #[<JSI (JSI::JSONSchemaDraft06::Dependencies::Dependency, JSI::JSONSchemaDraft06::StringArray)> "b"]}}, #{<JSI (JSI::JSONSchemaDraft06) Schema> "dependencies" => #{<JSI (JSI::JSONSchemaDraft06::Dependencies)> "a" => #{<JSI (JSI::JSONSchemaDraft06::Dependencies::Dependency, JSI::JSONSchemaDraft06) Schema>}}}], "definitions" => #{<JSI (JSI::JSONSchemaDraft06::Definitions)> "no" => #{<JSI (JSI::JSONSchemaDraft06) Schema> "enum" => #[<JSI (JSI::JSONSchemaDraft06::Enum)>]}}}), schema.inspect)
14✔
724
    end
725
    it '#pretty_print' do
14✔
726
      pp = <<~PP
14✔
727
        \#{<JSI (JSI::JSONSchemaDraft06) Schema>
728
          "$schema" => "http://json-schema.org/draft-06/schema",
729
          "$id" => "http://jsi/schema/stringification",
730
          "type" => #[<JSI (JSI::JSONSchemaDraft06::Type, JSI::JSONSchemaDraft06::Type::Array)>
731
            "object",
732
            "array"
733
          ],
734
          "properties" => \#{<JSI (JSI::JSONSchemaDraft06::Properties)>
735
            "foo" => \#{<JSI (JSI::JSONSchemaDraft06) Schema>
736
              "items" => \#{<JSI (JSI::JSONSchemaDraft06::Items, JSI::JSONSchemaDraft06) Schema>
737
                "$ref" => "#/definitions/no"
738
              }
739
            }
740
          },
741
          "items" => #[<JSI (JSI::JSONSchemaDraft06::Items, JSI::JSONSchemaDraft06::SchemaArray)>
742
            \#{<JSI (JSI::JSONSchemaDraft06) Schema>
743
              "dependencies" => \#{<JSI (JSI::JSONSchemaDraft06::Dependencies)>
744
                "a" => #[<JSI (JSI::JSONSchemaDraft06::Dependencies::Dependency, JSI::JSONSchemaDraft06::StringArray)>
745
                  "b"
746
                ]
747
              }
748
            },
749
            \#{<JSI (JSI::JSONSchemaDraft06) Schema>
750
              "dependencies" => \#{<JSI (JSI::JSONSchemaDraft06::Dependencies)>
751
                "a" => \#{<JSI (JSI::JSONSchemaDraft06::Dependencies::Dependency, JSI::JSONSchemaDraft06) Schema>}
752
              }
753
            }
754
          ],
755
          "definitions" => \#{<JSI (JSI::JSONSchemaDraft06::Definitions)>
756
            "no" => \#{<JSI (JSI::JSONSchemaDraft06) Schema>
757
              "enum" => #[<JSI (JSI::JSONSchemaDraft06::Enum)>]
758
            }
759
          }
760
        }
761
        PP
762
      assert_equal(pp, schema.pretty_inspect)
14✔
763
    end
764
  end
765

766
  describe 'stringification, thorough for draft 7' do
14✔
767
    let(:recursive_default_child_as_jsi_true) do
14✔
768
      JSI::SimpleWrap::METASCHEMA.new_schema(:recursive_default_child_as_jsi_true) do
14✔
769
        redef_method(:jsi_child_as_jsi_default) { true }
3,822✔
770
      end
771
    end
772

773
    let(:schema) do
14✔
774
      JSI::SchemaSet[JSI::JSONSchemaDraft07.schema, recursive_default_child_as_jsi_true].new_jsi(YAML.load(<<~YAML
14✔
775
        $schema: "http://json-schema.org/draft-07/schema#"
776
        description:
777
          A schema containing each keyword of the meta-schema with valid and invalid type / structure of the keyword value
778
        definitions:
779
          "true": true
780
          "false": false
781
          empty: {}
782
          invalid-int: 0
783
          invalid-array: []
784
          id: {$id: "tag:test"}
785
          id-int: {$id: 0}
786
          schema: {$schema: "tag:test"}
787
          schema-int: {$schema: 0}
788
          ref: {$ref: "#"}
789
          ref-int: {$ref: 0}
790
          comment: {$comment: "comment"}
791
          comment-int: {$comment: 0}
792
          title: {title: "title"}
793
          title-int: {title: 0}
794
          description: {description: "description"}
795
          description-int: {description: 0}
796
          default: {default: [default]}
797
          readOnly: {readOnly: true}
798
          readOnly-int: {readOnly: 0}
799
          examples: {examples: [{}, x]}
800
          examples-dict: {examples: {x: 0}}
801
          multipleOf: {multipleOf: 1}
802
          multipleOf-ary: {multipleOf: []}
803
          maximum: {maximum: 0}
804
          maximum-ary: {maximum: [0]}
805
          exclusiveMaximum: {exclusiveMaximum: 0}
806
          exclusiveMaximum-ary: {exclusiveMaximum: [0]}
807
          minimum: {minimum: 0}
808
          minimum-ary: {minimum: [0]}
809
          exclusiveMinimum: {exclusiveMinimum: 0}
810
          exclusiveMinimum-ary: {exclusiveMinimum: [0]}
811
          maxLength: {maxLength: 0}
812
          maxLength-ary: {maxLength: []}
813
          minLength: {minLength: 0}
814
          minLength-ary: {minLength: []}
815
          maxItems: {maxItems: 0}
816
          maxItems-ary: {maxItems: []}
817
          minItems: {minItems: 0}
818
          minItems-ary: {minItems: []}
819
          maxProperties: {maxProperties: 0}
820
          maxProperties-ary: {maxProperties: []}
821
          minProperties: {minProperties: 0}
822
          minProperties-ary: {minProperties: []}
823
          pattern: {pattern: "pattern"}
824
          pattern-int: {pattern: 0}
825
          additionalItems: {additionalItems: {}}
826
          additionalItems-int: {additionalItems: 0}
827
          items: {items: {}}
828
          items-ary: {items: [{}]}
829
          items-ary-int: {items: [0]}
830
          items-int: {items: 0}
831
          uniqueItems: {uniqueItems: true}
832
          uniqueItems-int: {uniqueItems: 0}
833
          contains: {contains: {}}
834
          contains-int: {contains: 0}
835
          required: {required: [a]}
836
          required-ary-int: {required: [0]}
837
          required-int: {required: 0}
838
          additionalProperties: {additionalProperties: {}}
839
          additionalProperties-int: {additionalProperties: 0}
840
          definitions: {definitions: {definition: {}}}
841
          definitions-schema-int: {definitions: {definition: 0}}
842
          definitions-ary: {definitions: [{}]}
843
          definitions-int: {definitions: 0}
844
          properties: {properties: {property: {}}}
845
          properties-schema-int: {properties: {property: 0}}
846
          properties-ary: {properties: [{}]}
847
          properties-int: {properties: 0}
848
          patternProperties: {patternProperties: {patternProperty: {}}}
849
          patternProperties-schema-int: {patternProperties: {patternProperty: 0}}
850
          patternProperties-ary: {patternProperties: [{}]}
851
          patternProperties-int: {patternProperties: 0}
852
          dependencies: {dependencies: {}}
853
          dependencies-dep-schema: {dependencies: {s: {}}}
854
          dependencies-dep-strary: {dependencies: {a: [b]}}
855
          dependencies-dep-schema+strary: {dependencies: {a: [b], s: {}}}
856
          dependencies-dep-int: {dependencies: {i: 0}}
857
          dependencies-dep-schema+strary+int: {dependencies: {s: {}, a: [b], i: 0}}
858
          dependencies-ary: {dependencies: [{a: {}}]}
859
          dependencies-int: {dependencies: 0}
860
          propertyNames: {propertyNames: {}}
861
          propertyNames-int: {propertyNames: 0}
862
          const: {const: {}}
863
          enum: {enum: [{}]}
864
          enum-int: {enum: 0}
865
          type: {type: string}
866
          type-badstr: {type: a}
867
          type-ary: {type: [string]}
868
          type-ary-badstr: {type: [a]}
869
          type-ary-int: {type: [0]}
870
          type-int: {type: 0}
871
          format: {format: "format"}
872
          format-int: {format: 0}
873
          contentMediaType: {contentMediaType: "contentMediaType"}
874
          contentMediaType-int: {contentMediaType: 0}
875
          contentEncoding: {contentEncoding: "contentEncoding"}
876
          contentEncoding-int: {contentEncoding: 0}
877
          if: {if: {}}
878
          if-int: {if: 0}
879
          then: {then: {}}
880
          then-int: {then: 0}
881
          else: {else: {}}
882
          else-int: {else: 0}
883
          allOf: {allOf: [{}]}
884
          allOf-ary-int: {allOf: [0]}
885
          allOf-int: {allOf: 0}
886
          anyOf: {anyOf: [{}]}
887
          anyOf-ary-int: {anyOf: [0]}
888
          anyOf-int: {anyOf: 0}
889
          oneOf: {oneOf: [{}]}
890
          oneOf-ary-int: {oneOf: [0]}
891
          oneOf-int: {oneOf: 0}
892
          not: {not: {}}
893
          not-int: {not: 0}
894
        YAML
895
      ))
896
    end
897

898
    it '#pretty_print' do
14✔
899
      pppath = JSI::TEST_RESOURCES_PATH.join('schema.thorough.pretty_print')
14✔
900
      if ENV['JSI_TEST_REGEN']
14✔
901
        pppath.write(schema.pretty_inspect)
×
902
      end
903
      assert_equal(pppath.read, schema.pretty_inspect)
14✔
904
    end
905
  end
906

907
  describe 'validation' do
14✔
908
    let(:schema) { JSI::JSONSchemaDraft07.new_schema({'$id' => 'http://jsi/schema/validation', type: 'object'}) }
70✔
909
    describe 'without errors' do
14✔
910
      let(:instance) { {'foo' => 'bar'} }
42✔
911
      it '#instance_validate' do
14✔
912
        result = schema.instance_validate(instance)
14✔
913
        assert_equal(true, result.valid?)
14✔
914
        assert_equal(Set[], result.validation_errors)
14✔
915
        assert_equal(Set[], result.schema_issues)
14✔
916
      end
917
      it '#instance_valid?' do
14✔
918
        assert_equal(true, schema.instance_valid?(instance))
14✔
919
      end
920
    end
921
    describe 'with errors' do
14✔
922
      let(:instance) { ['no'] }
42✔
923
      it '#instance_validate' do
14✔
924
        result = schema.instance_validate(instance)
14✔
925
        assert_equal(false, result.valid?)
14✔
926
        assert_equal(Set[
16✔
927
          JSI::Validation::Error.new({
928
            :message => "instance type does not match `type` value",
929
            :keyword => "type",
930
            :schema => schema,
931
            :instance_ptr => JSI::Ptr[], :instance_document => ["no"],
932
          }),
933
        ], result.validation_errors)
934
        assert_equal(Set[], result.schema_issues)
14✔
935
      end
936
      it '#instance_valid?' do
14✔
937
        assert_equal(false, schema.instance_valid?(instance))
14✔
938
      end
939
    end
940
  end
941
end
942

943
$test_report_file_loaded[__FILE__]
14✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc