json_schema-faker 0.4.0 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fe0bd03f8a005b3e787b728ce7287db41612d36
4
- data.tar.gz: ab3c402bb39c68ee5c3c9102b5dcbc5dccc370d4
3
+ metadata.gz: 9a48c2a0057da8ee6de1652e93757976bda7579f
4
+ data.tar.gz: ce9fba20b0e52dfb882311a2c6959b10f6c7431d
5
5
  SHA512:
6
- metadata.gz: 8cfdfcb77c087e913d4d555a6793a948a847f7dae5b4fe9722cc3f844a10a1f5f1b6b14b54ef20db7909faef0e59263bc71e32f0aba1d95af0f5f23f1c8005c7
7
- data.tar.gz: 25b74a451865ab813ed00c2575fe8b43eab4775a6503dbf984baefbb4a794236c828d5a2e0b620115cc8af055e5c2caa470b3e0f91643e48eadea7d6fe787bed
6
+ metadata.gz: f2aa83f9038c66b9c569b35b1fafac65b08638c99b00635c3daf24119ec26c43094e7e8607c9678de66ead6eefde411eca0ed94dd77b0d7374be9b0f290df82b
7
+ data.tar.gz: '0558dcd25334eda4711868fd89e7d291195ccc32013bb37aabaebdf90cd05d430fd61e6b0f55558d2eab33f4f52f749c1604db8f42b3e54595d163f37bfef7ec'
@@ -0,0 +1,37 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ - image: circleci/ruby:2.4.1
10
+
11
+ working_directory: ~/repo
12
+
13
+ steps:
14
+ - checkout
15
+
16
+ # Download and cache dependencies
17
+ - restore_cache:
18
+ keys:
19
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
20
+ # fallback to using the latest cache if no exact match is found
21
+ - v1-dependencies-
22
+
23
+ - run:
24
+ name: install dependencies
25
+ command: |
26
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
27
+
28
+ - save_cache:
29
+ paths:
30
+ - ./venv
31
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
32
+
33
+ # run tests!
34
+ - run:
35
+ name: run tests
36
+ command: |
37
+ bundle exec danger
@@ -1,6 +1,8 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
+ - ruby-head
5
+ - 2.4.1
4
6
  - 2.3.1
5
7
  - 2.2.5
6
8
  before_install: gem install bundler -v 1.12.3
@@ -1,22 +1,29 @@
1
+ ## 0.5.0
2
+
3
+ * Added
4
+ * ::JsonSchema::Faker::Util. utility for json_schema
5
+ * Removed
6
+ * ::JsonSchema::Faker::Strategy::Simple.merge_schema! is removed. use ::JsonSchema::Faker::Util.take_logical_and_of_schema instead.
7
+
1
8
  ## 0.4.0
2
9
 
3
- * ADDED
4
- * Greedy strategy to use properties as much as possible (suitable to response generation)
10
+ * Added
11
+ * Greedy strategy to use properties as much as possible (suitable to response generation)
5
12
 
6
13
  ## 0.3.0
7
14
 
8
- * ENHANCEMENT
9
- * can add faker to format
15
+ * Added
16
+ * can add faker to format
10
17
 
11
18
  ## 0.2.0
12
19
 
13
- * ENHANCEMENT
14
- * support example as hint
20
+ * Added
21
+ * support example as hint
15
22
 
16
23
  ## 0.1.1
17
24
 
18
- * IMPROVEMENT
19
- * refactor and improve generation
25
+ * Added
26
+ * refactor and improve generation
20
27
 
21
28
  ## 0.1.0
22
29
 
@@ -0,0 +1 @@
1
+ rspec_no_filter.warn_for_rspec_filter
data/README.md CHANGED
@@ -28,7 +28,7 @@ raw_schema = {
28
28
  "required" => [ "a" ],
29
29
  }
30
30
 
31
- schema = JsonSchema::Schema.parse(raw_schema)
31
+ schema = JsonSchema.parse!(raw_schema)
32
32
 
33
33
  JsonSchema::Faker.new(schema).generate #=> { "a" => "e" }
