json_schema-faker 0.5.1 → 0.5.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/CHANGELOG.md +10 -1
- data/VERSION +1 -1
- data/lib/json_schema/faker/strategy/simple.rb +24 -16
- data/lib/json_schema/faker/util.rb +9 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86004c55c41bf6565a1352415755ad096271acc1
|
4
|
+
data.tar.gz: 7bd049df4f6b5fcf5d9d6b0eb9ac7e3903420690
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf5aa0f7718587a6f509bb436b8c7830a9aeb8eab5ec8b7bbee1269ecb39641ea774a2d592fd0ddcaf9085ce1892e0accf7af81afda0a5150d8610e34d0ddc18
|
7
|
+
data.tar.gz: e5ebca434d25c2ecae25f77f49a363bbe406bcecee211614674f760a495d22acef38195fc7e1747e1b9111ae23a9e9c0cce6e8651fa90064d48b8287b7ee6a26
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
+
## 0.5.2
|
2
|
+
|
3
|
+
* Added
|
4
|
+
* support of schema dependency for JsonSchema::Faker::Strategy::Simple
|
5
|
+
* validate default and return only if valid
|
6
|
+
* Fixed
|
7
|
+
* fixes bug of disruption in JsonSchema::Faker::Util.take_logical_and_of_schema
|
8
|
+
* fixes bug of not merged in JsonSchema::Faker::Strategy::Simple#compact_schema
|
9
|
+
|
1
10
|
## 0.5.1
|
2
11
|
|
3
12
|
* Added
|
4
|
-
|
13
|
+
* support for copying pattern in take_logical_and_of_schema
|
5
14
|
|
6
15
|
## 0.5.0
|
7
16
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.2
|
@@ -22,7 +22,7 @@ module JsonSchema::Faker::Strategy
|
|
22
22
|
::JsonSchema::Faker::Configuration.logger.debug schema.inspect_schema if ::JsonSchema::Faker::Configuration.logger
|
23
23
|
schema = compact_schema(schema, position: position)
|
24
24
|
|
25
|
-
return schema.default if schema.default
|
25
|
+
return schema.default if schema.default && schema.validate(schema.default).first
|
26
26
|
return self.class.formats[schema.format].call(schema, hint: hint, position: position) if self.class.formats.has_key?(schema.format)
|
27
27
|
|
28
28
|
if schema.not
|
@@ -100,19 +100,27 @@ module JsonSchema::Faker::Strategy
|
|
100
100
|
|
101
101
|
# consider dependency
|
102
102
|
depended_keys = object.keys & schema.dependencies.keys
|
103
|
+
if depended_keys.all? {|key| schema.dependencies[key].is_a?(Array) }
|
104
|
+
# FIXME: circular dependency is not supported
|
105
|
+
depended_keys.each.with_object(object) do |key, hash|
|
106
|
+
schema.dependencies[key].each do |additional_key|
|
107
|
+
hash[additional_key] = generate(schema.properties[additional_key], hint: hint, position: "#{position}/dependencies/#{key}/#{additional_key}") unless object.has_key?(additional_key)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
else
|
111
|
+
::JsonSchema::Faker::Configuration.logger.info "generate again because of dependended keys exists: #{depended_keys}" if ::JsonSchema::Faker::Configuration.logger
|
103
112
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
else
|
112
|
-
dependency.each do |additional_key|
|
113
|
-
object[additional_key] = generate(schema.properties[additional_key], hint: hint, position: "#{position}/dependencies/#{key}/#{additional_key}") unless object.has_key?(additional_key)
|
113
|
+
merged_schema = ::JsonSchema::Schema.new.tap {|s| s.copy_from(schema) }
|
114
|
+
depended_keys.each do |key|
|
115
|
+
dependency = schema.dependencies[key]
|
116
|
+
if dependency.is_a?(::JsonSchema::Schema)
|
117
|
+
merged_schema = compact_schema(take_logical_and_of_schema(merged_schema, dependency), position: position)
|
118
|
+
else
|
119
|
+
merged_schema.required = (merged_schema.required + dependency).uniq
|
114
120
|
end
|
115
121
|
end
|
122
|
+
merged_schema.dependencies = nil # XXX: recursive dependency will fail
|
123
|
+
generate_for_object(merged_schema, hint: hint, position: position)
|
116
124
|
end
|
117
125
|
end
|
118
126
|
|
@@ -248,7 +256,7 @@ module JsonSchema::Faker::Strategy
|
|
248
256
|
end
|
249
257
|
end
|
250
258
|
|
251
|
-
|
259
|
+
unless schema.one_of.empty? && schema.any_of.empty?
|
252
260
|
::JsonSchema::Faker::Configuration.logger.info "find from one_of and any_of which satiffy all_of" if ::JsonSchema::Faker::Configuration.logger
|
253
261
|
one_of_candidate = schema.one_of.find do |s|
|
254
262
|
s2 = take_logical_and_of_schema(s, all_of)
|
@@ -262,13 +270,13 @@ module JsonSchema::Faker::Strategy
|
|
262
270
|
|
263
271
|
unless one_of_candidate || any_of_candidate
|
264
272
|
::JsonSchema::Faker::Configuration.logger.error "failed to find condition which satfisfy all_of in one_of and any_of" if ::JsonSchema::Faker::Configuration.logger
|
265
|
-
take_logical_and_of_schema(merged_schema, all_of, a_position: position, b_position: "#{position}/all_of")
|
273
|
+
merged_schema = take_logical_and_of_schema(merged_schema, all_of, a_position: position, b_position: "#{position}/all_of")
|
266
274
|
else
|
267
|
-
take_logical_and_of_schema(merged_schema, one_of_candidate, a_position: position, b_position: "#{position}/one_of") if one_of_candidate
|
268
|
-
take_logical_and_of_schema(merged_schema, any_of_candidate, a_position: position, b_position: "#{position}/any_of") if any_of_candidate
|
275
|
+
merged_schema = take_logical_and_of_schema(merged_schema, one_of_candidate, a_position: position, b_position: "#{position}/one_of") if one_of_candidate
|
276
|
+
merged_schema = take_logical_and_of_schema(merged_schema, any_of_candidate, a_position: position, b_position: "#{position}/any_of") if any_of_candidate
|
269
277
|
end
|
270
278
|
else
|
271
|
-
take_logical_and_of_schema(merged_schema, all_of, a_position: position, b_position: "#{position}/all_of")
|
279
|
+
merged_schema = take_logical_and_of_schema(merged_schema, all_of, a_position: position, b_position: "#{position}/all_of")
|
272
280
|
end
|
273
281
|
else
|
274
282
|
unless schema.one_of.empty?
|
@@ -82,8 +82,11 @@ class JsonSchema::Faker
|
|
82
82
|
if b.items
|
83
83
|
if a.items
|
84
84
|
if a.items.is_a?(Array) && b.items.is_a?(Array)
|
85
|
-
|
86
|
-
|
85
|
+
original_a_items = a.items
|
86
|
+
a.items = [] # avoid disruptive
|
87
|
+
[ original_a_items.size, b.items.size ].max.times do |i|
|
88
|
+
# XXX:
|
89
|
+
ai, bi = original_a_items[i], b.items[i]
|
87
90
|
if ai && bi
|
88
91
|
a.items[i] = take_logical_and_of_schema(ai, bi)
|
89
92
|
else
|
@@ -143,8 +146,10 @@ class JsonSchema::Faker
|
|
143
146
|
end
|
144
147
|
# properties
|
145
148
|
if !b.properties.empty?
|
146
|
-
|
147
|
-
|
149
|
+
original_a_properties = a.properties
|
150
|
+
a.properties = {} # avoid disruptive
|
151
|
+
( original_a_properties.keys + b.properties.keys ).uniq.each do |key|
|
152
|
+
a.properties[key] = take_logical_and_of_schema(original_a_properties[key], b.properties[key])
|
148
153
|
end
|
149
154
|
end
|
150
155
|
# additionalProperties, patternProperties, dependencies
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_schema-faker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okitan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_schema
|