fakeit 0.10.0 → 0.12.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/.gitignore +0 -2
- data/.rubocop.yml +28 -3
- data/CHANGELOG.md +20 -17
- data/Gemfile +12 -1
- data/Gemfile.lock +104 -62
- data/README.md +3 -1
- data/Rakefile +3 -3
- data/bin/fakeit +2 -1
- data/fakeit.gemspec +28 -32
- data/lib/fakeit/app/app_builder.rb +15 -11
- data/lib/fakeit/app/helpers/body_parser.rb +7 -7
- data/lib/fakeit/app/helpers/response_builder.rb +5 -5
- data/lib/fakeit/app/options.rb +16 -2
- data/lib/fakeit/app/routes/config_route.rb +3 -3
- data/lib/fakeit/app/routes/openapi_route.rb +4 -5
- data/lib/fakeit/core_extensions/array_validator.rb +1 -1
- data/lib/fakeit/core_extensions/schema.rb +4 -4
- data/lib/fakeit/middleware/recorder.rb +3 -3
- data/lib/fakeit/openapi/example/array_example.rb +4 -4
- data/lib/fakeit/openapi/example/boolean_example.rb +1 -1
- data/lib/fakeit/openapi/example/integer_example.rb +4 -4
- data/lib/fakeit/openapi/example/number_example.rb +4 -4
- data/lib/fakeit/openapi/example/string_example.rb +24 -22
- data/lib/fakeit/openapi/loader.rb +5 -5
- data/lib/fakeit/openapi/operation.rb +4 -4
- data/lib/fakeit/openapi/schema.rb +11 -11
- data/lib/fakeit/openapi/specification.rb +3 -3
- data/lib/fakeit/validation/validator.rb +4 -4
- data/lib/fakeit/version.rb +1 -1
- data/lib/fakeit.rb +13 -11
- metadata +48 -108
- data/lib/fakeit/core_extensions/reference.rb +0 -9
- data/lib/fakeit/openapi/reference_error.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 387b057ba9e0387d7b3cf46715b966049d3adcc19bbd95fe22778c92cedf19f8
|
4
|
+
data.tar.gz: 16ba2939faacc64769123f2819b19bf25444fcbfcbe7f9a492809b6b473169e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94d467b095d75eb421fa4b0b864a304061257b6abd974b732536b65efabd529d0a46279a49587528856cf9711556864ccd9fbe88af9b2be22c3052d07dffd869
|
7
|
+
data.tar.gz: 7b957a4784e93ff5aa77adb3ca44ade65e36c183cc6a513ddd9d9b943ea671220d011573200f5e1b27475f15783f31ec14f327710574ffaa1b9092a77331086f
|
data/.circleci/config.yml
CHANGED
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 3.
|
2
|
+
TargetRubyVersion: 3.4
|
3
3
|
NewCops: enable
|
4
|
+
SuggestExtensions: false
|
5
|
+
|
6
|
+
Style/Alias:
|
7
|
+
EnforcedStyle: prefer_alias_method
|
4
8
|
|
5
9
|
Style/Documentation:
|
6
10
|
Enabled: false
|
@@ -8,16 +12,37 @@ Style/Documentation:
|
|
8
12
|
Style/FrozenStringLiteralComment:
|
9
13
|
Enabled: false
|
10
14
|
|
15
|
+
Style/RescueStandardError:
|
16
|
+
EnforcedStyle: implicit
|
17
|
+
|
18
|
+
Style/SafeNavigationChainLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/StringLiterals:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/TernaryParentheses:
|
25
|
+
Enabled: false
|
26
|
+
|
11
27
|
Layout/LineLength:
|
12
28
|
Max: 120
|
13
29
|
|
30
|
+
Layout/SpaceInsideHashLiteralBraces:
|
31
|
+
EnforcedStyle: no_space
|
32
|
+
|
14
33
|
Metrics/BlockLength:
|
15
34
|
Exclude:
|
16
|
-
-
|
17
|
-
-
|
35
|
+
- "spec/**/*.rb"
|
36
|
+
- "fakeit.gemspec"
|
18
37
|
|
19
38
|
Security/Open:
|
20
39
|
Enabled: false
|
21
40
|
|
22
41
|
Style/HashTransformKeys:
|
23
42
|
Enabled: false
|
43
|
+
|
44
|
+
Metrics/ParameterLists:
|
45
|
+
CountKeywordArgs: false
|
46
|
+
|
47
|
+
Metrics/MethodLength:
|
48
|
+
Max: 20
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v0.12.0](https://github.com/JustinFeng/fakeit/tree/v0.12.0) (2025-05-13)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.11.0...v0.12.0)
|
6
|
+
|
7
|
+
## [v0.11.0](https://github.com/JustinFeng/fakeit/tree/v0.11.0) (2022-10-09)
|
8
|
+
|
9
|
+
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.10.0...v0.11.0)
|
10
|
+
|
11
|
+
## [v0.10.0](https://github.com/JustinFeng/fakeit/tree/v0.10.0) (2021-11-21)
|
12
|
+
|
13
|
+
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.9.2...v0.10.0)
|
14
|
+
|
15
|
+
**Merged pull requests:**
|
16
|
+
|
17
|
+
- Allows specification of a base path for the mock API [\#26](https://github.com/JustinFeng/fakeit/pull/26) ([jphastings](https://github.com/jphastings))
|
18
|
+
|
3
19
|
## [v0.9.2](https://github.com/JustinFeng/fakeit/tree/v0.9.2) (2021-08-14)
|
4
20
|
|
5
21
|
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.9.1...v0.9.2)
|
@@ -16,7 +32,7 @@
|
|
16
32
|
|
17
33
|
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.9.0...v0.9.1)
|
18
34
|
|
19
|
-
**
|
35
|
+
**Closed issues:**
|
20
36
|
|
21
37
|
- Query parameter array [\#23](https://github.com/JustinFeng/fakeit/issues/23)
|
22
38
|
|
@@ -24,9 +40,9 @@
|
|
24
40
|
|
25
41
|
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.8.1...v0.9.0)
|
26
42
|
|
27
|
-
**
|
43
|
+
**Closed issues:**
|
28
44
|
|
29
|
-
-
|
45
|
+
- camelCase instead of PascalCase [\#22](https://github.com/JustinFeng/fakeit/issues/22)
|
30
46
|
|
31
47
|
## [v0.8.1](https://github.com/JustinFeng/fakeit/tree/v0.8.1) (2021-03-01)
|
32
48
|
|
@@ -40,10 +56,6 @@
|
|
40
56
|
|
41
57
|
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.7.1...v0.8.0)
|
42
58
|
|
43
|
-
**Implemented enhancements:**
|
44
|
-
|
45
|
-
- Upgraded to ruby 3.0.0
|
46
|
-
|
47
59
|
## [v0.7.1](https://github.com/JustinFeng/fakeit/tree/v0.7.1) (2021-02-07)
|
48
60
|
|
49
61
|
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.7.0...v0.7.1)
|
@@ -58,17 +70,12 @@
|
|
58
70
|
|
59
71
|
**Implemented enhancements:**
|
60
72
|
|
61
|
-
-
|
62
|
-
- Allowed to redirect console log to a file
|
73
|
+
- Enhancement: Allow for POSTed data to be persisted while running [\#19](https://github.com/JustinFeng/fakeit/issues/19)
|
63
74
|
|
64
75
|
## [v0.6.3](https://github.com/JustinFeng/fakeit/tree/v0.6.3) (2020-09-11)
|
65
76
|
|
66
77
|
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.6.2...v0.6.3)
|
67
78
|
|
68
|
-
**Implemented enhancements:**
|
69
|
-
|
70
|
-
- Enhanced regex example generation
|
71
|
-
|
72
79
|
## [v0.6.2](https://github.com/JustinFeng/fakeit/tree/v0.6.2) (2020-07-12)
|
73
80
|
|
74
81
|
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.6.1...v0.6.2)
|
@@ -81,10 +88,6 @@
|
|
81
88
|
|
82
89
|
[Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.5.3...v0.6.0)
|
83
90
|
|
84
|
-
**Implemented enhancements:**
|
85
|
-
|
86
|
-
- Added support for multipart/form-data validation
|
87
|
-
|
88
91
|
**Fixed bugs:**
|
89
92
|
|
90
93
|
- Multipart request contain special character will respond 500 [\#16](https://github.com/JustinFeng/fakeit/issues/16)
|
data/Gemfile
CHANGED
@@ -1,4 +1,15 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in fakeit.gemspec
|
4
4
|
gemspec
|
5
|
+
group :development do
|
6
|
+
gem "bundler", "~> 2.6"
|
7
|
+
gem "debug", "~> 1.10"
|
8
|
+
gem "racc", "~> 1.8"
|
9
|
+
gem "rack-test", "~> 2.2"
|
10
|
+
gem "rake", "~> 13.2"
|
11
|
+
gem "rspec", "~> 3.13"
|
12
|
+
gem "rubocop", "~> 1.75"
|
13
|
+
gem "rubocop-rake", "~> 0.7"
|
14
|
+
gem "simplecov", "~> 0.22"
|
15
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,92 +1,134 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fakeit (0.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
fakeit (0.12.0)
|
5
|
+
base64 (~> 0.2.0)
|
6
|
+
faker (= 3.5.1)
|
7
|
+
logger (= 1.7)
|
8
|
+
openapi_parser (= 2.2.6)
|
9
|
+
ostruct (~> 0.6)
|
10
|
+
rack (~> 3.1)
|
11
|
+
rack-cors (~> 2.0)
|
12
|
+
rackup (~> 2.2)
|
13
|
+
rainbow (~> 3.1)
|
14
|
+
regexp-examples (= 1.6.0)
|
15
|
+
slop (~> 4.10)
|
16
|
+
webrick (~> 1.9)
|
13
17
|
|
14
18
|
GEM
|
15
19
|
remote: https://rubygems.org/
|
16
20
|
specs:
|
17
21
|
ast (2.4.2)
|
18
|
-
|
19
|
-
concurrent-ruby (1.1.
|
20
|
-
|
22
|
+
base64 (0.2.0)
|
23
|
+
concurrent-ruby (1.1.10)
|
24
|
+
date (3.4.1)
|
25
|
+
debug (1.10.0)
|
26
|
+
irb (~> 1.10)
|
27
|
+
reline (>= 0.3.8)
|
28
|
+
diff-lcs (1.5.0)
|
21
29
|
docile (1.4.0)
|
22
|
-
faker (
|
23
|
-
i18n (>= 1.
|
24
|
-
i18n (1.
|
30
|
+
faker (3.5.1)
|
31
|
+
i18n (>= 1.8.11, < 2)
|
32
|
+
i18n (1.12.0)
|
25
33
|
concurrent-ruby (~> 1.0)
|
26
|
-
|
27
|
-
|
28
|
-
|
34
|
+
io-console (0.5.11)
|
35
|
+
irb (1.15.2)
|
36
|
+
pp (>= 0.6.0)
|
37
|
+
rdoc (>= 4.0.0)
|
38
|
+
reline (>= 0.4.2)
|
39
|
+
json (2.6.2)
|
40
|
+
language_server-protocol (3.17.0.5)
|
41
|
+
lint_roller (1.1.0)
|
42
|
+
logger (1.7.0)
|
43
|
+
openapi_parser (2.2.6)
|
44
|
+
ostruct (0.6.1)
|
45
|
+
parallel (1.22.1)
|
46
|
+
parser (3.3.8.0)
|
29
47
|
ast (~> 2.4.1)
|
30
|
-
|
31
|
-
|
48
|
+
racc
|
49
|
+
pp (0.6.2)
|
50
|
+
prettyprint
|
51
|
+
prettyprint (0.2.0)
|
52
|
+
prism (1.4.0)
|
53
|
+
psych (5.2.6)
|
54
|
+
date
|
55
|
+
stringio
|
56
|
+
racc (1.8.1)
|
57
|
+
rack (3.1.14)
|
58
|
+
rack-cors (2.0.2)
|
32
59
|
rack (>= 2.0.0)
|
33
|
-
rack-test (
|
34
|
-
rack (>= 1.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
60
|
+
rack-test (2.2.0)
|
61
|
+
rack (>= 1.3)
|
62
|
+
rackup (2.2.1)
|
63
|
+
rack (>= 3)
|
64
|
+
rainbow (3.1.1)
|
65
|
+
rake (13.2.1)
|
66
|
+
rdoc (6.13.1)
|
67
|
+
psych (>= 4.0.0)
|
68
|
+
regexp-examples (1.6.0)
|
69
|
+
regexp_property_values (~> 1.5)
|
70
|
+
regexp_parser (2.10.0)
|
71
|
+
regexp_property_values (1.5.2)
|
72
|
+
reline (0.6.1)
|
73
|
+
io-console (~> 0.5)
|
74
|
+
rspec (3.13.0)
|
75
|
+
rspec-core (~> 3.13.0)
|
76
|
+
rspec-expectations (~> 3.13.0)
|
77
|
+
rspec-mocks (~> 3.13.0)
|
78
|
+
rspec-core (3.13.3)
|
79
|
+
rspec-support (~> 3.13.0)
|
80
|
+
rspec-expectations (3.13.4)
|
47
81
|
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
-
rspec-support (~> 3.
|
49
|
-
rspec-mocks (3.
|
82
|
+
rspec-support (~> 3.13.0)
|
83
|
+
rspec-mocks (3.13.4)
|
50
84
|
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
-
rspec-support (~> 3.
|
52
|
-
rspec-support (3.
|
53
|
-
rubocop (1.
|
85
|
+
rspec-support (~> 3.13.0)
|
86
|
+
rspec-support (3.13.3)
|
87
|
+
rubocop (1.75.5)
|
88
|
+
json (~> 2.3)
|
89
|
+
language_server-protocol (~> 3.17.0.2)
|
90
|
+
lint_roller (~> 1.1.0)
|
54
91
|
parallel (~> 1.10)
|
55
|
-
parser (>= 3.
|
92
|
+
parser (>= 3.3.0.2)
|
56
93
|
rainbow (>= 2.2.2, < 4.0)
|
57
|
-
regexp_parser (>=
|
58
|
-
|
59
|
-
rubocop-ast (>= 1.9.1, < 2.0)
|
94
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
95
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
60
96
|
ruby-progressbar (~> 1.7)
|
61
|
-
unicode-display_width (>=
|
62
|
-
rubocop-ast (1.
|
63
|
-
parser (>= 3.
|
64
|
-
|
65
|
-
|
97
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
98
|
+
rubocop-ast (1.44.1)
|
99
|
+
parser (>= 3.3.7.2)
|
100
|
+
prism (~> 1.4)
|
101
|
+
rubocop-rake (0.7.1)
|
102
|
+
lint_roller (~> 1.1)
|
103
|
+
rubocop (>= 1.72.1)
|
66
104
|
ruby-progressbar (1.11.0)
|
67
|
-
simplecov (0.
|
105
|
+
simplecov (0.22.0)
|
68
106
|
docile (~> 1.1)
|
69
107
|
simplecov-html (~> 0.11)
|
70
108
|
simplecov_json_formatter (~> 0.1)
|
71
109
|
simplecov-html (0.12.3)
|
72
|
-
simplecov_json_formatter (0.1.
|
73
|
-
slop (4.
|
74
|
-
|
75
|
-
|
110
|
+
simplecov_json_formatter (0.1.4)
|
111
|
+
slop (4.10.1)
|
112
|
+
stringio (3.1.7)
|
113
|
+
unicode-display_width (3.1.4)
|
114
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
115
|
+
unicode-emoji (4.0.4)
|
116
|
+
webrick (1.9.1)
|
76
117
|
|
77
118
|
PLATFORMS
|
78
119
|
ruby
|
79
120
|
|
80
121
|
DEPENDENCIES
|
81
|
-
bundler (~> 2.
|
82
|
-
|
122
|
+
bundler (~> 2.6)
|
123
|
+
debug (~> 1.10)
|
83
124
|
fakeit!
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
rubocop
|
89
|
-
|
125
|
+
racc (~> 1.8)
|
126
|
+
rack-test (~> 2.2)
|
127
|
+
rake (~> 13.2)
|
128
|
+
rspec (~> 3.13)
|
129
|
+
rubocop (~> 1.75)
|
130
|
+
rubocop-rake (~> 0.7)
|
131
|
+
simplecov (~> 0.22)
|
90
132
|
|
91
133
|
BUNDLED WITH
|
92
|
-
2.
|
134
|
+
2.6.8
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Fakeit
|
2
2
|
|
3
|
+
[Fukuoka Ruby Award - Special Award](https://www.digitalfukuoka.jp/event_reports/21?locale=ja)
|
4
|
+
|
3
5
|
[](https://circleci.com/gh/JustinFeng/fakeit)
|
4
6
|
[](https://codeclimate.com/github/JustinFeng/fakeit)
|
5
7
|
[](https://rubygems.org/gems/fakeit)
|
@@ -98,7 +100,7 @@ Request and response:
|
|
98
100
|
"static_properties": [
|
99
101
|
"id"
|
100
102
|
],
|
101
|
-
"base_path": "/"
|
103
|
+
"base_path": "/api"
|
102
104
|
}
|
103
105
|
```
|
104
106
|
|
data/Rakefile
CHANGED
data/bin/fakeit
CHANGED
@@ -36,7 +36,7 @@ rescue Slop::Error => e
|
|
36
36
|
exit
|
37
37
|
end
|
38
38
|
|
39
|
-
server =
|
39
|
+
server = Rackup::Handler::WEBrick
|
40
40
|
|
41
41
|
trap(:INT) do
|
42
42
|
if server.respond_to?(:shutdown)
|
@@ -65,6 +65,7 @@ app.use Rack::Cors do
|
|
65
65
|
resource '*', headers: :any, methods: :any
|
66
66
|
end
|
67
67
|
end
|
68
|
+
app.use(Rack::RewindableInput::Middleware)
|
68
69
|
app.use(Fakeit::Middleware::Recorder) unless opts.quiet?
|
69
70
|
|
70
71
|
server.run(app, Port: opts[:port], Host: '0.0.0.0')
|
data/fakeit.gemspec
CHANGED
@@ -1,44 +1,40 @@
|
|
1
|
-
lib = File.expand_path(
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require
|
3
|
+
require "fakeit/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
6
|
+
spec.name = "fakeit"
|
7
|
+
spec.version = Fakeit::VERSION
|
8
|
+
spec.authors = ["Justin Feng"]
|
9
|
+
spec.email = ["realfengjia@foxmail.com"]
|
10
10
|
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
11
|
+
spec.summary = "Create mock server from Openapi specification"
|
12
|
+
spec.description = "Create mock server from Openapi specification"
|
13
|
+
spec.homepage = "https://github.com/JustinFeng/fakeit"
|
14
|
+
spec.license = "MIT"
|
15
15
|
|
16
16
|
# Specify which files should be added to the gem when it is released.
|
17
17
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
-
spec.files
|
18
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
19
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
20
|
end
|
21
|
-
spec.bindir
|
22
|
-
spec.executables
|
23
|
-
spec.require_paths = [
|
21
|
+
spec.bindir = "bin"
|
22
|
+
spec.executables = "fakeit"
|
23
|
+
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
-
spec.required_ruby_version =
|
25
|
+
spec.required_ruby_version = ">= 3.4"
|
26
26
|
|
27
|
-
spec.
|
28
|
-
spec.
|
29
|
-
spec.
|
30
|
-
spec.
|
31
|
-
spec.
|
32
|
-
spec.
|
33
|
-
spec.
|
34
|
-
spec.
|
35
|
-
|
36
|
-
spec.add_dependency
|
37
|
-
spec.add_dependency
|
38
|
-
spec.add_dependency
|
39
|
-
spec.
|
40
|
-
spec.add_dependency 'rainbow', '~> 3.0'
|
41
|
-
spec.add_dependency 'regexp-examples', '1.5.1'
|
42
|
-
spec.add_dependency 'slop', '~> 4.8'
|
43
|
-
spec.add_dependency 'webrick', '~> 1.7'
|
27
|
+
spec.add_dependency "base64", "~> 0.2.0"
|
28
|
+
spec.add_dependency "faker", "3.5.1"
|
29
|
+
spec.add_dependency "logger", "1.7"
|
30
|
+
spec.add_dependency "openapi_parser", "2.2.6"
|
31
|
+
spec.add_dependency "ostruct", "~> 0.6"
|
32
|
+
spec.add_dependency "rack", "~> 3.1"
|
33
|
+
spec.add_dependency "rack-cors", "~> 2.0"
|
34
|
+
spec.add_dependency "rackup", "~> 2.2"
|
35
|
+
spec.add_dependency "rainbow", "~> 3.1"
|
36
|
+
spec.add_dependency "regexp-examples", "1.6.0"
|
37
|
+
spec.add_dependency "slop", "~> 4.10"
|
38
|
+
spec.add_dependency "webrick", "~> 1.9"
|
39
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
44
40
|
end
|
@@ -2,7 +2,6 @@ module Fakeit
|
|
2
2
|
module App
|
3
3
|
class AppBuilder
|
4
4
|
def initialize(spec_file, options)
|
5
|
-
@options = options
|
6
5
|
@config_route = Routes::ConfigRoute.new(options)
|
7
6
|
@openapi_route = Routes::OpenapiRoute.new(spec_file)
|
8
7
|
end
|
@@ -10,25 +9,30 @@ module Fakeit
|
|
10
9
|
def build
|
11
10
|
proc do |env|
|
12
11
|
request = Rack::Request.new(env)
|
12
|
+
base_path = @config_route.options.base_path
|
13
|
+
path_info = request.path_info
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
if path_info == "/__fakeit_config__"
|
16
|
+
config(request)
|
17
|
+
elsif path_info.start_with?(base_path)
|
18
|
+
openapi(request, path_info[(base_path.length - 1)..])
|
19
|
+
elsif "#{path_info}/" == base_path
|
20
|
+
openapi(request, "/")
|
17
21
|
else
|
18
|
-
|
19
|
-
@openapi_route.call(request, @config_route.options)
|
22
|
+
Fakeit::App::Helpers::ResponseBuilder.not_found
|
20
23
|
end
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
24
27
|
private
|
25
28
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
return path unless path.start_with?(@options.base_path)
|
29
|
+
def config(request)
|
30
|
+
@config_route.call(request)
|
31
|
+
end
|
30
32
|
|
31
|
-
|
33
|
+
def openapi(request, path_info)
|
34
|
+
request.path_info = path_info
|
35
|
+
@openapi_route.call(request, @config_route.options)
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -6,11 +6,11 @@ module Fakeit
|
|
6
6
|
def parse(request)
|
7
7
|
case request.media_type
|
8
8
|
when %r{^application/.*json}
|
9
|
-
{
|
10
|
-
when
|
11
|
-
{
|
9
|
+
{media_type: request.media_type, data: parse_json(request.body.read)}
|
10
|
+
when "multipart/form-data"
|
11
|
+
{media_type: request.media_type, data: parse_form_data(request.params)}
|
12
12
|
else
|
13
|
-
{
|
13
|
+
{media_type: request.media_type, data: request.body&.read}
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -18,12 +18,12 @@ module Fakeit
|
|
18
18
|
|
19
19
|
def parse_json(body)
|
20
20
|
body.empty? ? {} : JSON.parse(body)
|
21
|
-
rescue
|
22
|
-
raise Fakeit::Validation::ValidationError,
|
21
|
+
rescue
|
22
|
+
raise Fakeit::Validation::ValidationError, "Invalid json payload"
|
23
23
|
end
|
24
24
|
|
25
25
|
def parse_form_data(params)
|
26
|
-
params.transform_values { |v| v.instance_of?(Hash) && v[:tempfile] ? v[:tempfile].read : 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,15 +3,15 @@ module Fakeit
|
|
3
3
|
module Helpers
|
4
4
|
class ResponseBuilder
|
5
5
|
class << self
|
6
|
-
def error(code, err) = [code, {
|
6
|
+
def error(code, err) = [code, {"Content-Type" => "application/json"}, [{message: err.message}.to_json]]
|
7
7
|
|
8
|
-
def not_found = [404, {}, [
|
8
|
+
def not_found = [404, {}, ["Not Found"]]
|
9
9
|
|
10
|
-
def method_not_allowed = [405, {}, [
|
10
|
+
def method_not_allowed = [405, {}, ["Method Not Allowed"]]
|
11
11
|
|
12
|
-
def unsupported_media_type = [415, {}, [
|
12
|
+
def unsupported_media_type = [415, {}, ["Unsupported Media Type"]]
|
13
13
|
|
14
|
-
def ok(body) = [200, {
|
14
|
+
def ok(body) = [200, {"Content-Type" => "application/json"}, [body.to_json]]
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/fakeit/app/options.rb
CHANGED
@@ -3,7 +3,14 @@ module Fakeit
|
|
3
3
|
class Options
|
4
4
|
attr_reader :permissive, :use_example, :base_path
|
5
5
|
|
6
|
-
def initialize(
|
6
|
+
def initialize(
|
7
|
+
permissive: false,
|
8
|
+
use_example: false,
|
9
|
+
static: false,
|
10
|
+
static_types: [],
|
11
|
+
static_properties: [],
|
12
|
+
base_path: nil
|
13
|
+
)
|
7
14
|
@permissive = permissive
|
8
15
|
@use_example = use_example
|
9
16
|
@static = static
|
@@ -11,7 +18,14 @@ module Fakeit
|
|
11
18
|
@static_properties = static_properties
|
12
19
|
# Standardize the base path to include trailing slash
|
13
20
|
# so that `/base` matches `/base/path` but doesn't match `/basement/path`
|
14
|
-
@base_path =
|
21
|
+
@base_path =
|
22
|
+
if base_path.nil?
|
23
|
+
"/"
|
24
|
+
elsif base_path[-1] == "/"
|
25
|
+
base_path
|
26
|
+
else
|
27
|
+
"#{base_path}/"
|
28
|
+
end
|
15
29
|
end
|
16
30
|
|
17
31
|
def use_static?(type: nil, property: nil)
|
@@ -8,11 +8,11 @@ module Fakeit
|
|
8
8
|
|
9
9
|
def call(request)
|
10
10
|
case [request.request_method, request.media_type]
|
11
|
-
in [
|
11
|
+
in ["GET", _]
|
12
12
|
Fakeit::App::Helpers::ResponseBuilder.ok(@options.to_hash)
|
13
|
-
in [
|
13
|
+
in ["PUT", "application/json"]
|
14
14
|
update(request)
|
15
|
-
in [
|
15
|
+
in ["PUT", _]
|
16
16
|
Fakeit::App::Helpers::ResponseBuilder.unsupported_media_type
|
17
17
|
else
|
18
18
|
Fakeit::App::Helpers::ResponseBuilder.method_not_allowed
|