34
34
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -24,6 +24,11 @@ Gem::Specification.new do |spec|
24
24
  # test
25
25
  spec.add_development_dependency "rspec"
26
26
  spec.add_development_dependency "guard-rspec"
27
+ spec.add_development_dependency "activesupport"
28
+
29
+ # check pr
30
+ spec.add_development_dependency "danger"
31
+ spec.add_development_dependency "danger-rspec_no_filter"
27
32
 
28
33
  # debug
29
34
  spec.add_development_dependency "pry"
@@ -21,22 +21,27 @@ module JsonSchema::Faker::Strategy
21
21
  {}
22
22
  end
23
23
 
24
- # http://json-schema.org/latest/json-schema-validation.html#anchor53
25
- required_length = schema.max_properties || [ schema.properties.size, (schema.min_properties || 0) ].max
26
-
27
- keys = ((schema.required || [])+ (schema.properties || {}).keys).uniq - object.keys
28
- keys -= hint[:not_have_keys] if hint && hint[:not_have_keys]
24
+ if hint && hint[:not_have_keys]
25
+ candidates = schema.properties.keys - object.keys - hint[:not_have_keys]
26
+ required_length = schema.max_properties || [ (schema.properties.keys - hint[:not_have_keys]).size, (schema.min_properties || 0) ].max
27
+ else
28
+ candidates = schema.properties.keys - object.keys
29
+ required_length = schema.max_properties || [ schema.properties.keys.size, (schema.min_properties || 0) ].max
30
+ end
29
31
 
30
- keys.first(required_length).each.with_object(object) do |key, hash|
32
+ # http://json-schema.org/latest/json-schema-validation.html#anchor53
33
+ # TODO: candidates.shift(required_length)
34
+ candidates.first(required_length).each.with_object(object) do |key, hash|
31
35
  hash[key] = generate(schema.properties[key], hint: hint, position: "#{position}/#{key}")
32
36
  end
37
+ candidates = candidates - object.keys
33
38
 
34
39
  # if length is not enough
35
40
  if schema.additional_properties === false
36
41
  (required_length - object.keys.length).times.each.with_object(object) do |i, hash|
37
42
  if schema.pattern_properties.empty?
38
- key = (schema.properties.keys - object.keys).first
39
- hash[key] = generate(schema.properties[key], hint: hint, position: "#{position}/#{key}")
43
+ key = candidates.pop
44
+ hash[key] = generate(schema.properties[key], hint: hint, position: "#{position}/#{key}") if key
40
45
  else
41
46
  name = ::Pxeger.new(schema.pattern_properties.keys.first).generate
42
47
  hash[name] = generate(schema.pattern_properties.values.first, hint: hint, position: "#{position}/#{name}")
@@ -51,7 +56,6 @@ module JsonSchema::Faker::Strategy
51
56
 
52
57
  # consider dependency
53
58
  depended_keys = object.keys & schema.dependencies.keys
54
-
55
59
  # FIXME: circular dependency is not supported
56
60
  depended_keys.each.with_object(object) do |key, hash|
57
61
  dependency = schema.dependencies[key]
@@ -61,7 +65,7 @@ module JsonSchema::Faker::Strategy
61
65
  hash.update(generate(schema.dependencies[key], hint: nil, position: "#{position}/dependencies/#{key}"))
62
66
  else
63
67
  dependency.each do |additional_key|
64
- object[additional_key] = generate(schema.properties[additional_key], hint: hint, position: "#{position}/dependencies/#{key}/#{additional_key}") unless object.has_key?(additional_key)
68
+ hash[additional_key] = generate(schema.properties[additional_key], hint: hint, position: "#{position}/dependencies/#{key}/#{additional_key}") unless object.has_key?(additional_key)
65
69
  end
66
70
  end
67
71
  end
@@ -1,5 +1,9 @@
1
+ require "json_schema/faker/util"
2
+
1
3
  module JsonSchema::Faker::Strategy
2
4
  class Simple
5
+ include ::JsonSchema::Faker::Util
6
+
3
7
  class << self
4
8
  def formats
5
9
  @formats ||= {}
