json_schema 0.20.1 → 0.20.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/json_schema/reference_expander.rb +24 -0
- data/test/json_schema/reference_expander_test.rb +106 -0
- metadata +3 -101
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45216e42386e80c6e481d45fafb3bcecad1c55cde5137efb455bb45261e87424
|
4
|
+
data.tar.gz: 8764080e6a1c38b519110a8001b53ebda5864e7b16cdf418b272459542f60e1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f43b198fc8050550fb78d3a96ad14dff765fdcce80b5ae73ce080e6fb13600697658cf3b9d2b73e1ed9adc0d40cedfb890047696778dc5e3770dead5889e666
|
7
|
+
data.tar.gz: 6f30c6b07f81396b3f7366fd30186b83ddbf1ef474e375838c77df5a635b96bc2ac4dc4bf2036789a235f19efa3bc22ac76c246d31db9a697b8235790f045c4b
|
@@ -105,6 +105,30 @@ 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
|
+
if !subschema.reference.uri
|
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}#{subschema.reference.pointer}")
|
127
|
+
end
|
128
|
+
dereference(subschema, ref_stack)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
108
132
|
# copy new schema into existing one while preserving parent, fragment,
|
109
133
|
# and reference
|
110
134
|
parent = ref_schema.parent
|
@@ -265,6 +265,112 @@ 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 external 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
|
+
}
|
277
|
+
}
|
278
|
+
schema1 = JsonSchema::Parser.new.parse!(sample1)
|
279
|
+
schema1.uri = "http://json-schema.org/a.json"
|
280
|
+
|
281
|
+
sample2 = {
|
282
|
+
"$schema" => "http://json-schema.org/draft-04/hyper-schema",
|
283
|
+
"type" => "object",
|
284
|
+
"definitions" => {
|
285
|
+
"bar" => {
|
286
|
+
"type" => "object",
|
287
|
+
"properties" => {
|
288
|
+
"omg" => {
|
289
|
+
"$ref" => "http://json-schema.org/c.json#/definitions/baz"
|
290
|
+
}
|
291
|
+
}
|
292
|
+
}
|
293
|
+
}
|
294
|
+
}
|
295
|
+
schema2 = JsonSchema::Parser.new.parse!(sample2)
|
296
|
+
schema2.uri = "http://json-schema.org/b.json"
|
297
|
+
|
298
|
+
sample3 = {
|
299
|
+
"$schema" => "http://json-schema.org/draft-04/hyper-schema",
|
300
|
+
"type" => "object",
|
301
|
+
"definitions" => {
|
302
|
+
"baz" => {
|
303
|
+
"type" => "string",
|
304
|
+
"maxLength" => 3
|
305
|
+
}
|
306
|
+
}
|
307
|
+
}
|
308
|
+
schema3 = JsonSchema::Parser.new.parse!(sample3)
|
309
|
+
schema3.uri = "http://json-schema.org/c.json"
|
310
|
+
|
311
|
+
# Initialize a store and add our schema to it.
|
312
|
+
store = JsonSchema::DocumentStore.new
|
313
|
+
store.add_schema(schema1)
|
314
|
+
store.add_schema(schema2)
|
315
|
+
store.add_schema(schema3)
|
316
|
+
|
317
|
+
expander = JsonSchema::ReferenceExpander.new
|
318
|
+
expander.expand!(schema1, store: store)
|
319
|
+
|
320
|
+
assert_equal 3, schema1.properties["foo"].properties["omg"].max_length
|
321
|
+
end
|
322
|
+
|
323
|
+
it "expands a schema with a reference to an external schema with a nested local property reference" do
|
324
|
+
sample1 = {
|
325
|
+
"$schema" => "http://json-schema.org/draft-04/hyper-schema",
|
326
|
+
"type" => "object",
|
327
|
+
"properties" => {
|
328
|
+
"foo" => {
|
329
|
+
"$ref" => "http://json-schema.org/b.json#/definitions/bar"
|
330
|
+
},
|
331
|
+
"foo2" => {
|
332
|
+
"$ref" => "http://json-schema.org/b.json#/definitions/baz"
|
333
|
+
}
|
334
|
+
}
|
335
|
+
}
|
336
|
+
schema1 = JsonSchema::Parser.new.parse!(sample1)
|
337
|
+
schema1.uri = "http://json-schema.org/a.json"
|
338
|
+
|
339
|
+
sample2 = {
|
340
|
+
"$schema" => "http://json-schema.org/draft-04/hyper-schema",
|
341
|
+
"type" => "object",
|
342
|
+
"definitions" => {
|
343
|
+
"bar" => {
|
344
|
+
"type" => "object",
|
345
|
+
"properties" => {
|
346
|
+
"omg" => {
|
347
|
+
"$ref" => "#/definitions/baz"
|
348
|
+
}
|
349
|
+
}
|
350
|
+
},
|
351
|
+
"baz" => {
|
352
|
+
"type" => "string",
|
353
|
+
"maxLength" => 3
|
354
|
+
}
|
355
|
+
}
|
356
|
+
}
|
357
|
+
schema2 = JsonSchema::Parser.new.parse!(sample2)
|
358
|
+
schema2.uri = "http://json-schema.org/b.json"
|
359
|
+
|
360
|
+
# Initialize a store and add our schema to it.
|
361
|
+
store = JsonSchema::DocumentStore.new
|
362
|
+
store.add_schema(schema1)
|
363
|
+
store.add_schema(schema2)
|
364
|
+
|
365
|
+
expander = JsonSchema::ReferenceExpander.new
|
366
|
+
expander.expand!(schema1, store: store)
|
367
|
+
|
368
|
+
# These both point to the same definition, 'baz', but
|
369
|
+
# 'foo' has a level of indirection.
|
370
|
+
assert_equal 3, schema1.properties["foo2"].max_length
|
371
|
+
assert_equal 3, schema1.properties["foo"].properties["omg"].max_length
|
372
|
+
end
|
373
|
+
|
268
374
|
it "expands a reference to a link" do
|
269
375
|
pointer("#/properties").merge!(
|
270
376
|
"link" => { "$ref" => "#/links/0" }
|
metadata
CHANGED
@@ -1,113 +1,15 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: ecma-re-validator
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.1'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.1'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: minitest
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '5.3'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '5.3'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '10.3'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '10.3'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: byebug
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: pry
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: pry-byebug
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: simplecov
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
11
|
+
date: 2019-02-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
111
13
|
description:
|
112
14
|
email:
|
113
15
|
- brandur@mutelight.org
|