json_schema 0.20.5 → 0.20.6
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/parser.rb +20 -16
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03e0e0136ad95f554577990c183117cf37641279202ee77cb9591abf23dbdc90
|
4
|
+
data.tar.gz: 6ee750e3752bbe753d790f423b5bb2fdadd75c6878b0c6e3f06bac2e70320997
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76aa10dbefa5e67da46de6203858b4dda181761f7c896f55a77a6efb49f07b914ffbf3c92ddb11b49602f82b2091d4d78335a7f1ada8c9df7e8dfae806c7909e
|
7
|
+
data.tar.gz: f874b4c7c2ddf0a8c1859388f6ac167f0150d69399c585402906af671f252e35185c43e9f2cfa67d298b42ee799359742a44e0f26f090c1b85053cd4a89884c9
|
data/lib/json_schema/parser.rb
CHANGED
@@ -17,6 +17,10 @@ module JsonSchema
|
|
17
17
|
TrueClass => "boolean",
|
18
18
|
}
|
19
19
|
|
20
|
+
# Reuse these frozen objects to avoid allocations
|
21
|
+
EMPTY_ARRAY = [].freeze
|
22
|
+
EMPTY_HASH = {}.freeze
|
23
|
+
|
20
24
|
attr_accessor :errors
|
21
25
|
|
22
26
|
# Basic parsing of a schema. May return a malformed schema! (Use `#parse!`
|
@@ -101,21 +105,21 @@ module JsonSchema
|
|
101
105
|
end
|
102
106
|
|
103
107
|
def parse_all_of(schema)
|
104
|
-
if schema.all_of
|
108
|
+
if schema.all_of && !schema.all_of.empty?
|
105
109
|
schema.all_of = schema.all_of.each_with_index.
|
106
110
|
map { |s, i| parse_data(s, schema, "allOf/#{i}") }
|
107
111
|
end
|
108
112
|
end
|
109
113
|
|
110
114
|
def parse_any_of(schema)
|
111
|
-
if schema.any_of
|
115
|
+
if schema.any_of && !schema.any_of.empty?
|
112
116
|
schema.any_of = schema.any_of.each_with_index.
|
113
117
|
map { |s, i| parse_data(s, schema, "anyOf/#{i}") }
|
114
118
|
end
|
115
119
|
end
|
116
120
|
|
117
121
|
def parse_one_of(schema)
|
118
|
-
if schema.one_of
|
122
|
+
if schema.one_of && !schema.one_of.empty?
|
119
123
|
schema.one_of = schema.one_of.each_with_index.
|
120
124
|
map { |s, i| parse_data(s, schema, "oneOf/#{i}") }
|
121
125
|
end
|
@@ -140,7 +144,7 @@ module JsonSchema
|
|
140
144
|
end
|
141
145
|
|
142
146
|
def parse_definitions(schema)
|
143
|
-
if schema.definitions
|
147
|
+
if schema.definitions && !schema.definitions.empty?
|
144
148
|
# leave the original data reference intact
|
145
149
|
schema.definitions = schema.definitions.dup
|
146
150
|
schema.definitions.each do |key, definition|
|
@@ -151,7 +155,7 @@ module JsonSchema
|
|
151
155
|
end
|
152
156
|
|
153
157
|
def parse_dependencies(schema)
|
154
|
-
if schema.dependencies
|
158
|
+
if schema.dependencies && !schema.dependencies.empty?
|
155
159
|
# leave the original data reference intact
|
156
160
|
schema.dependencies = schema.dependencies.dup
|
157
161
|
schema.dependencies.each do |k, s|
|
@@ -181,7 +185,7 @@ module JsonSchema
|
|
181
185
|
end
|
182
186
|
|
183
187
|
def parse_links(schema)
|
184
|
-
if schema.links
|
188
|
+
if schema.links && !schema.links.empty?
|
185
189
|
schema.links = schema.links.each_with_index.map { |l, i|
|
186
190
|
link = Schema::Link.new
|
187
191
|
link.parent = schema
|
@@ -231,7 +235,7 @@ module JsonSchema
|
|
231
235
|
end
|
232
236
|
|
233
237
|
def parse_pattern_properties(schema)
|
234
|
-
if schema.pattern_properties
|
238
|
+
if schema.pattern_properties && !schema.pattern_properties.empty?
|
235
239
|
# leave the original data reference intact
|
236
240
|
properties = schema.pattern_properties.dup
|
237
241
|
properties = properties.map do |k, s|
|
@@ -254,8 +258,8 @@ module JsonSchema
|
|
254
258
|
|
255
259
|
def parse_properties(schema)
|
256
260
|
# leave the original data reference intact
|
257
|
-
schema.properties
|
258
|
-
|
261
|
+
if schema.properties && schema.properties.is_a?(Hash) && !schema.properties.empty?
|
262
|
+
schema.properties = schema.properties.dup
|
259
263
|
schema.properties.each do |key, definition|
|
260
264
|
subschema = parse_data(definition, schema, "properties/#{key}")
|
261
265
|
schema.properties[key] = subschema
|
@@ -282,11 +286,11 @@ module JsonSchema
|
|
282
286
|
schema.default = schema.data["default"]
|
283
287
|
|
284
288
|
# validation: any
|
285
|
-
schema.all_of = validate_type(schema, [Array], "allOf") ||
|
286
|
-
schema.any_of = validate_type(schema, [Array], "anyOf") ||
|
287
|
-
schema.definitions = validate_type(schema, [Hash], "definitions") ||
|
289
|
+
schema.all_of = validate_type(schema, [Array], "allOf") || EMPTY_ARRAY
|
290
|
+
schema.any_of = validate_type(schema, [Array], "anyOf") || EMPTY_ARRAY
|
291
|
+
schema.definitions = validate_type(schema, [Hash], "definitions") || EMPTY_HASH
|
288
292
|
schema.enum = validate_type(schema, [Array], "enum")
|
289
|
-
schema.one_of = validate_type(schema, [Array], "oneOf") ||
|
293
|
+
schema.one_of = validate_type(schema, [Array], "oneOf") || EMPTY_ARRAY
|
290
294
|
schema.not = validate_type(schema, [Hash], "not")
|
291
295
|
schema.type = validate_type(schema, [Array, String], "type")
|
292
296
|
schema.type = [schema.type] if schema.type.is_a?(String)
|
@@ -309,11 +313,11 @@ module JsonSchema
|
|
309
313
|
# validation: object
|
310
314
|
schema.additional_properties =
|
311
315
|
validate_type(schema, BOOLEAN + [Hash], "additionalProperties")
|
312
|
-
schema.dependencies = validate_type(schema, [Hash], "dependencies") ||
|
316
|
+
schema.dependencies = validate_type(schema, [Hash], "dependencies") || EMPTY_HASH
|
313
317
|
schema.max_properties = validate_type(schema, [Integer], "maxProperties")
|
314
318
|
schema.min_properties = validate_type(schema, [Integer], "minProperties")
|
315
|
-
schema.pattern_properties = validate_type(schema, [Hash], "patternProperties") ||
|
316
|
-
schema.properties = validate_type(schema, [Hash], "properties") ||
|
319
|
+
schema.pattern_properties = validate_type(schema, [Hash], "patternProperties") || EMPTY_HASH
|
320
|
+
schema.properties = validate_type(schema, [Hash], "properties") || EMPTY_HASH
|
317
321
|
schema.required = validate_type(schema, [Array], "required")
|
318
322
|
schema.strict_properties = validate_type(schema, BOOLEAN, "strictProperties")
|
319
323
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -69,8 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
|
-
|
73
|
-
rubygems_version: 2.7.7
|
72
|
+
rubygems_version: 3.0.3
|
74
73
|
signing_key:
|
75
74
|
specification_version: 4
|
76
75
|
summary: A JSON Schema V4 and Hyperschema V4 parser and validator.
|