@@ -171,7 +175,7 @@ module JsonSchema::Faker::Strategy
171
175
  if schema.items.is_a?(Array)
172
176
  items = schema.items.map.with_index {|e, i| generate(e, hint: hint, position: "#{position}/items[#{i}]") }
173
177
 
174
- items + (length - items.size).map.with_index {|i| schema.additional_items === false ? i : generate(schema.additional_items, hint: hint, position: "#{position}/additional_items[#{i}]") }
178
+ items + (length - items.size).times.map.with_index {|i| schema.additional_items === false ? i : generate(schema.additional_items, hint: hint, position: "#{position}/additional_items[#{i}]") }
175
179
  else
176
180
  length.times.map.with_index {|i| generate(schema.items, hint: hint, position: "#{position}/items[#{i}]") }
177
181
  end
@@ -218,15 +222,7 @@ module JsonSchema::Faker::Strategy
218
222
  end
219
223
  end
220
224
 
221
- def compact_and_merge_schema(a, b, a_position:, b_position:)
222
- merge_schema!(
223
- compact_schema(a, position: a_position),
224
- compact_schema(b, position: b_position),
225
- a_position: a_position,
226
- b_position: b_position
227
- )
228
- end
229
-
225
+ # TODO: compacting all_of and one_of/any_of at once will not work
230
226
  def compact_schema(schema, position:)
231
227
  return schema if schema.one_of.empty? && schema.any_of.empty? && schema.all_of.empty?
232
228
 
@@ -241,108 +237,57 @@ module JsonSchema::Faker::Strategy
241
237
  merged_schema.any_of = []
242
238
  merged_schema.all_of = []
243
239
 
244
- unless schema.one_of.empty?
245
- ::JsonSchema::Faker::Configuration.logger.info "compact one_of" if ::JsonSchema::Faker::Configuration.logger
246
- compact_and_merge_schema(merged_schema, schema.one_of.first, a_position: position, b_position: "#{position}/one_of[0]")
247
- end
248
-
249
- unless schema.any_of.empty?
250
- ::JsonSchema::Faker::Configuration.logger.info "compact any_of" if ::JsonSchema::Faker::Configuration.logger
251
- compact_and_merge_schema(merged_schema, schema.any_of.first, a_position: position, b_position: "#{position}/any_of[0]")
252
- end
253
-
254
240
  unless schema.all_of.empty?
255
241
  ::JsonSchema::Faker::Configuration.logger.info "compact all_of" if ::JsonSchema::Faker::Configuration.logger
256
- all_of = ::JsonSchema::Schema.new
257
- all_of.copy_from(schema.all_of.first)
258
242
 
259
- all_of = schema.all_of[1..-1].each.with_index.inject(all_of) do |(a, _), (b, i)|
260
- compact_and_merge_schema(a, b, a_position: "#{position}/all_of", b_position: "#{position}/all_of[#{i+1}]")
243
+ all_of = schema.all_of.each.with_index.inject(nil) do |(a, _), (b, i)|
244
+ if a
245
+ take_logical_and_of_schema(a, b, a_position: "#{position}/all_of", b_position: "#{position}/all_of[#{i+1}]")
246
+ else
247
+ b
248
+ end
261
249
  end
262
250
 
