json_schema 0.20.1 → 0.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/json_schema/reference_expander.rb +23 -0
- data/test/json_schema/reference_expander_test.rb +51 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8995d131af07bfdde3422f2a9cac2a8aaaab975c98692bb944bb8430847cda1
|
4
|
+
data.tar.gz: 893dfed770a20c6e7e66b2a8c0bd8a3defae02a7f2413f839a23df45344028bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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-
|
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
|