json_schema-faker 0.6.0 → 0.6.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
- SHA1:
3
- metadata.gz: 7ebcb70af9b5de9a47ba9a6a8d539add9631e80e
4
- data.tar.gz: 8c7d300c7562ef22fa6d29788f53dd464f742cde
2
+ SHA256:
3
+ metadata.gz: a4f6fbdc7ca4c32a0a702ccfb5736acbcdefc121f6498deebd896ab80e1d723e
4
+ data.tar.gz: 7891a2f2e045b2e12bbb2d0766bd5fb0ee852665d814d2b72da16990b25596bb
5
5
  SHA512:
6
- metadata.gz: afea57d43a6f1862473597c5f4ec93ce9ae5a88f8abee2107b77b9d7c8c872544f098f0e4c2a62131e13ddcf8ebbd6de4a87c4657dcc3662e2ef83ad4f6228db
7
- data.tar.gz: '09ee363bb4a24a32f8cd26f690335a0f25fe019b4e63ec6db4e311da07fe8e32a8370d6a13bc8e12c844c9d6e69d98b02fb2042e2873f874e4b40d2f071f6dec'
6
+ metadata.gz: 53041ee71b24a655fb688813223f21ebb441cb829610421f322fd5a3470ed4ccc53b208ee48b798033f03812f04012569d826f1011fcc9cb9f80f9d723aa691f
7
+ data.tar.gz: 14b6f30ccb927e521aaf129c856ba1e2396a289a250dd9c2a63c876e154772343a7dab4a9ec4062f00f211752773c043874377364018f53a7e620668a27f7e11
data/CHANGELOG.md CHANGED
@@ -1,50 +1,60 @@
1
+ ## 0.6.2
2
+
3
+ - Fixed
4
+ - #16
5
+
6
+ ## 0.6.1
7
+
8
+ - Fixed
9
+ - hint-example descending
10
+
1
11
  ## 0.6.0
2
12
 
3
- * Added
4
- * support of default faker against format
5
- * support for copying format in take_logical_and_of_schema
13
+ - Added
14
+ - support of default faker against format
15
+ - support for copying format in take_logical_and_of_schema
6
16
 
7
17
  ## 0.5.2
8
18
 
9
- * Added
10
- * support of schema dependency for JsonSchema::Faker::Strategy::Simple
11
- * validate default and return only if valid
12
- * Fixed
13
- * fixes bug of disruption in JsonSchema::Faker::Util.take_logical_and_of_schema
14
- * fixes bug of not merged in JsonSchema::Faker::Strategy::Simple#compact_schema
19
+ - Added
20
+ - support of schema dependency for JsonSchema::Faker::Strategy::Simple
21
+ - validate default and return only if valid
22
+ - Fixed
23
+ - fixes bug of disruption in JsonSchema::Faker::Util.take_logical_and_of_schema
24
+ - fixes bug of not merged in JsonSchema::Faker::Strategy::Simple#compact_schema
15
25
 
16
26
  ## 0.5.1
17
27
 
18
- * Added
19
- * support for copying pattern in take_logical_and_of_schema
28
+ - Added
29
+ - support for copying pattern in take_logical_and_of_schema
20
30
 
21
31
  ## 0.5.0
22
32
 
23
- * Added
24
- * ::JsonSchema::Faker::Util. utility for json_schema
25
- * Removed
26
- * ::JsonSchema::Faker::Strategy::Simple.merge_schema! is removed. use ::JsonSchema::Faker::Util.take_logical_and_of_schema instead.
33
+ - Added
34
+ - ::JsonSchema::Faker::Util. utility for json_schema
35
+ - Removed
36
+ - ::JsonSchema::Faker::Strategy::Simple.merge_schema! is removed. use ::JsonSchema::Faker::Util.take_logical_and_of_schema instead.
27
37
 
28
38
  ## 0.4.0
29
39
 
30
- * Added
31
- * Greedy strategy to use properties as much as possible (suitable to response generation)
40
+ - Added
41
+ - Greedy strategy to use properties as much as possible (suitable to response generation)
32
42
 
33
43
  ## 0.3.0
34
44
 
35
- * Added
36
- * can add faker to format
45
+ - Added
46
+ - can add faker to format
37
47
 
38
48
  ## 0.2.0
39
49
 
40
- * Added
41
- * support example as hint
50
+ - Added
51
+ - support example as hint
42
52
 
43
53
  ## 0.1.1
44
54
 
45
- * Added
46
- * refactor and improve generation
55
+ - Added
56
+ - refactor and improve generation
47
57
 
48
58
  ## 0.1.0
49
59
 
50
- * initial release
60
+ - initial release
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.2
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.add_dependency "pxeger"
20
20
  spec.add_dependency "faker"
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "bundler"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
 
25
25
  # test
@@ -8,7 +8,7 @@ module JsonSchema::Faker::Strategy
8
8
  hint[:example].each.with_object({}) do |(key, value), hash|
9
9
  if value.is_a?(Hash)
10
10
  if schema.properties.has_key?(key)
11
- hash[key] = generate(schema.properties[key], hint: { example: hint[:example][key] }, position: "#{position}/#{key}")
11
+ hash[key] = generate(schema.properties[key], hint: { example: hint[:example][key] }, position: "#{position}/#{key}")
12
12
  else
13
13
  # TODO: support pattern properties
14
14
  hash[key] = value
@@ -18,6 +18,19 @@ module JsonSchema::Faker::Strategy
18
18
  end
19
19
  end
20
20
 