263
- merge_schema!(merged_schema, all_of, a_position: position, b_position: "#{position}/all_of")
264
- end
265
-
266
- ::JsonSchema::Faker::Configuration.logger.debug "compacted: #{merged_schema.inspect_schema}" if ::JsonSchema::Faker::Configuration.logger
267
-
268
- merged_schema
269
- end
270
-
271
- def merge_schema!(a, b, a_position:, b_position:)
272
- if ::JsonSchema::Faker::Configuration.logger
273
- ::JsonSchema::Faker::Configuration.logger.info "start to merge at #{a_position} with #{b_position}"
274
- ::JsonSchema::Faker::Configuration.logger.debug "a: #{a.inspect_schema}"
275
- ::JsonSchema::Faker::Configuration.logger.debug "b: #{b.inspect_schema}"
276
- end
277
- # attr not supported now
278
- # not: too difficult (if `not` is not wrapped by all_of wrap it?)
279
- # multiple_of TODO: least common multiple
280
- # format TODO: just override
281
-
282
- # array properties
283
- a.any_of = (a.any_of.empty? ? b.any_of : a.any_of) # XXX: actually impossible
284
- a.enum = (a.enum ? (a.enum & b.enum) : b.enum) if b.enum
285
-
286
- %i[ type one_of all_of ].each do |attr|
287
- a.__send__("#{attr}=", a.__send__(attr) + b.__send__(attr))
288
- end
289
- a.required = (a.required ? (a.required + b.required).uniq : b.required) if b.required
290
-
291
- # object properties
292
- # XXX: key conflict
293
- %i[ properties pattern_properties dependencies ].each do |attr|
294
- a.__send__("#{attr}=", a.__send__(attr).merge(b.__send__(attr)))
295
- end
251
+ merged_schema = unless schema.one_of.empty? && schema.any_of.empty?
252
+ ::JsonSchema::Faker::Configuration.logger.info "find from one_of and any_of which satiffy all_of" if ::JsonSchema::Faker::Configuration.logger
253
+ one_of_candidate = schema.one_of.find do |s|
254
+ s2 = take_logical_and_of_schema(s, all_of)
255
+ compare_schema(s, s2) # FIXME: check s2 > s
256
+ end
296
257
 
297
- # array of object
298
- if a.items && b.items
299
- if a.items.is_a?(Array) && b.items.is_a?(Array)
300
- # TODO: zip and merge it
301
- elsif a.items.is_a?(Array) && b.items.is_a?(::JsonSchema::Schema)
302
- a.items = a.items.map.with_index do |e, i|
303
- compact_and_merge_schema(e, b.items, a_position: "#{a_position}/items[#{i}]", b_position: "#{b_position}/items")
258
+ any_of_candidate = schema.any_of.find do |s|
259
+ s2 = take_logical_and_of_schema(s, all_of)
260
+ compare_schema(s, s2) # FIXME: check s2 > s
304
261
  end
305
- elsif a.items.is_a?(::JsonSchema::Schema) && a.items.is_a?(Array)
306
- a.items = b.items.map.with_index do |e, i|
307
- compact_and_merge_schema(a.items, e, a_position: "#{a_position}/items", b_position: "#{b_position}/items[#{i}]")
262
+
263
+ unless one_of_candidate || any_of_candidate
264
+ ::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")
266
+ 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
308
269
  end
309
270
  else
310
- compact_and_merge_schema(a.items, b.items, a_position: "#{a_position}/items", b_position: "#{b_position}/items")
271
+ take_logical_and_of_schema(merged_schema, all_of, a_position: position, b_position: "#{position}/all_of")
311
272
  end
312
273
  else
313
- a.items ||= b.items
314
- end
315
-
316
- # override to stronger validation
317
- %i[ additional_items additional_properties ].each do |attr|
318
- a.__send__("#{attr}=", false) unless a.__send__(attr) && b.__send__(attr)
319
- end
320
- %i[ min_exclusive max_exclusive unique_items ].each do |attr|
321
- a.__send__("#{attr}=", a.__send__(attr) & b.__send__(attr))
322
- end
323
- %i[ min min_length min_properties min_items ].each do |attr|
324
- if b.__send__(attr)
325
- if a.__send__(attr)
326
- a.__send__("#{attr}=", b.__send__(attr)) if b.__send__(attr) < a.__send__(attr)
327
- else
328
- a.__send__("#{attr}=", b.__send__(attr))
329
- end
274
+ unless schema.one_of.empty?
275
+ ::JsonSchema::Faker::Configuration.logger.info "compact one_of" if ::JsonSchema::Faker::Configuration.logger
276
+ merged_schema = take_logical_and_of_schema(merged_schema, schema.one_of.first, a_position: position, b_position: "#{position}/one_of[0]")
330
277
  end
