fakeit 0.7.1 → 0.8.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 +4 -4
- data/.circleci/config.yml +1 -1
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +41 -34
- data/fakeit.gemspec +5 -3
- data/lib/fakeit.rb +1 -1
- data/lib/fakeit/app/helpers/body_parser.rb +1 -1
- data/lib/fakeit/app/helpers/response_builder.rb +5 -15
- data/lib/fakeit/app/routes/config_route.rb +1 -3
- data/lib/fakeit/app/routes/openapi_route.rb +2 -6
- data/lib/fakeit/core_extensions/reference.rb +1 -3
- data/lib/fakeit/core_extensions/schema.rb +1 -3
- data/lib/fakeit/middleware/recorder.rb +2 -6
- data/lib/fakeit/openapi/example/array_example.rb +5 -15
- data/lib/fakeit/openapi/example/integer_example.rb +4 -12
- data/lib/fakeit/openapi/example/number_example.rb +6 -19
- data/lib/fakeit/openapi/example/string_example.rb +8 -24
- data/lib/fakeit/openapi/operation.rb +7 -21
- data/lib/fakeit/validation/validator.rb +4 -12
- data/lib/fakeit/version.rb +1 -1
- metadata +36 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 285f5035e5fbd29cc124715beb4a901f63641eace09deda6b42a520222bc706c
|
|
4
|
+
data.tar.gz: 4dcacbd9adbfabdb80e265e740829afc920e9653563c047206197f39716336e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b07445c0ddc4b8d21918b0ee6ede3108d1fcd01ff0babe8ae8aed1cc3686f4953d7ee0486247dd6f77195abafcd1a1584c44fe0a2e7030f24fba476883f256f
|
|
7
|
+
data.tar.gz: ecf3f4325a81c3ca550ff08f4738385ae9ae3d4de46bd32262dc58d303ac40f80ecd505ef29b411e59c25f360ca38c3f09c7839e75e538c33828d86b5872bef2
|
data/.circleci/config.yml
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v0.7.1](https://github.com/JustinFeng/fakeit/tree/v0.7.1) (2021-02-07)
|
|
4
|
+
|
|
5
|
+
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.7.0...v0.7.1)
|
|
6
|
+
|
|
7
|
+
**Fixed bugs:**
|
|
8
|
+
|
|
9
|
+
- ERROR NoMethodError: undefined method `to\_example' for \# [\#20](https://github.com/JustinFeng/fakeit/issues/20)
|
|
10
|
+
|
|
3
11
|
## [v0.7.0](https://github.com/JustinFeng/fakeit/tree/v0.7.0) (2020-10-22)
|
|
4
12
|
|
|
5
13
|
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.6.3...v0.7.0)
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
fakeit (0.
|
|
4
|
+
fakeit (0.8.0)
|
|
5
5
|
faker (= 2.13.0)
|
|
6
6
|
openapi_parser (= 0.12.1)
|
|
7
7
|
rack (~> 2.0)
|
|
@@ -9,22 +9,23 @@ PATH
|
|
|
9
9
|
rainbow (~> 3.0)
|
|
10
10
|
regexp-examples (= 1.5.1)
|
|
11
11
|
slop (~> 4.8)
|
|
12
|
+
webrick (~> 1.7)
|
|
12
13
|
|
|
13
14
|
GEM
|
|
14
15
|
remote: https://rubygems.org/
|
|
15
16
|
specs:
|
|
16
|
-
ast (2.4.
|
|
17
|
+
ast (2.4.2)
|
|
17
18
|
byebug (11.1.3)
|
|
18
|
-
concurrent-ruby (1.1.
|
|
19
|
+
concurrent-ruby (1.1.8)
|
|
19
20
|
diff-lcs (1.4.4)
|
|
20
|
-
docile (1.3.
|
|
21
|
+
docile (1.3.5)
|
|
21
22
|
faker (2.13.0)
|
|
22
23
|
i18n (>= 1.6, < 2)
|
|
23
|
-
i18n (1.8.
|
|
24
|
+
i18n (1.8.9)
|
|
24
25
|
concurrent-ruby (~> 1.0)
|
|
25
26
|
openapi_parser (0.12.1)
|
|
26
|
-
parallel (1.
|
|
27
|
-
parser (
|
|
27
|
+
parallel (1.20.1)
|
|
28
|
+
parser (3.0.0.0)
|
|
28
29
|
ast (~> 2.4.1)
|
|
29
30
|
rack (2.2.3)
|
|
30
31
|
rack-cors (1.1.1)
|
|
@@ -32,41 +33,46 @@ GEM
|
|
|
32
33
|
rack-test (1.1.0)
|
|
33
34
|
rack (>= 1.0, < 3)
|
|
34
35
|
rainbow (3.0.0)
|
|
35
|
-
rake (
|
|
36
|
+
rake (13.0.3)
|
|
36
37
|
regexp-examples (1.5.1)
|
|
37
|
-
regexp_parser (1.
|
|
38
|
+
regexp_parser (2.1.1)
|
|
38
39
|
rexml (3.2.4)
|
|
39
|
-
rspec (3.
|
|
40
|
-
rspec-core (~> 3.
|
|
41
|
-
rspec-expectations (~> 3.
|
|
42
|
-
rspec-mocks (~> 3.
|
|
43
|
-
rspec-core (3.
|
|
44
|
-
rspec-support (~> 3.
|
|
45
|
-
rspec-expectations (3.
|
|
40
|
+
rspec (3.10.0)
|
|
41
|
+
rspec-core (~> 3.10.0)
|
|
42
|
+
rspec-expectations (~> 3.10.0)
|
|
43
|
+
rspec-mocks (~> 3.10.0)
|
|
44
|
+
rspec-core (3.10.1)
|
|
45
|
+
rspec-support (~> 3.10.0)
|
|
46
|
+
rspec-expectations (3.10.1)
|
|
46
47
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
47
|
-
rspec-support (~> 3.
|
|
48
|
-
rspec-mocks (3.
|
|
48
|
+
rspec-support (~> 3.10.0)
|
|
49
|
+
rspec-mocks (3.10.2)
|
|
49
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
50
|
-
rspec-support (~> 3.
|
|
51
|
-
rspec-support (3.
|
|
52
|
-
rubocop (
|
|
51
|
+
rspec-support (~> 3.10.0)
|
|
52
|
+
rspec-support (3.10.2)
|
|
53
|
+
rubocop (1.10.0)
|
|
53
54
|
parallel (~> 1.10)
|
|
54
|
-
parser (>=
|
|
55
|
+
parser (>= 3.0.0.0)
|
|
55
56
|
rainbow (>= 2.2.2, < 4.0)
|
|
56
|
-
regexp_parser (>= 1.
|
|
57
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
57
58
|
rexml
|
|
58
|
-
rubocop-ast (>=
|
|
59
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
|
59
60
|
ruby-progressbar (~> 1.7)
|
|
60
|
-
unicode-display_width (>= 1.4.0, <
|
|
61
|
-
rubocop-ast (
|
|
62
|
-
parser (>= 2.7.1.
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
62
|
+
rubocop-ast (1.4.1)
|
|
63
|
+
parser (>= 2.7.1.5)
|
|
64
|
+
rubocop-rake (0.5.1)
|
|
65
|
+
rubocop
|
|
66
|
+
ruby-progressbar (1.11.0)
|
|
67
|
+
simplecov (0.21.2)
|
|
65
68
|
docile (~> 1.1)
|
|
66
69
|
simplecov-html (~> 0.11)
|
|
67
|
-
|
|
70
|
+
simplecov_json_formatter (~> 0.1)
|
|
71
|
+
simplecov-html (0.12.3)
|
|
72
|
+
simplecov_json_formatter (0.1.2)
|
|
68
73
|
slop (4.8.2)
|
|
69
|
-
unicode-display_width (
|
|
74
|
+
unicode-display_width (2.0.0)
|
|
75
|
+
webrick (1.7.0)
|
|
70
76
|
|
|
71
77
|
PLATFORMS
|
|
72
78
|
ruby
|
|
@@ -76,10 +82,11 @@ DEPENDENCIES
|
|
|
76
82
|
byebug (~> 11.0)
|
|
77
83
|
fakeit!
|
|
78
84
|
rack-test (~> 1.1)
|
|
79
|
-
rake (~>
|
|
85
|
+
rake (~> 13.0)
|
|
80
86
|
rspec (~> 3.0)
|
|
81
|
-
rubocop (~>
|
|
87
|
+
rubocop (~> 1.10)
|
|
88
|
+
rubocop-rake (~> 0.5)
|
|
82
89
|
simplecov (~> 0.18)
|
|
83
90
|
|
|
84
91
|
BUNDLED WITH
|
|
85
|
-
2.
|
|
92
|
+
2.2.11
|
data/fakeit.gemspec
CHANGED
|
@@ -22,14 +22,15 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.executables = 'fakeit'
|
|
23
23
|
spec.require_paths = ['lib']
|
|
24
24
|
|
|
25
|
-
spec.required_ruby_version = '>=
|
|
25
|
+
spec.required_ruby_version = '>= 3.0.0'
|
|
26
26
|
|
|
27
27
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
|
28
28
|
spec.add_development_dependency 'byebug', '~> 11.0'
|
|
29
29
|
spec.add_development_dependency 'rack-test', '~> 1.1'
|
|
30
|
-
spec.add_development_dependency 'rake', '~>
|
|
30
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
|
31
31
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
32
|
-
spec.add_development_dependency 'rubocop', '~>
|
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 1.10'
|
|
33
|
+
spec.add_development_dependency 'rubocop-rake', '~> 0.5'
|
|
33
34
|
spec.add_development_dependency 'simplecov', '~> 0.18'
|
|
34
35
|
|
|
35
36
|
spec.add_dependency 'faker', '2.13.0'
|
|
@@ -39,4 +40,5 @@ Gem::Specification.new do |spec|
|
|
|
39
40
|
spec.add_dependency 'rainbow', '~> 3.0'
|
|
40
41
|
spec.add_dependency 'regexp-examples', '1.5.1'
|
|
41
42
|
spec.add_dependency 'slop', '~> 4.8'
|
|
43
|
+
spec.add_dependency 'webrick', '~> 1.7'
|
|
42
44
|
end
|
data/lib/fakeit.rb
CHANGED
|
@@ -9,7 +9,7 @@ require 'rack'
|
|
|
9
9
|
require 'logger'
|
|
10
10
|
require 'rainbow'
|
|
11
11
|
|
|
12
|
-
Dir.glob(File.join(File.dirname(__FILE__), 'fakeit', '**/*.rb')).
|
|
12
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'fakeit', '**/*.rb')).each { require _1 }
|
|
13
13
|
|
|
14
14
|
module Fakeit
|
|
15
15
|
class << self
|
|
@@ -23,7 +23,7 @@ module Fakeit
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def parse_form_data(params)
|
|
26
|
-
params.transform_values { |v| v.
|
|
26
|
+
params.transform_values { |v| v.instance_of?(Hash) && v[:tempfile] ? v[:tempfile].read : v }
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -3,25 +3,15 @@ module Fakeit
|
|
|
3
3
|
module Helpers
|
|
4
4
|
class ResponseBuilder
|
|
5
5
|
class << self
|
|
6
|
-
def error(code, err)
|
|
7
|
-
[code, { 'Content-Type' => 'application/json' }, [{ message: err.message }.to_json]]
|
|
8
|
-
end
|
|
6
|
+
def error(code, err) = [code, { 'Content-Type' => 'application/json' }, [{ message: err.message }.to_json]]
|
|
9
7
|
|
|
10
|
-
def not_found
|
|
11
|
-
[404, {}, ['Not Found']]
|
|
12
|
-
end
|
|
8
|
+
def not_found = [404, {}, ['Not Found']]
|
|
13
9
|
|
|
14
|
-
def method_not_allowed
|
|
15
|
-
[405, {}, ['Method Not Allowed']]
|
|
16
|
-
end
|
|
10
|
+
def method_not_allowed = [405, {}, ['Method Not Allowed']]
|
|
17
11
|
|
|
18
|
-
def unsupported_media_type
|
|
19
|
-
[415, {}, ['Unsupported Media Type']]
|
|
20
|
-
end
|
|
12
|
+
def unsupported_media_type = [415, {}, ['Unsupported Media Type']]
|
|
21
13
|
|
|
22
|
-
def ok(body)
|
|
23
|
-
[200, { 'Content-Type' => 'application/json' }, [body.to_json]]
|
|
24
|
-
end
|
|
14
|
+
def ok(body) = [200, { 'Content-Type' => 'application/json' }, [body.to_json]]
|
|
25
15
|
end
|
|
26
16
|
end
|
|
27
17
|
end
|
|
@@ -2,9 +2,7 @@ module Fakeit
|
|
|
2
2
|
module App
|
|
3
3
|
module Routes
|
|
4
4
|
class OpenapiRoute
|
|
5
|
-
def initialize(spec_file)
|
|
6
|
-
@specification = Fakeit::Openapi::Specification.new(spec_file)
|
|
7
|
-
end
|
|
5
|
+
def initialize(spec_file) = @specification = Fakeit::Openapi::Specification.new(spec_file)
|
|
8
6
|
|
|
9
7
|
def call(request, options)
|
|
10
8
|
@specification
|
|
@@ -22,9 +20,7 @@ module Fakeit
|
|
|
22
20
|
options.permissive ? response(operation) : Fakeit::App::Helpers::ResponseBuilder.error(418, e)
|
|
23
21
|
end
|
|
24
22
|
|
|
25
|
-
def response(operation)
|
|
26
|
-
[operation.status, operation.headers, [operation.body]]
|
|
27
|
-
end
|
|
23
|
+
def response(operation) = [operation.status, operation.headers, [operation.body]]
|
|
28
24
|
|
|
29
25
|
def validate(operation, request)
|
|
30
26
|
operation.validate(
|
|
@@ -3,9 +3,7 @@ require 'fakeit/openapi/schema'
|
|
|
3
3
|
module OpenAPIParser
|
|
4
4
|
module Schemas
|
|
5
5
|
class Reference
|
|
6
|
-
def to_example(_)
|
|
7
|
-
raise Fakeit::Openapi::ReferenceError, "Invalid $ref at \"#{ref}\""
|
|
8
|
-
end
|
|
6
|
+
def to_example(_) = raise(Fakeit::Openapi::ReferenceError, "Invalid $ref at \"#{ref}\"")
|
|
9
7
|
end
|
|
10
8
|
end
|
|
11
9
|
end
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
module Fakeit
|
|
2
2
|
module Middleware
|
|
3
3
|
class Recorder
|
|
4
|
-
def initialize(app)
|
|
5
|
-
@app = app
|
|
6
|
-
end
|
|
4
|
+
def initialize(app) = @app = app
|
|
7
5
|
|
|
8
6
|
def call(env)
|
|
9
7
|
env
|
|
@@ -20,9 +18,7 @@ module Fakeit
|
|
|
20
18
|
&.tap { |body| body.rewind }
|
|
21
19
|
end
|
|
22
20
|
|
|
23
|
-
def log_response(response)
|
|
24
|
-
Logger.info("Response body: #{response[2].first}")
|
|
25
|
-
end
|
|
21
|
+
def log_response(response) = Logger.info("Response body: #{response[2].first}")
|
|
26
22
|
end
|
|
27
23
|
end
|
|
28
24
|
end
|
|
@@ -33,25 +33,15 @@ module Fakeit
|
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
def add_depth(example_options)
|
|
37
|
-
{ **example_options, depth: example_options[:depth] + 1 }
|
|
38
|
-
end
|
|
36
|
+
def add_depth(example_options) = { **example_options, depth: example_options[:depth] + 1 }
|
|
39
37
|
|
|
40
|
-
def need_retry?(item, result, retries)
|
|
41
|
-
uniqueItems && result.include?(item) && retries.positive?
|
|
42
|
-
end
|
|
38
|
+
def need_retry?(item, result, retries) = uniqueItems && result.include?(item) && retries.positive?
|
|
43
39
|
|
|
44
|
-
def non_empty_size
|
|
45
|
-
[min_array, 1].max
|
|
46
|
-
end
|
|
40
|
+
def non_empty_size = [min_array, 1].max
|
|
47
41
|
|
|
48
|
-
def min_array
|
|
49
|
-
minItems || 1
|
|
50
|
-
end
|
|
42
|
+
def min_array = minItems || 1
|
|
51
43
|
|
|
52
|
-
def max_array(depth)
|
|
53
|
-
maxItems || min_array + (depth > 1 ? 2 : 9)
|
|
54
|
-
end
|
|
44
|
+
def max_array(depth) = maxItems || min_array + (depth > 1 ? 2 : 9)
|
|
55
45
|
end
|
|
56
46
|
end
|
|
57
47
|
end
|
|
@@ -29,21 +29,13 @@ module Fakeit
|
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
def int_rand_begin
|
|
33
|
-
min_int / int_multiple + int_rand_begin_adjust
|
|
34
|
-
end
|
|
32
|
+
def int_rand_begin = min_int / int_multiple + int_rand_begin_adjust
|
|
35
33
|
|
|
36
|
-
def int_rand_end
|
|
37
|
-
max_int / int_multiple
|
|
38
|
-
end
|
|
34
|
+
def int_rand_end = max_int / int_multiple
|
|
39
35
|
|
|
40
|
-
def int_rand_begin_adjust
|
|
41
|
-
(min_int % int_multiple).zero? ? 0 : 1
|
|
42
|
-
end
|
|
36
|
+
def int_rand_begin_adjust = (min_int % int_multiple).zero? ? 0 : 1
|
|
43
37
|
|
|
44
|
-
def int_multiple
|
|
45
|
-
multipleOf || 1
|
|
46
|
-
end
|
|
38
|
+
def int_multiple = multipleOf || 1
|
|
47
39
|
|
|
48
40
|
def min_int
|
|
49
41
|
if minimum
|
|
@@ -14,35 +14,22 @@ module Fakeit
|
|
|
14
14
|
|
|
15
15
|
private
|
|
16
16
|
|
|
17
|
-
def static_number_example
|
|
18
|
-
(num_rand_end * num_multiple)
|
|
19
|
-
.then { multipleOf ? _1 : _1.round(2) }
|
|
20
|
-
end
|
|
17
|
+
def static_number_example = (num_rand_end * num_multiple).then { multipleOf ? _1 : _1.round(2) }
|
|
21
18
|
|
|
22
19
|
def random_number_example
|
|
23
20
|
(Faker::Number.between(from: num_rand_begin, to: num_rand_end) * num_multiple)
|
|
24
21
|
.then { multipleOf ? _1 : _1.round(2) }
|
|
25
22
|
end
|
|
26
23
|
|
|
27
|
-
def num_rand_begin
|
|
28
|
-
multipleOf ? (min_num / multipleOf).ceil : min_num
|
|
29
|
-
end
|
|
24
|
+
def num_rand_begin = multipleOf ? (min_num / multipleOf).ceil : min_num
|
|
30
25
|
|
|
31
|
-
def num_rand_end
|
|
32
|
-
multipleOf ? (max_num / multipleOf).floor : max_num
|
|
33
|
-
end
|
|
26
|
+
def num_rand_end = multipleOf ? (max_num / multipleOf).floor : max_num
|
|
34
27
|
|
|
35
|
-
def num_multiple
|
|
36
|
-
multipleOf || 1
|
|
37
|
-
end
|
|
28
|
+
def num_multiple = multipleOf || 1
|
|
38
29
|
|
|
39
|
-
def min_num
|
|
40
|
-
(minimum || MIN_NUM).to_f.ceil(2)
|
|
41
|
-
end
|
|
30
|
+
def min_num = (minimum || MIN_NUM).to_f.ceil(2)
|
|
42
31
|
|
|
43
|
-
def max_num
|
|
44
|
-
(maximum || MAX_NUM).to_f.floor(2)
|
|
45
|
-
end
|
|
32
|
+
def max_num = (maximum || MAX_NUM).to_f.floor(2)
|
|
46
33
|
end
|
|
47
34
|
end
|
|
48
35
|
end
|
|
@@ -65,13 +65,9 @@ module Fakeit
|
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
def static_string_with_length
|
|
69
|
-
'1' * max_string_length
|
|
70
|
-
end
|
|
68
|
+
def static_string_with_length = '1' * max_string_length
|
|
71
69
|
|
|
72
|
-
def static_string_format
|
|
73
|
-
(STATIC_FORMAT_HANDLERS[format] || method(:unknown_format))[]
|
|
74
|
-
end
|
|
70
|
+
def static_string_format = (STATIC_FORMAT_HANDLERS[format] || method(:unknown_format))[]
|
|
75
71
|
|
|
76
72
|
def static_string_pattern
|
|
77
73
|
@static_string_pattern ||= @string_pattern.examples(
|
|
@@ -79,29 +75,17 @@ module Fakeit
|
|
|
79
75
|
).first
|
|
80
76
|
end
|
|
81
77
|
|
|
82
|
-
def length_constraint
|
|
83
|
-
minLength || maxLength
|
|
84
|
-
end
|
|
78
|
+
def length_constraint = minLength || maxLength
|
|
85
79
|
|
|
86
|
-
def string_with_length
|
|
87
|
-
Faker::Internet.username(specifier: min_string_length..max_string_length)
|
|
88
|
-
end
|
|
80
|
+
def string_with_length = Faker::Internet.username(specifier: min_string_length..max_string_length)
|
|
89
81
|
|
|
90
|
-
def min_string_length
|
|
91
|
-
minLength || 0
|
|
92
|
-
end
|
|
82
|
+
def min_string_length = minLength || 0
|
|
93
83
|
|
|
94
|
-
def max_string_length
|
|
95
|
-
maxLength || min_string_length + 10
|
|
96
|
-
end
|
|
84
|
+
def max_string_length = maxLength || min_string_length + 10
|
|
97
85
|
|
|
98
|
-
def random_string_format
|
|
99
|
-
(RANDOM_FORMAT_HANDLERS[format] || method(:unknown_format))[]
|
|
100
|
-
end
|
|
86
|
+
def random_string_format = (RANDOM_FORMAT_HANDLERS[format] || method(:unknown_format))[]
|
|
101
87
|
|
|
102
|
-
def random_string_pattern
|
|
103
|
-
@random_string_pattern ||= @string_pattern.random_example(max_repeater_variance: 1)
|
|
104
|
-
end
|
|
88
|
+
def random_string_pattern = @random_string_pattern ||= @string_pattern.random_example(max_repeater_variance: 1)
|
|
105
89
|
|
|
106
90
|
def unknown_format
|
|
107
91
|
Logger.info("Unknown string format: #{format}")
|
|
@@ -7,9 +7,7 @@ module Fakeit
|
|
|
7
7
|
@app_options = app_options
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def status
|
|
11
|
-
response.first.to_i
|
|
12
|
-
end
|
|
10
|
+
def status = response.first.to_i
|
|
13
11
|
|
|
14
12
|
def headers
|
|
15
13
|
response_headers
|
|
@@ -26,9 +24,7 @@ module Fakeit
|
|
|
26
24
|
.to_s
|
|
27
25
|
end
|
|
28
26
|
|
|
29
|
-
def validate(
|
|
30
|
-
@validator.validate(**request_parts)
|
|
31
|
-
end
|
|
27
|
+
def validate(...) = @validator.validate(...)
|
|
32
28
|
|
|
33
29
|
private
|
|
34
30
|
|
|
@@ -36,25 +32,15 @@ module Fakeit
|
|
|
36
32
|
{ use_example: @app_options.use_example, use_static: @app_options.method(:use_static?), depth: 0 }
|
|
37
33
|
end
|
|
38
34
|
|
|
39
|
-
def response_content
|
|
40
|
-
response.last.content&.find { |k, _| k =~ %r{^application/.*json} }
|
|
41
|
-
end
|
|
35
|
+
def response_content = response.last.content&.find { |k, _| k =~ %r{^application/.*json} }
|
|
42
36
|
|
|
43
|
-
def response_schema
|
|
44
|
-
response_content&.last
|
|
45
|
-
end
|
|
37
|
+
def response_schema = response_content&.last
|
|
46
38
|
|
|
47
|
-
def response_content_type
|
|
48
|
-
response_content&.first
|
|
49
|
-
end
|
|
39
|
+
def response_content_type = response_content&.first
|
|
50
40
|
|
|
51
|
-
def response_headers
|
|
52
|
-
response.last.headers
|
|
53
|
-
end
|
|
41
|
+
def response_headers = response.last.headers
|
|
54
42
|
|
|
55
|
-
def response
|
|
56
|
-
@request_operation.operation_object.responses.response.min
|
|
57
|
-
end
|
|
43
|
+
def response = @request_operation.operation_object.responses.response.min
|
|
58
44
|
end
|
|
59
45
|
end
|
|
60
46
|
end
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
module Fakeit
|
|
2
2
|
module Validation
|
|
3
3
|
class Validator
|
|
4
|
-
def initialize(operation)
|
|
5
|
-
@operation = operation
|
|
6
|
-
end
|
|
4
|
+
def initialize(operation) = @operation = operation
|
|
7
5
|
|
|
8
6
|
def validate(body: {}, params: {}, headers: {})
|
|
9
7
|
options = OpenAPIParser::SchemaValidator::Options.new(coerce_value: true)
|
|
@@ -26,17 +24,11 @@ module Fakeit
|
|
|
26
24
|
end
|
|
27
25
|
end
|
|
28
26
|
|
|
29
|
-
def can_validate?(media_type)
|
|
30
|
-
media_type =~ %r{^application/.*json} || media_type == 'multipart/form-data'
|
|
31
|
-
end
|
|
27
|
+
def can_validate?(media_type) = media_type =~ %r{^application/.*json} || media_type == 'multipart/form-data'
|
|
32
28
|
|
|
33
|
-
def request_content_types
|
|
34
|
-
request_body&.content&.keys.to_a
|
|
35
|
-
end
|
|
29
|
+
def request_content_types = request_body&.content&.keys.to_a
|
|
36
30
|
|
|
37
|
-
def request_body
|
|
38
|
-
@operation.operation_object.request_body
|
|
39
|
-
end
|
|
31
|
+
def request_body = @operation.operation_object.request_body
|
|
40
32
|
end
|
|
41
33
|
end
|
|
42
34
|
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.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Feng
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-02-
|
|
11
|
+
date: 2021-02-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -58,14 +58,14 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
61
|
+
version: '13.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: '
|
|
68
|
+
version: '13.0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: rspec
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -86,14 +86,28 @@ dependencies:
|
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '
|
|
89
|
+
version: '1.10'
|
|
90
90
|
type: :development
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '
|
|
96
|
+
version: '1.10'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rubocop-rake
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0.5'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0.5'
|
|
97
111
|
- !ruby/object:Gem::Dependency
|
|
98
112
|
name: simplecov
|
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -206,6 +220,20 @@ dependencies:
|
|
|
206
220
|
- - "~>"
|
|
207
221
|
- !ruby/object:Gem::Version
|
|
208
222
|
version: '4.8'
|
|
223
|
+
- !ruby/object:Gem::Dependency
|
|
224
|
+
name: webrick
|
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
|
226
|
+
requirements:
|
|
227
|
+
- - "~>"
|
|
228
|
+
- !ruby/object:Gem::Version
|
|
229
|
+
version: '1.7'
|
|
230
|
+
type: :runtime
|
|
231
|
+
prerelease: false
|
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
233
|
+
requirements:
|
|
234
|
+
- - "~>"
|
|
235
|
+
- !ruby/object:Gem::Version
|
|
236
|
+
version: '1.7'
|
|
209
237
|
description: Create mock server from Openapi specification
|
|
210
238
|
email:
|
|
211
239
|
- realfengjia@foxmail.com
|
|
@@ -265,14 +293,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
265
293
|
requirements:
|
|
266
294
|
- - ">="
|
|
267
295
|
- !ruby/object:Gem::Version
|
|
268
|
-
version:
|
|
296
|
+
version: 3.0.0
|
|
269
297
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
298
|
requirements:
|
|
271
299
|
- - ">="
|
|
272
300
|
- !ruby/object:Gem::Version
|
|
273
301
|
version: '0'
|
|
274
302
|
requirements: []
|
|
275
|
-
rubygems_version: 3.
|
|
303
|
+
rubygems_version: 3.2.3
|
|
276
304
|
signing_key:
|
|
277
305
|
specification_version: 4
|
|
278
306
|
summary: Create mock server from Openapi specification
|