json_schema 0.19.1 → 0.20.1
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 +5 -5
- data/lib/json_schema/attributes.rb +5 -2
- data/lib/json_schema/reference_expander.rb +39 -40
- data/lib/json_schema/schema.rb +1 -1
- data/test/json_schema/attribute_test.rb +9 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e102114f71484ad7ec4468d6433422c08d7e9a02e20bf635fe7c9a891fce1f99
|
4
|
+
data.tar.gz: 63012a87275d8ee64e9465a5b7998d7db859990d9da99ee197153061e1a00c91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e7481a34dd6f9c56684b387c200afed357dd30fca5d443a1a55ce3eb2b9b75535feb05c4682763b464b882cc1c0cf1a80255bf344e897b8b1f7892a0019225f
|
7
|
+
data.tar.gz: 1175aed4f46aeea66c9d8d65288f6e7a2c9f232bd1f47fdfed342b79259e08975e8b2c795d1fe75e7da563d9d5c171a3ac4b88b6e0045b6c5e965d060bcc28c0
|
@@ -33,13 +33,16 @@ module JsonSchema
|
|
33
33
|
# remove the reader already created by attr_accessor
|
34
34
|
remove_method(attr)
|
35
35
|
|
36
|
-
|
36
|
+
if [Array, Hash, Set].include?(default.class)
|
37
|
+
default = default.freeze
|
38
|
+
end
|
39
|
+
|
37
40
|
define_method(attr) do
|
38
41
|
val = instance_variable_get(ref)
|
39
42
|
if !val.nil?
|
40
43
|
val
|
41
44
|
else
|
42
|
-
|
45
|
+
default
|
43
46
|
end
|
44
47
|
end
|
45
48
|
end
|
@@ -71,7 +71,7 @@ module JsonSchema
|
|
71
71
|
paths = @schema_paths[uri] ||= {}
|
72
72
|
paths[schema.pointer] = schema
|
73
73
|
|
74
|
-
schema_children(schema)
|
74
|
+
schema_children(schema) do |subschema|
|
75
75
|
build_schema_paths(uri, subschema)
|
76
76
|
end
|
77
77
|
|
@@ -114,7 +114,7 @@ module JsonSchema
|
|
114
114
|
# correct all parent references to point back to ref_schema instead of
|
115
115
|
# new_schema
|
116
116
|
if ref_schema.original?
|
117
|
-
schema_children(ref_schema)
|
117
|
+
schema_children(ref_schema) do |schema|
|
118
118
|
schema.parent = ref_schema
|
119
119
|
end
|
120
120
|
end
|
@@ -219,47 +219,44 @@ module JsonSchema
|
|
219
219
|
end
|
220
220
|
|
221
221
|
def schema_children(schema)
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
if additional
|
231
|
-
|
232
|
-
yielder << additional
|
233
|
-
end
|
222
|
+
schema.all_of.each { |s| yield s }
|
223
|
+
schema.any_of.each { |s| yield s }
|
224
|
+
schema.one_of.each { |s| yield s }
|
225
|
+
schema.definitions.each { |_, s| yield s }
|
226
|
+
schema.pattern_properties.each { |_, s| yield s }
|
227
|
+
schema.properties.each { |_, s| yield s }
|
228
|
+
|
229
|
+
if additional = schema.additional_properties
|
230
|
+
if additional.is_a?(Schema)
|
231
|
+
yield additional
|
234
232
|
end
|
233
|
+
end
|
235
234
|
|
236
|
-
|
237
|
-
|
238
|
-
|
235
|
+
if schema.not
|
236
|
+
yield schema.not
|
237
|
+
end
|
239
238
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
end
|
239
|
+
# can either be a single schema (list validation) or multiple (tuple
|
240
|
+
# validation)
|
241
|
+
if items = schema.items
|
242
|
+
if items.is_a?(Array)
|
243
|
+
items.each { |s| yield s }
|
244
|
+
else
|
245
|
+
yield items
|
248
246
|
end
|
247
|
+
end
|
249
248
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
each { |s| yielder << s }
|
262
|
-
end
|
249
|
+
# dependencies can either be simple or "schema"; only replace the
|
250
|
+
# latter
|
251
|
+
schema.dependencies.
|
252
|
+
each_value { |s| yield s if s.is_a?(Schema) }
|
253
|
+
|
254
|
+
# schemas contained inside hyper-schema links objects
|
255
|
+
if schema.links
|
256
|
+
schema.links.each { |l|
|
257
|
+
yield l.schema if l.schema
|
258
|
+
yield l.target_schema if l.target_schema
|
259
|
+
}
|
263
260
|
end
|
264
261
|
end
|
265
262
|
|
@@ -267,19 +264,21 @@ module JsonSchema
|
|
267
264
|
# prevent endless recursion
|
268
265
|
return [] unless schema.original?
|
269
266
|
|
270
|
-
|
267
|
+
arr = []
|
268
|
+
schema_children(schema) do |subschema|
|
271
269
|
if !subschema.expanded?
|
272
270
|
arr += [subschema.reference]
|
273
271
|
else
|
274
272
|
arr += unresolved_refs(subschema)
|
275
273
|
end
|
276
274
|
end
|
275
|
+
arr
|
277
276
|
end
|
278
277
|
|
279
278
|
def traverse_schema(schema)
|
280
279
|
add_reference(schema)
|
281
280
|
|
282
|
-
schema_children(schema)
|
281
|
+
schema_children(schema) do |subschema|
|
283
282
|
if subschema.reference && !subschema.expanded?
|
284
283
|
dereference(subschema, [])
|
285
284
|
end
|
data/lib/json_schema/schema.rb
CHANGED
@@ -26,7 +26,15 @@ describe JsonSchema::Attributes do
|
|
26
26
|
|
27
27
|
hash = obj.copyable_default_with_object
|
28
28
|
assert_equal({}, hash)
|
29
|
-
|
29
|
+
ex = if defined?(FrozenError)
|
30
|
+
FrozenError
|
31
|
+
else
|
32
|
+
RuntimeError
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_raises(ex) do
|
36
|
+
hash[:x] = 123
|
37
|
+
end
|
30
38
|
|
31
39
|
# This is a check to make sure that the new object is not the same object
|
32
40
|
# as the one that we just mutated above. When assigning defaults the module
|
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.
|
4
|
+
version: 0.20.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ecma-re-validator
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.7.7
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: A JSON Schema V4 and Hyperschema V4 parser and validator.
|