331
- end
332
- %i[ max max_length max_properties max_items ].each do |attr|
333
- if b.__send__(attr)
334
- if a.__send__(attr)
335
- a.__send__("#{attr}=", b.__send__(attr)) if b.__send__(attr) > a.__send__(attr)
336
- else
337
- a.__send__("#{attr}=", b.__send__(attr))
338
- end
278
+
279
+ unless schema.any_of.empty?
280
+ ::JsonSchema::Faker::Configuration.logger.info "compact any_of" if ::JsonSchema::Faker::Configuration.logger
281
+ merged_schema = take_logical_and_of_schema(merged_schema, schema.any_of.first, a_position: position, b_position: "#{position}/any_of[0]")
339
282
  end
340
283
  end
341
- a.pattern = (a.pattern && b.pattern) ? "(?:#{a.pattern})(?=#{b.pattern})" : (a.pattern || b.pattern)
342
284
 
343
- ::JsonSchema::Faker::Configuration.logger.debug "merged: #{a.inspect_schema}" if ::JsonSchema::Faker::Configuration.logger
285
+ # compact recursively
286
+ merged_schema = compact_schema(merged_schema, position: position)
344
287
 
345
- a
288
+ ::JsonSchema::Faker::Configuration.logger.debug "compacted: #{merged_schema.inspect_schema}" if ::JsonSchema::Faker::Configuration.logger
289
+
290
+ merged_schema
346
291
  end
347
292
  end
348
293
  end
