json_schema 0.20.1 → 0.20.2

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: e102114f71484ad7ec4468d6433422c08d7e9a02e20bf635fe7c9a891fce1f99
4
- data.tar.gz: 63012a87275d8ee64e9465a5b7998d7db859990d9da99ee197153061e1a00c91
3
+ metadata.gz: f8995d131af07bfdde3422f2a9cac2a8aaaab975c98692bb944bb8430847cda1
4
+ data.tar.gz: 893dfed770a20c6e7e66b2a8c0bd8a3defae02a7f2413f839a23df45344028bc
5
5
  SHA512:
6
- metadata.gz: 3e7481a34dd6f9c56684b387c200afed357dd30fca5d443a1a55ce3eb2b9b75535feb05c4682763b464b882cc1c0cf1a80255bf344e897b8b1f7892a0019225f
7
- data.tar.gz: 1175aed4f46aeea66c9d8d65288f6e7a2c9f232bd1f47fdfed342b79259e08975e8b2c795d1fe75e7da563d9d5c171a3ac4b88b6e0045b6c5e965d060bcc28c0
6
+ metadata.gz: 126055feefc345b2eb5df31af7e0536569d1054ed2ba14d0976ad441078bf577cbaa320b8cbfc1de5da50018ba2bb6463ad60216a9bfbda0622677cc865aa62f
7
+ data.tar.gz: 03b6f5215269dbd62323fec83204316bc3ab8b143185ec1a4bfe6be67a79fa88406d2ef05ce63f372525ceb411a9e7e3878470b6303702b3b1cbeca2aa2d19d0
@@ -105,6 +105,29 @@ module JsonSchema
105
105
  return false unless success
106
106
  end
107
107
 
108
+ # If the reference schema is a global reference
109
+ # then we'll need to manually expand any nested
110
+ # references.
111
+ if ref.uri
112
+ schema_children(new_schema) do |subschema|
113
+ next if subschema.expanded?
114
+ next unless subschema.reference
115
+
116
+ # Don't bother if the subschema points to the same
117
+ # schema as the reference schema.
118
+ next if ref_schema == subschema
119
+
120
+ subref = subschema.reference
121
+ # the subschema's ref is local to the file that the
122
+ # subschema is in; however since there's no URI
123
+ # the 'resolve_pointer' method would try to look it up
124
+ # within @schema. So: manually reconstruct the reference to
125
+ # use the URI of the parent ref.
126
+ subschema.reference = JsonReference::Reference.new("#{ref.uri}#{subref.pointer}")
127
+ dereference(subschema, ref_stack + [subref])
128
+ end
129
+ end
130
+
108
131
  # copy new schema into existing one while preserving parent, fragment,
109
132
  # and reference
110
133
  parent = ref_schema.parent
@@ -265,6 +265,57 @@ 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 with a nested property reference" do
269
+ sample1 = {
270
+ "$schema" => "http://json-schema.org/draft-04/hyper-schema",
271
+ "type" => "object",
272
+ "properties" => {
273
+ "foo" => {
274
+ "$ref" => "http://json-schema.org/b.json#/definitions/bar"
275
+ },
276
+ "foo2" => {
277
+ "$ref" => "http://json-schema.org/b.json#/definitions/baz"
278
+ }
279
+ }
280
+ }
281
+ schema1 = JsonSchema::Parser.new.parse!(sample1)
282
+ schema1.uri = "http://json-schema.org/a.json"
283
+
284
+ sample2 = {
285
+ "$schema" => "http://json-schema.org/draft-04/hyper-schema",
286
+ "type" => "object",
287
+ "definitions" => {
288
+ "bar" => {
289
+ "type" => "object",
290
+ "properties" => {
291
+ "omg" => {
292
+ "$ref" => "#/definitions/baz"
293
+ }
294
+ }
295
+ },
296
+ "baz" => {
297
+ "type" => "string",
298
+ "maxLength" => 3
299
+ }
300
+ }
301
+ }
302
+ schema2 = JsonSchema::Parser.new.parse!(sample2)
303
+ schema2.uri = "http://json-schema.org/b.json"
304
+
305
+ # Initialize a store and add our schema to it.
306
+ store = JsonSchema::DocumentStore.new
307
+ store.add_schema(schema1)
308
+ store.add_schema(schema2)
309
+
310
+ expander = JsonSchema::ReferenceExpander.new
311
+ expander.expand!(schema1, store: store)
312
+
313
+ # These both point to the same definition, 'baz', but
314
+ # 'foo' has a level of indirection.
315
+ assert_equal 3, schema1.properties["foo2"].max_length
316
+ assert_equal 3, schema1.properties["foo"].properties["omg"].max_length
317
+ end
318
+
268
319
  it "expands a reference to a link" do
269
320
  pointer("#/properties").merge!(
270
321
  "link" => { "$ref" => "#/links/0" }
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.1
4
+ version: 0.20.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-04 00:00:00.000000000 Z
11
+ date: 2019-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ecma-re-validator