json_schema-faker 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfafb79a64676037970d45ea495b3c5dd601ba44
4
- data.tar.gz: c5e69abcb15a816b5e90ee5cd9c08752082ab8f5
3
+ metadata.gz: 86004c55c41bf6565a1352415755ad096271acc1
4
+ data.tar.gz: 7bd049df4f6b5fcf5d9d6b0eb9ac7e3903420690
5
5
  SHA512:
6
- metadata.gz: 96ef98bb3d841808674fdbe71d4e7781604f3aba3e731696ef7eebb181a0051091fd98bec9dbe9f273229508b3a0b893e90a87d3a0f13d3a673f30a11b8d6c64
7
- data.tar.gz: fa77f0ea527055174ad18b868029f597f07652e41daed123710c25f6c7f8985209f00111abdd85e40f5bde46a8c80e0bb20a0d1f94bd8781b0fac337d12f9564
6
+ metadata.gz: cf5aa0f7718587a6f509bb436b8c7830a9aeb8eab5ec8b7bbee1269ecb39641ea774a2d592fd0ddcaf9085ce1892e0accf7af81afda0a5150d8610e34d0ddc18
7
+ data.tar.gz: e5ebca434d25c2ecae25f77f49a363bbe406bcecee211614674f760a495d22acef38195fc7e1747e1b9111ae23a9e9c0cce6e8651fa90064d48b8287b7ee6a26
@@ -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
- * support for copying pattern in take_logical_and_of_schema
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
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
- # FIXME: circular dependency is not supported
105
- depended_keys.each.with_object(object) do |key, hash|
106
- dependency = schema.dependencies[key]
107
-
108
- if dependency.is_a?(::JsonSchema::Schema)
109
- # too difficult we just merge
110
- hash.update(generate(schema.dependencies[key], hint: nil, position: "#{position}/dependencies/#{key}"))
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
- merged_schema = unless schema.one_of.empty? && schema.any_of.empty?
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
- [ a.items.size, b.items.size ].max.times do |i|
86
- ai, bi = a.items[i], b.items[i]
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
- ( a.properties.keys + b.properties.keys ).uniq.each do |key|
147
- a.properties[key] = take_logical_and_of_schema(a.properties[key], b.properties[key])
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.1
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-15 00:00:00.000000000 Z
11
+ date: 2017-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_schema