@@ -0,0 +1,235 @@
1
+ require "json_schema/faker"
2
+
3
+ class JsonSchema::Faker
4
+ module Util
5
+ # umhhh maybe we don't need this...
6
+ def compare_schema(a, b)
7
+ if a.is_a?(::JsonSchema::Schema) && b.is_a?(::JsonSchema::Schema)
8
+ %i[ multiple_of min max min_exclusive max_exclusive
9
+ max_length min_length pattern
10
+ additional_items items max_items min_items unique_items
11
+ max_properties min_properties required additional_properties properties pattern_properties
12
+ enum type all_of any_of one_of not
13
+ ].all? {|k| compare_schema(a.__send__(k), b.__send__(k)) }
14
+ elsif a.is_a?(::Array) && b.is_a?(::Array)
15
+ return false unless a.size == b.size
16
+ a.zip(b).all? {|ai, bi| compare_schema(ai, bi) }
17
+ elsif a.is_a?(::Hash) && b.is_a?(::Hash)
18
+ return false unless a.keys.sort == b.keys.sort
19
+ a.keys.all? {|key| compare_schema(a[key], b[key]) }
20
+ else
21
+ a == b
22
+ end
23
+ end
24
+
25
+ def take_unique_items(a, b)
26
+ a.select do |ae|
27
+ b.any? {|be| compare_schema(ae, be) }
28
+ end
29
+ end
30
+
31
+ def take_logical_and_of_schema(a, b, a_position: nil, b_position: nil)
32
+ return a || b if a.nil? || b.nil?
33
+
34
+ # deep copy and modify it
35
+ a = ::JsonSchema::Schema.new.tap {|s| s.copy_from(a) }
36
+
37
+ # for numeric
38
+ if a.multiple_of && b.multiple_of
39
+ # TODO: multipleOf it seems easy
40
+ ::JsonSchema::Faker::Configuration.logger.warn "not support merging multipleOf" if ::JsonSchema::Faker::Configuration.logger
41
+ end
42
+
43
+ # maximum minimum exclusiveMinimum exclusiveMinimum
44
+ if b.max
45
+ if !a.max || a.max > b.max
46
+ a.max = b.max
47
+ end
48
+ a.max_exclusive = b.max_exclusive if b.max_exclusive
49
+ end
50
+ if b.min
51
+ if !a.min || a.min < b.min
52
+ a.min = b.min
53
+ end
54
+ a.min_exclusive = b.min_exclusive if b.min_exclusive
55
+ end
56
+
57
+ # for string
58
+ # maxLength minLength
59
+ if b.max_length
60
+ if !a.max_length || a.max_length > b.max_length
61
+ a.max_length = b.max_length
62
+ end
63
+ end
64
+ if b.min_length
65
+ if !a.min_length || a.min_length < b.min_length
66
+ a.min_length = b.min_length
67
+ end
68
+ end
69
+ # pattern
70
+ if a.pattern && b.pattern
71
+ # TODO: pexeger does not support generated one
72
+ ::JsonSchema::Faker::Configuration.logger.warn "not support merging pattern" if ::JsonSchema::Faker::Configuration.logger
73
+ end
74
+ #if b.pattern
75
+ # a.pattern = (a.pattern ? "/^(?=.*#{a.pattern.inspect.gsub("/\\/", "").gsub("\\//", "")})(?=.*#{b.pattern.inspect.gsub("/\\/", "").gsub("\\//", "")})/" : b.pattern)
76
+ #end
77
+
78
+ # for array
79
+ # items and aditionalItems
80
+ if b.items
81
+ if a.items
82
+ if a.items.is_a?(Array) && b.items.is_a?(Array)
83
+ [ a.items.size, b.items.size ].max.times do |i|
84
+ ai, bi = a.items[i], b.items[i]
85
+ if ai && bi
86
+ a.items[i] = take_logical_and_of_schema(ai, bi)
87
+ else
88
+ # XXX: consider aditionalItems
89
+ a.items[i] = ai || bi
90
+ end
91
+ end
92
+ elsif a.items.is_a?(::JsonSchema::Schema) && b.items.is_a?(::JsonSchema::Schema)
93
+ a.items = take_logical_and_of_schema(a.items, b.items)
94
+ end
95
+ else
96
+ a.items = b.items
97
+ end
98
+ end
99
+ if a.additional_items === false || b.additional_items === false
100
+ a.additonal_items = false
101
+ else
102
+ if b.additional_items.is_a?(::JsonSchema::Schema)
103
+ if a.additional_items.is_a?(::JsonSchem::Schema)
104
+ ::JsonSchema::Faker::Configuration.logger.warn "not support merging additionalItems" if ::JsonSchema::Faker::Configuration.logger
105
+ else
106
+ a.additional_items = b.additional_items
107
+ end
108
+ end
109
+ end
110
+ # maxItems, minItems
111
+ if b.max_items
112
+ if !a.max_items || a.max_items > b.max_items
113
+ a.max_items = b.max_items
114
+ end
115
+ end
116
+ if b.min_items
117
+ if !a.min_items || a.min_items < b.min_items
118
+ a.min_items = b.min_items
119
+ end
120
+ end
121
+ # uniqueItems
122
+ if a.unique_items || b.unique_items
123
+ a.unique_items = true
124
+ end
125
+
126
+ # for object
127
+ # maxProperties, minProperties
128
+ if b.max_properties
129
+ if !a.max_properties || a.max_properties > b.max_properties
130
+ a.max_properties = b.max_properties
131
+ end
132
+ end
133
+ if b.min_properties
134
+ if !a.min_properties || a.min_properties < b.min_properties
135
+ a.min_properties = b.min_properties
136
+ end
137
+ end
138
+ # required
139
+ if b.required
140
+ a.required = a.required ? (a.required + b.required).uniq : b.required
141
+ end
142
+ # properties
143
+ if !b.properties.empty?
144
+ ( a.properties.keys + b.properties.keys ).uniq.each do |key|
145
+ a.properties[key] = take_logical_and_of_schema(a.properties[key], b.properties[key])
146
+ end
147
+ end
148
+ # additionalProperties, patternProperties, dependencies
149
+ if a.additional_properties === false || b.additional_properties === false
150
+ a.additional_properties = false
151
+ else
152
+ if b.additional_properties.is_a?(::JsonSchema::Schema)
153
+ if a.additional_properties.is_a?(::JsonSchem::Schema)
154
+ ::JsonSchema::Faker::Configuration.logger.warn "not support merging additionalProperties" if ::JsonSchema::Faker::Configuration.logger
155
+ else
156
+ a.additional_properties = b.additional_properties
157
+ end
158
+ end
159
+ end
160
+ if !b.pattern_properties.empty?
161
+ if !a.pattern_properties.empty?
162
+ ::JsonSchema::Faker::Configuration.logger.warn "not support merging patternProperties" if ::JsonSchema::Faker::Configuration.logger
163
+ else
164
+ a.pattern_properties = b.pattern_properties
165
+ end
166
+ end
167
+ if !b.dependencies.empty?
168
+ if !a.dependencies.empty?
169
+ ::JsonSchema::Faker::Configuration.logger.warn "not support merging dependencies" if ::JsonSchema::Faker::Configuration.logger
170
+ else
171
+ a.dependencies = b.dependencies
172
+ end
173
+ end
174
+ # for any
175
+ # enum
176
+ if b.enum
177
+ if a.enum
178
+ a.enum = a.enum & b.enum
179
+ else
180
+ a.enum = b.enum
181
+ end
182
+ end
183
+ # type
184
+ if !b.type.empty?
185
+ if !a.type.empty?
186
+ a.type = a.type & b.type
187
+ else
188
+ a.type = b.type
189
+ end
190
+ end
191
+ # allOf
192
+ if !b.all_of.empty?
193
+ if !a.all_of.empty?
194
+ a.all_of = [
195
+ [ *a.all_of, *b.all_of ].inject(nil) {|res, c| res ? take_logical_and_of_schema(res, c) : c }
196
+ ]
197
+ else
198
+ a.all_of = b.all_of
199
+ end
200
+ end
201
+ # anyOf
202
+ if !b.any_of.empty?
203
+ if !a.any_of.empty?
204
+ # XXX: it is difficult to find logically and of any_of
205
+ # like "anyOf": { "minimum": 5 }, { "multipleOf": 3 } and { "maximum": 6 }, { "multipleOf": 2 }
206
+ a.any_of = take_unique_items(a.any_of, b.any_of)
207
+ else
208
+ a.any_of = b.any_of
209
+ end
210
+ end
211
+ # oneOf
212
+ if !b.one_of.empty?
213
+ if !a.one_of.empty?
214
+ # XXX: it is difficult to find logically and of one_of
215
+ a.one_of = take_unique_items(a.one_of, b.one_of)
216
+ else
217
+ a.one_of = b.one_of
218
+ end
219
+ end
220
+ # not
221
+ if b.not
222
+ if a.not
223
+ ::JsonSchema::Faker::Configuration.logger.warn "not support merging not" if ::JsonSchema::Faker::Configuration.logger
224
+ else
225
+ a.not = b.not
226
+ end
227
+ end
228
+
229
+ a
230
+ end
231
+
232
+
233
+ module_function *instance_methods
234
+ end
235
+ end
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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - okitan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-11 00:00:00.000000000 Z
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_schema
@@ -94,6 +94,48 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
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'
111
+ - !ruby/object:Gem::Dependency
112
+ name: danger
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: danger-rspec_no_filter
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
97
139
  - !ruby/object:Gem::Dependency
