fakeit 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -5
- data/README.md +1 -1
- data/fakeit.gemspec +2 -1
- data/lib/fakeit.rb +1 -0
- data/lib/fakeit/app/app.rb +2 -6
- data/lib/fakeit/openapi/example/array_example.rb +6 -2
- data/lib/fakeit/openapi/example/integer_example.rb +1 -1
- data/lib/fakeit/openapi/example/number_example.rb +1 -1
- data/lib/fakeit/openapi/example/object_example.rb +1 -1
- data/lib/fakeit/openapi/example/string_example.rb +4 -4
- data/lib/fakeit/openapi/schema.rb +1 -1
- data/lib/fakeit/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e00b82e5234f7a84b09aa97b54ca9bc6b3d21e180d70d04093cc9abfa70df47b
|
4
|
+
data.tar.gz: 2d4e588379c5e8d5db03044353c37318388eb3abbc44f1ff8582d29e1fcd70dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b31b1a0365c538bcd89f9a9b61d09477a36a522e2bc12dc88dc71603856c6e9c269aadb378dd83f34f37910fe2b76693a8bb11444306deaf1e54526b306cc294
|
7
|
+
data.tar.gz: 4db7cb39db416d99e1585a9bb141f803d5f555d7203fa4f4095b587f0d883593c7f9498093b3ba71ec30f6696a219dcb6925e10e18256268d30ddd2e1ab50057
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fakeit (0.3.
|
5
|
-
faker (~>
|
4
|
+
fakeit (0.3.1)
|
5
|
+
faker (~> 2.2)
|
6
6
|
openapi_parser (= 0.3.1)
|
7
7
|
rack (~> 2.0)
|
8
8
|
rack-cors (~> 1.0)
|
9
|
+
rainbow (~> 3.0)
|
9
10
|
slop (~> 4.6)
|
10
11
|
|
11
12
|
GEM
|
@@ -16,15 +17,15 @@ GEM
|
|
16
17
|
concurrent-ruby (1.1.5)
|
17
18
|
diff-lcs (1.3)
|
18
19
|
docile (1.3.2)
|
19
|
-
faker (
|
20
|
-
i18n (>= 0.
|
20
|
+
faker (2.2.1)
|
21
|
+
i18n (>= 0.8)
|
21
22
|
i18n (1.6.0)
|
22
23
|
concurrent-ruby (~> 1.0)
|
23
24
|
jaro_winkler (1.5.3)
|
24
25
|
json (2.2.0)
|
25
26
|
openapi_parser (0.3.1)
|
26
27
|
parallel (1.17.0)
|
27
|
-
parser (2.6.
|
28
|
+
parser (2.6.4.0)
|
28
29
|
ast (~> 2.4.0)
|
29
30
|
rack (2.0.7)
|
30
31
|
rack-cors (1.0.3)
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Openapi mock server is one of core components to support contract based developm
|
|
26
26
|
}
|
27
27
|
```
|
28
28
|
|
29
|
-
After tried several existing options, we cannot find a best solution to meet all the requirements. So we
|
29
|
+
After tried several existing options, we cannot find a best solution to meet all the requirements. So we end up with __Fakeit__.
|
30
30
|
|
31
31
|
## Features
|
32
32
|
|
data/fakeit.gemspec
CHANGED
@@ -32,9 +32,10 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency 'rubocop', '~> 0.67'
|
33
33
|
spec.add_development_dependency 'simplecov', '~> 0.16'
|
34
34
|
|
35
|
-
spec.add_dependency 'faker', '~>
|
35
|
+
spec.add_dependency 'faker', '~> 2.2'
|
36
36
|
spec.add_dependency 'openapi_parser', '0.3.1'
|
37
37
|
spec.add_dependency 'rack', '~> 2.0'
|
38
38
|
spec.add_dependency 'rack-cors', '~> 1.0'
|
39
|
+
spec.add_dependency 'rainbow', '~> 3.0'
|
39
40
|
spec.add_dependency 'slop', '~> 4.6'
|
40
41
|
end
|
data/lib/fakeit.rb
CHANGED
data/lib/fakeit/app/app.rb
CHANGED
@@ -18,12 +18,8 @@ module Fakeit
|
|
18
18
|
validate(operation, request)
|
19
19
|
response(operation)
|
20
20
|
rescue Fakeit::Validation::ValidationError => e
|
21
|
-
|
22
|
-
|
23
|
-
response(operation)
|
24
|
-
else
|
25
|
-
error(e)
|
26
|
-
end
|
21
|
+
Fakeit::Logger.warn(Rainbow(e.message).red)
|
22
|
+
options.permissive ? response(operation) : error(e)
|
27
23
|
end
|
28
24
|
|
29
25
|
def error(err)
|
@@ -18,10 +18,14 @@ module Fakeit
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def random_array_example(example_options)
|
21
|
-
size = retries =
|
21
|
+
size = retries = random_array_size(example_options)
|
22
22
|
[].tap { |result| generate_items(size, retries, example_options, result) }
|
23
23
|
end
|
24
24
|
|
25
|
+
def random_array_size(example_options)
|
26
|
+
uniqueItems ? min_array : Faker::Number.between(from: min_array, to: max_array(example_options[:depth]))
|
27
|
+
end
|
28
|
+
|
25
29
|
def generate_items(size, retries, example_options, result)
|
26
30
|
loop do
|
27
31
|
item = items.to_example(example_options)
|
@@ -35,7 +39,7 @@ module Fakeit
|
|
35
39
|
end
|
36
40
|
|
37
41
|
def add_depth(example_options)
|
38
|
-
example_options
|
42
|
+
{ **example_options, depth: example_options[:depth] + 1 }
|
39
43
|
end
|
40
44
|
|
41
45
|
def need_retry?(item, result, retries)
|
@@ -20,7 +20,7 @@ module Fakeit
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def random_number_example
|
23
|
-
(Faker::Number.between(num_rand_begin, num_rand_end) * num_multiple)
|
23
|
+
(Faker::Number.between(from: num_rand_begin, to: num_rand_end) * num_multiple)
|
24
24
|
.then { |result| multipleOf ? result : result.round(2) }
|
25
25
|
end
|
26
26
|
|
@@ -3,7 +3,7 @@ module Fakeit
|
|
3
3
|
module Example
|
4
4
|
def object_example(example_options)
|
5
5
|
properties.each_with_object({}) do |(name, schema), obj|
|
6
|
-
obj[name] = schema.to_example(example_options
|
6
|
+
obj[name] = schema.to_example(**example_options, property: name)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -18,8 +18,8 @@ module Fakeit
|
|
18
18
|
'uuid' => -> { SecureRandom.uuid },
|
19
19
|
'guid' => -> { SecureRandom.uuid },
|
20
20
|
'email' => -> { Faker::Internet.email },
|
21
|
-
'date' => -> { Faker::Date.backward(100).iso8601 },
|
22
|
-
'date-time' => -> { Faker::Time.backward(100).iso8601 }
|
21
|
+
'date' => -> { Faker::Date.backward(days: 100).iso8601 },
|
22
|
+
'date-time' => -> { Faker::Time.backward(days: 100).iso8601 }
|
23
23
|
}.freeze
|
24
24
|
|
25
25
|
def string_example(example_options)
|
@@ -72,7 +72,7 @@ module Fakeit
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def string_with_length
|
75
|
-
Faker::Internet.
|
75
|
+
Faker::Internet.username(specifier: min_string_length..max_string_length)
|
76
76
|
end
|
77
77
|
|
78
78
|
def min_string_length
|
@@ -88,7 +88,7 @@ module Fakeit
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def unknown_format
|
91
|
-
Fakeit::Logger.
|
91
|
+
Fakeit::Logger.info("Unknown string format: #{format}")
|
92
92
|
'Unknown string format'
|
93
93
|
end
|
94
94
|
end
|
data/lib/fakeit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakeit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Feng
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '2.2'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '2.2'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: openapi_parser
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '1.0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rainbow
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '3.0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '3.0'
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: slop
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|