21
+ def hint_descend(hint, key)
22
+ if hint && hint[:example]
23
+ hint_without_example = hint.reject{|k,v|k == :example}
24
+ if hint[:example][key]
25
+ hint_without_example.merge(example: hint[:example][key])
26
+ else
27
+ hint_without_example
28
+ end
29
+ else
30
+ hint
31
+ end
32
+ end
33
+
21
34
  def call(schema, hint: nil, position:)
22
35
  if ::JsonSchema::Faker::Configuration.logger
23
36
  ::JsonSchema::Faker::Configuration.logger.debug "current position: #{position}"
@@ -56,7 +69,7 @@ module JsonSchema::Faker::Strategy
56
69
  hint[:example].each.with_object({}) do |(key, value), hash|
57
70
  if value.is_a?(Hash)
58
71
  if schema.properties.has_key?(key)
59
- hash[key] = generate(schema.properties[key], hint: { example: hint[:example][key] }, position: "#{position}/#{key}")
72
+ hash[key] = generate(schema.properties[key], hint: { example: hint[:example][key] }, position: "#{position}/#{key}")
60
73
  else
61
74
  # TODO: support pattern properties
62
75
  hash[key] = value
@@ -75,7 +88,7 @@ module JsonSchema::Faker::Strategy
75
88
  required_length = schema.min_properties || keys.length
76
89
 
77
90
  (keys - object.keys).each.with_object(object) do |key, hash|
78
- hash[key] = generate(schema.properties[key], hint: hint, position: "#{position}/#{key}")
91
+ hash[key] = generate(schema.properties[key], hint: hint_descend(hint, key), position: "#{position}/#{key}")
79
92
  end
80
93
  else
81
94
  required_length = schema.min_properties || schema.max_properties || 0
@@ -84,7 +97,7 @@ module JsonSchema::Faker::Strategy
84
97
  keys -= hint[:not_have_keys] if hint && hint[:not_have_keys]
85
98
 
86
99
  keys.first(required_length).each.with_object(object) do |key, hash|
87
- hash[key] = generate(schema.properties[key], hint: hint, position: "#{position}/#{key}")
100
+ hash[key] = generate(schema.properties[key], hint: hint_descend(hint, key), position: "#{position}/#{key}")
88
101
  end
89
102
  end
90
103
 
@@ -93,10 +106,10 @@ module JsonSchema::Faker::Strategy
93
106
  (required_length - object.keys.length).times.each.with_object(object) do |i, hash|
94
107
  if schema.pattern_properties.empty?
95
108
  key = (schema.properties.keys - object.keys).first
96
- hash[key] = generate(schema.properties[key], hint: hint, position: "#{position}/#{key}")
109
+ hash[key] = generate(schema.properties[key], hint: hint_descend(hint, key), position: "#{position}/#{key}")
97
110
  else
98
111
  name = ::Pxeger.new(schema.pattern_properties.keys.first).generate
99
- hash[name] = generate(schema.pattern_properties.values.first, hint: hint, position: "#{position}/#{name}")
112
+ hash[name] = generate(schema.pattern_properties.values.first, hint: hint_descend(hint, name), position: "#{position}/#{name}")
100
113
  end
101
114
  end
102
115
  else
@@ -112,7 +125,7 @@ module JsonSchema::Faker::Strategy
112
125
  # FIXME: circular dependency is not supported
113
126
  depended_keys.each.with_object(object) do |key, hash|
114
127
  schema.dependencies[key].each do |additional_key|
115
- hash[additional_key] = generate(schema.properties[additional_key], hint: hint, position: "#{position}/dependencies/#{key}/#{additional_key}") unless object.has_key?(additional_key)
128
+ hash[additional_key] = generate(schema.properties[additional_key], hint: hint_descend(hint, additional_key), position: "#{position}/dependencies/#{key}/#{additional_key}") unless object.has_key?(additional_key)
116
129
  end
117
130
  end
118
131
  else
@@ -105,7 +105,7 @@ class JsonSchema::Faker
105
105
  a.additonal_items = false
106
106
  else
107
107
  if b.additional_items.is_a?(::JsonSchema::Schema)
108
- if a.additional_items.is_a?(::JsonSchem::Schema)
108
+ if a.additional_items.is_a?(::JsonSchema::Schema)
109
109
  ::JsonSchema::Faker::Configuration.logger.warn "not support merging additionalItems" if ::JsonSchema::Faker::Configuration.logger
110
110
  else
111
111
  a.additional_items = b.additional_items
@@ -157,7 +157,7 @@ class JsonSchema::Faker
157
157
  a.additional_properties = false
158
158
  else
159
159
  if b.additional_properties.is_a?(::JsonSchema::Schema)
160
- if a.additional_properties.is_a?(::JsonSchem::Schema)
160
+ if a.additional_properties.is_a?(::JsonSchema::Schema)
161
161
  ::JsonSchema::Faker::Configuration.logger.warn "not support merging additionalProperties" if ::JsonSchema::Faker::Configuration.logger
162
162
  else
163
163
  a.additional_properties = b.additional_properties
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.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - okitan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-17 00:00:00.000000000 Z
11
+ date: 2023-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_schema
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1.12'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '1.12'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -197,7 +197,7 @@ homepage: https://github.com/okitan/json_schema-faker
197
197
  licenses:
198
198
  - MIT
199
199
  metadata: {}
200
- post_install_message:
200
+ post_install_message:
201
201
  rdoc_options: []
202
202
  require_paths:
203
203
  - lib
@@ -212,9 +212,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
212
  - !ruby/object:Gem::Version
213
213
  version: '0'
214
214
  requirements: []
215
- rubyforge_project:
216
- rubygems_version: 2.6.12
217
- signing_key:
215
+ rubygems_version: 3.1.6
216
+ signing_key:
218
217
  specification_version: 4
219
218
  summary: generate fake data from json schema
220
219
  test_files: []