fakeit 0.7.0 → 0.9.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/.circleci/config.yml +1 -1
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +41 -0
- data/Gemfile.lock +41 -34
- data/README.md +16 -11
- 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/array_validator.rb +12 -0
- data/lib/fakeit/core_extensions/reference.rb +9 -0
- 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/loader.rb +2 -1
- data/lib/fakeit/openapi/operation.rb +10 -20
- data/lib/fakeit/openapi/reference_error.rb +6 -0
- data/lib/fakeit/validation/validator.rb +4 -12
- data/lib/fakeit/version.rb +1 -1
- metadata +42 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f48fecd4f45a0532ec3dd35f088d2b365c3fbbee815d7722bddc59c926088cce
|
|
4
|
+
data.tar.gz: 1a8e59d4f67a4e952f7c31052815786b19884b5feed18ad281f6133ae585de1a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3685b6808f4b614c78e76f443e0698fbd01b2559b67bae344fc3bd9cf7a09b66ace980f36beb7837fd6a5263134c270695b568c63da6812ed613b1c667701710
|
|
7
|
+
data.tar.gz: dc831a3a34658853679da5a0b5cfa54bbb947bc9a7ee11e0dc2c830f22b077d7534fe287633142e95db4782e8652c6ba24903d92a21a2752e4366e8695a88e5a
|
data/.circleci/config.yml
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v0.9.0](https://github.com/JustinFeng/fakeit/tree/v0.9.0) (2021-03-18)
|
|
4
|
+
|
|
5
|
+
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.8.1...v0.9.0)
|
|
6
|
+
|
|
7
|
+
**Implemented enhancements:**
|
|
8
|
+
|
|
9
|
+
- Experimental feature to support plain text and binary response, e.g. application/pdf
|
|
10
|
+
|
|
11
|
+
## [v0.8.1](https://github.com/JustinFeng/fakeit/tree/v0.8.1) (2021-03-01)
|
|
12
|
+
|
|
13
|
+
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.8.0...v0.8.1)
|
|
14
|
+
|
|
15
|
+
**Fixed bugs:**
|
|
16
|
+
|
|
17
|
+
- Cannot load spec file from url [\#21](https://github.com/JustinFeng/fakeit/issues/21)
|
|
18
|
+
|
|
19
|
+
## [v0.8.0](https://github.com/JustinFeng/fakeit/tree/v0.8.0) (2021-02-27)
|
|
20
|
+
|
|
21
|
+
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.7.1...v0.8.0)
|
|
22
|
+
|
|
23
|
+
**Implemented enhancements:**
|
|
24
|
+
|
|
25
|
+
- Upgraded to ruby 3.0.0
|
|
26
|
+
|
|
27
|
+
## [v0.7.1](https://github.com/JustinFeng/fakeit/tree/v0.7.1) (2021-02-07)
|
|
28
|
+
|
|
29
|
+
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.7.0...v0.7.1)
|
|
30
|
+
|
|
31
|
+
**Fixed bugs:**
|
|
32
|
+
|
|
33
|
+
- ERROR NoMethodError: undefined method `to\_example' for \# [\#20](https://github.com/JustinFeng/fakeit/issues/20)
|
|
34
|
+
|
|
35
|
+
## [v0.7.0](https://github.com/JustinFeng/fakeit/tree/v0.7.0) (2020-10-22)
|
|
36
|
+
|
|
37
|
+
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.6.3...v0.7.0)
|
|
38
|
+
|
|
39
|
+
**Implemented enhancements:**
|
|
40
|
+
|
|
41
|
+
- Supported change mock server behaviour on the fly
|
|
42
|
+
- Allowed to redirect console log to a file
|
|
43
|
+
|
|
3
44
|
## [v0.6.3](https://github.com/JustinFeng/fakeit/tree/v0.6.3) (2020-09-11)
|
|
4
45
|
|
|
5
46
|
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.6.2...v0.6.3)
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
fakeit (0.
|
|
4
|
+
fakeit (0.9.1)
|
|
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.15
|
data/README.md
CHANGED
|
@@ -35,6 +35,7 @@ After tried several existing options, we cannot find a best solution to meet all
|
|
|
35
35
|
* Load specification from local or remote
|
|
36
36
|
* Support hot reload local specification
|
|
37
37
|
* Support specification in yaml or json format
|
|
38
|
+
* [Experimental] Support plain text and binary response, e.g. `application/pdf`
|
|
38
39
|
|
|
39
40
|
## Installation
|
|
40
41
|
|
|
@@ -66,6 +67,12 @@ Or use the [docker image](https://hub.docker.com/r/realfengjia/fakeit)
|
|
|
66
67
|
-v, --version
|
|
67
68
|
-h, --help
|
|
68
69
|
|
|
70
|
+
**Notes:**
|
|
71
|
+
* See [here](docs/random.md) for Openapi properties supported in random response generation
|
|
72
|
+
* See [here](docs/static.md) for default value in static response generation
|
|
73
|
+
* Regarding `--use-example` mode, property without example specified will still be randomly or statically generated
|
|
74
|
+
* Random response generation can not handle recursive schema reference. If you do need it in your spec file, please provide `example` property for the recursive part of schema and specify `--use-example` option.
|
|
75
|
+
|
|
69
76
|
### Configuration endpoint
|
|
70
77
|
|
|
71
78
|
Mock server behaviour can be changed on the fly
|
|
@@ -81,20 +88,18 @@ Update config:
|
|
|
81
88
|
Request and response:
|
|
82
89
|
```json
|
|
83
90
|
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
"permissive": false,
|
|
92
|
+
"use_example": true,
|
|
93
|
+
"static": false,
|
|
94
|
+
"static_types": [
|
|
95
|
+
"integer"
|
|
96
|
+
],
|
|
97
|
+
"static_properties": [
|
|
98
|
+
"id"
|
|
99
|
+
]
|
|
89
100
|
}
|
|
90
101
|
```
|
|
91
102
|
|
|
92
|
-
**Notes:**
|
|
93
|
-
* See [here](docs/random.md) for Openapi properties supported in random response generation
|
|
94
|
-
* See [here](docs/static.md) for default value in static response generation
|
|
95
|
-
* Regarding `--use-example` mode, property without example specified will still be randomly or statically generated
|
|
96
|
-
* Random response generation can not handle recursive schema reference. If you do need it in your spec file, please provide `example` property for the recursive part of schema and specify `--use-example` option.
|
|
97
|
-
|
|
98
103
|
## Development
|
|
99
104
|
|
|
100
105
|
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake` to run the tests.
|
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(
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SchemaValidator
|
|
3
|
+
class ArrayValidator
|
|
4
|
+
alias old_impl coerce_and_validate
|
|
5
|
+
|
|
6
|
+
def coerce_and_validate(value, schema, **keyword_args)
|
|
7
|
+
coerced_value = schema.parent.is_a?(OpenAPIParser::Schemas::Parameter) ? [*value] : value
|
|
8
|
+
old_impl(coerced_value, schema, **keyword_args)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
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
|
|
@@ -22,39 +20,31 @@ module Fakeit
|
|
|
22
20
|
response_schema
|
|
23
21
|
&.schema
|
|
24
22
|
&.to_example(example_options)
|
|
25
|
-
&.then(&
|
|
23
|
+
&.then(&method(:serialise))
|
|
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
|
|
|
31
|
+
def serialise(body) = body.is_a?(String) ? body : JSON.generate(body)
|
|
32
|
+
|
|
35
33
|
def example_options
|
|
36
34
|
{ use_example: @app_options.use_example, use_static: @app_options.method(:use_static?), depth: 0 }
|
|
37
35
|
end
|
|
38
36
|
|
|
39
37
|
def response_content
|
|
40
|
-
response.last.content&.find { |k, _| k =~ %r{^application/.*json} }
|
|
38
|
+
response.last.content&.find { |k, _| k =~ %r{^application/.*json} || k == 'application/pdf' }
|
|
41
39
|
end
|
|
42
40
|
|
|
43
|
-
def response_schema
|
|
44
|
-
response_content&.last
|
|
45
|
-
end
|
|
41
|
+
def response_schema = response_content&.last
|
|
46
42
|
|
|
47
|
-
def response_content_type
|
|
48
|
-
response_content&.first
|
|
49
|
-
end
|
|
43
|
+
def response_content_type = response_content&.first
|
|
50
44
|
|
|
51
|
-
def response_headers
|
|
52
|
-
response.last.headers
|
|
53
|
-
end
|
|
45
|
+
def response_headers = response.last.headers
|
|
54
46
|
|
|
55
|
-
def response
|
|
56
|
-
@request_operation.operation_object.responses.response.min
|
|
57
|
-
end
|
|
47
|
+
def response = @request_operation.operation_object.responses.response.min
|
|
58
48
|
end
|
|
59
49
|
end
|
|
60
50
|
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.9.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Feng
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-04-18 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
|
|
@@ -235,6 +263,8 @@ files:
|
|
|
235
263
|
- lib/fakeit/app/options.rb
|
|
236
264
|
- lib/fakeit/app/routes/config_route.rb
|
|
237
265
|
- lib/fakeit/app/routes/openapi_route.rb
|
|
266
|
+
- lib/fakeit/core_extensions/array_validator.rb
|
|
267
|
+
- lib/fakeit/core_extensions/reference.rb
|
|
238
268
|
- lib/fakeit/core_extensions/schema.rb
|
|
239
269
|
- lib/fakeit/logger.rb
|
|
240
270
|
- lib/fakeit/middleware/recorder.rb
|
|
@@ -246,6 +276,7 @@ files:
|
|
|
246
276
|
- lib/fakeit/openapi/example/string_example.rb
|
|
247
277
|
- lib/fakeit/openapi/loader.rb
|
|
248
278
|
- lib/fakeit/openapi/operation.rb
|
|
279
|
+
- lib/fakeit/openapi/reference_error.rb
|
|
249
280
|
- lib/fakeit/openapi/schema.rb
|
|
250
281
|
- lib/fakeit/openapi/specification.rb
|
|
251
282
|
- lib/fakeit/validation/validation_error.rb
|
|
@@ -255,7 +286,7 @@ homepage: https://github.com/JustinFeng/fakeit
|
|
|
255
286
|
licenses:
|
|
256
287
|
- MIT
|
|
257
288
|
metadata: {}
|
|
258
|
-
post_install_message:
|
|
289
|
+
post_install_message:
|
|
259
290
|
rdoc_options: []
|
|
260
291
|
require_paths:
|
|
261
292
|
- lib
|
|
@@ -263,15 +294,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
263
294
|
requirements:
|
|
264
295
|
- - ">="
|
|
265
296
|
- !ruby/object:Gem::Version
|
|
266
|
-
version:
|
|
297
|
+
version: 3.0.0
|
|
267
298
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
268
299
|
requirements:
|
|
269
300
|
- - ">="
|
|
270
301
|
- !ruby/object:Gem::Version
|
|
271
302
|
version: '0'
|
|
272
303
|
requirements: []
|
|
273
|
-
rubygems_version: 3.
|
|
274
|
-
signing_key:
|
|
304
|
+
rubygems_version: 3.2.3
|
|
305
|
+
signing_key:
|
|
275
306
|
specification_version: 4
|
|
276
307
|
summary: Create mock server from Openapi specification
|
|
277
308
|
test_files: []
|