json_schema 0.20.4 → 0.20.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b59e2abb8260fc05004ddde201c9107a0be38149e0dbf9aff1f3d774e5d5ae8
4
- data.tar.gz: b40758dada1ba42ac46f7aa45c9370eae4d9ef5178126813fff6ba6ad8ab0ece
3
+ metadata.gz: 6f22094d77a8c40595f358c40c431ce2b86e694403bf310854046e069377dc83
4
+ data.tar.gz: 131983e9114e14eb15d87de99571631644827fbe40927f1a9912443343c474e7
5
5
  SHA512:
6
- metadata.gz: e06bc21c170498b1bcb09b1142a1971b64c8c9e376b395e72017d0aab538eacf54c1061e1a09be7e633734f75706fafe399b9272d9ac633fc7976b4d8084decc
7
- data.tar.gz: 98cb1d66418ebcdfe94367c01e946c210f7f79ffa89ee3daa609876398753cb7239c9e8f189087f01f81d33b55f4f038764d21d8da64049c6cc5dfd0034606aa
6
+ metadata.gz: d8dd23eb8a3e81fa88b4fe77d03b46289f687827c6eb92db29cce1daf41d1fe154a20840e918cb1be0580746929a2db68515795be6f1746fa9f0c649ecd15a2c
7
+ data.tar.gz: 2b7e8a4c19049c24fde7faa579bf7c21f1e650b5e9ba1a72b83b5cf899f560ef92b9d8883585adc1b663fa005e3d9980412f536bc988c7af97080ee74471579c
@@ -146,6 +146,17 @@ module JsonSchema
146
146
  end
147
147
  end
148
148
 
149
+ if subschema.items && subschema.items.reference
150
+ next if subschema.expanded?
151
+
152
+ if !subschema.items.reference.uri
153
+ # The subschema's ref is local to the file that the
154
+ # subschema is in. Manually reconstruct the reference
155
+ # so we can resolve it.
156
+ subschema.items.reference = JsonReference::Reference.new("#{ref.uri}#{subschema.items.reference.pointer}")
157
+ end
158
+ end
159
+
149
160
  # If we're recursing into a schema via a global reference, then if
150
161
  # the current subschema doesn't have a reference, we have no way of
151
162
  # figuring out what schema we're in. The resolve_pointer method will
@@ -265,6 +265,87 @@ describe JsonSchema::ReferenceExpander do
265
265
  assert schema.expanded?
266
266
  end
267
267
 
268
+ it "expands a schema with a reference to an external schema in a oneOf array" do
269
+ sample1 = {
270
+ "$schema" => "http://json-schema.org/draft-04/schema#",
271
+ "id" => "http://json-schema.org/draft-04/schema#",
272
+ "definitions" => {
273
+ "schemaArray" => {
274
+ "type" => "array",
275
+ "minItems" => 1,
276
+ "items" => { "$ref" => "#" }
277
+ }
278
+ }
279
+ }
280
+ schema1 = JsonSchema::Parser.new.parse!(sample1)
281
+
282
+ sample2 = {
283
+ "$schema" => "http://json-schema.org/draft-04/hyper-schema#",
284
+ "id" => "http://json-schema.org/draft-04/hyper-schema#",
285
+ "allOf" => [
286
+ {
287
+ "$ref" => "http://json-schema.org/draft-04/schema#"
288
+ }
289
+ ]
290
+ }
291
+ schema2 = JsonSchema::Parser.new.parse!(sample2)
292
+
293
+ store = JsonSchema::DocumentStore.new
294
+ expander = JsonSchema::ReferenceExpander.new
295
+
296
+ store.add_schema(schema1)
297
+ store.add_schema(schema2)
298
+
299
+ expander.expand!(schema2, store: store)
300
+
301
+ assert schema1.expanded?
302
+ assert schema2.expanded?
303
+ end
304
+
305
+ it "expands a schema with a nested reference to an external schema in a oneOf array" do
306
+ sample1 = {
307
+ "$schema" => "http://json-schema.org/draft-04/schema#",
308
+ "id" => "http://json-schema.org/draft-04/schema#",
309
+ "definitions" => {
310
+ "thingy" => {
311
+ "type" => ["string"]
312
+ },
313
+ "schemaArray" => {
314
+ "type" => "array",
315
+ "minItems" => 1,
316
+ "items" => { "$ref" => "#/definitions/thingy" }
317
+ }
318
+ },
319
+ "properties" => {
320
+ "whatsit" => {
321
+ "$ref" => "#/definitions/schemaArray"
322
+ },
323
+ }
324
+ }
325
+ schema1 = JsonSchema::Parser.new.parse!(sample1)
326
+
327
+ sample2 = {
328
+ "$schema" => "http://json-schema.org/draft-04/hyper-schema#",
329
+ "id" => "http://json-schema.org/draft-04/hyper-schema#",
330
+ "allOf" => [
331
+ {
332
+ "$ref" => "http://json-schema.org/draft-04/schema#"
333
+ }
334
+ ]
335
+ }
336
+ schema2 = JsonSchema::Parser.new.parse!(sample2)
337
+
338
+ store = JsonSchema::DocumentStore.new
339
+ expander = JsonSchema::ReferenceExpander.new
340
+
341
+ store.add_schema(schema1)
342
+ store.add_schema(schema2)
343
+
344
+ expander.expand!(schema2, store: store)
345
+
346
+ assert_equal ["string"], schema2.all_of[0].properties["whatsit"].items.type
347
+ end
348
+
268
349
  it "expands a schema with a reference to an external schema with a nested external property reference" do
269
350
  sample1 = {
270
351
  "$schema" => "http://json-schema.org/draft-04/hyper-schema",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.4
4
+ version: 0.20.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-12 00:00:00.000000000 Z
11
+ date: 2019-05-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  requirements: []
72
72
  rubyforge_project:
73
- rubygems_version: 2.7.3
73
+ rubygems_version: 2.7.7
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: A JSON Schema V4 and Hyperschema V4 parser and validator.