json_schema-faker 0.6.0 → 0.6.1
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 +5 -0
- data/VERSION +1 -1
- data/lib/json_schema/faker/strategy/greedy.rb +1 -1
- data/lib/json_schema/faker/strategy/simple.rb +19 -6
- 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: 55f8ba801612ccb07d821cc0428a9909b3ddff4c
|
|
4
|
+
data.tar.gz: 7c4f071e4a7c0e0ba22025dc6d5334d7a6a3c32f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '04390e5b4ab6c4a3a9782f32a55656465d6b0c4ecdfebd5507eca7cff91177acaa7ecc16eceb0d2be8e3773915dd156265530820693ccc713723ab2dcd02077b'
|
|
7
|
+
data.tar.gz: 664d28afe382ea2764198fab2a811129c78b01cbafae64b97668fb367ced53abdaa6db2fa0381c8ef6e6564d7644168731f1e9d2cf12fd8afe37a3d7e7043bfc
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.6.
|
|
1
|
+
0.6.1
|
|
@@ -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] =
|
|
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] =
|
|
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
|
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.
|
|
4
|
+
version: 0.6.1
|
|
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-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json_schema
|