98
140
  name: pry
99
141
  requirement: !ruby/object:Gem::Requirement
@@ -115,12 +157,14 @@ executables: []
115
157
  extensions: []
116
158
  extra_rdoc_files: []
117
159
  files:
160
+ - ".circleci/config.yml"
118
161
  - ".gitignore"
119
162
  - ".gitmodules"
120
163
  - ".rspec"
121
164
  - ".travis.yml"
122
165
  - CHANGELOG.md
123
166
  - CODE_OF_CONDUCT.md
167
+ - Dangerfile
124
168
  - Gemfile
125
169
  - Guardfile
126
170
  - LICENSE.txt
@@ -133,6 +177,7 @@ files:
133
177
  - lib/json_schema/faker.rb
134
178
  - lib/json_schema/faker/strategy/greedy.rb
135
179
  - lib/json_schema/faker/strategy/simple.rb
180
+ - lib/json_schema/faker/util.rb
136
181
  homepage: https://github.com/okitan/json_schema-faker
137
182
  licenses:
138
183
  - MIT
@@ -153,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
198
  version: '0'
154
199
  requirements: []
155
200
  rubyforge_project:
156
- rubygems_version: 2.5.1
201
+ rubygems_version: 2.6.12
157
202
  signing_key:
158
203
  specification_version: 4
159
204
  summary: generate fake data from json schema