fakeit 0.6.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ module Fakeit
2
+ module Openapi
3
+ class ReferenceError < StandardError
4
+ end
5
+ end
6
+ end
@@ -25,7 +25,7 @@ module Fakeit
25
25
  @mtime = new_mtime
26
26
  @doc = Fakeit::Openapi.load(@spec_file)
27
27
  rescue StandardError => _e
28
- Fakeit::Logger.warn(Rainbow('Invalid spec file, use previous snapshot instead').red)
28
+ Logger.warn(Rainbow('Invalid spec file, use previous snapshot instead').red)
29
29
  end
30
30
  end
31
31
  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
@@ -1,3 +1,3 @@
1
1
  module Fakeit
2
- VERSION = '0.6.1'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
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.6.1
4
+ version: 0.8.0
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: 2020-05-02 00:00:00.000000000 Z
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: '12.0'
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: '12.0'
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: '0.80'
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: '0.80'
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
@@ -114,28 +128,28 @@ dependencies:
114
128
  requirements:
115
129
  - - '='
116
130
  - !ruby/object:Gem::Version
117
- version: 2.11.0
131
+ version: 2.13.0
118
132
  type: :runtime
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - '='
123
137
  - !ruby/object:Gem::Version
124
- version: 2.11.0
138
+ version: 2.13.0
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: openapi_parser
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - '='
130
144
  - !ruby/object:Gem::Version
131
- version: 0.8.0
145
+ version: 0.12.1
132
146
  type: :runtime
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - '='
137
151
  - !ruby/object:Gem::Version
138
- version: 0.8.0
152
+ version: 0.12.1
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rack
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +192,20 @@ dependencies:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
194
  version: '3.0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: regexp-examples
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '='
200
+ - !ruby/object:Gem::Version
201
+ version: 1.5.1
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - '='
207
+ - !ruby/object:Gem::Version
208
+ version: 1.5.1
181
209
  - !ruby/object:Gem::Dependency
182
210
  name: slop
183
211
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +220,20 @@ dependencies:
192
220
  - - "~>"
193
221
  - !ruby/object:Gem::Version
194
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'
195
237
  description: Create mock server from Openapi specification
196
238
  email:
197
239
  - realfengjia@foxmail.com
@@ -204,6 +246,7 @@ files:
204
246
  - ".gitignore"
205
247
  - ".rspec"
206
248
  - ".rubocop.yml"
249
+ - CHANGELOG.md
207
250
  - Gemfile
208
251
  - Gemfile.lock
209
252
  - LICENSE.txt
@@ -214,11 +257,13 @@ files:
214
257
  - docs/static.md
215
258
  - fakeit.gemspec
216
259
  - lib/fakeit.rb
217
- - lib/fakeit/app/app.rb
218
- - lib/fakeit/app/body_parser.rb
260
+ - lib/fakeit/app/app_builder.rb
261
+ - lib/fakeit/app/helpers/body_parser.rb
262
+ - lib/fakeit/app/helpers/response_builder.rb
219
263
  - lib/fakeit/app/options.rb
220
- - lib/fakeit/core_extensions/findable.rb
221
- - lib/fakeit/core_extensions/path_item_finder.rb
264
+ - lib/fakeit/app/routes/config_route.rb
265
+ - lib/fakeit/app/routes/openapi_route.rb
266
+ - lib/fakeit/core_extensions/reference.rb
222
267
  - lib/fakeit/core_extensions/schema.rb
223
268
  - lib/fakeit/logger.rb
224
269
  - lib/fakeit/middleware/recorder.rb
@@ -230,6 +275,7 @@ files:
230
275
  - lib/fakeit/openapi/example/string_example.rb
231
276
  - lib/fakeit/openapi/loader.rb
232
277
  - lib/fakeit/openapi/operation.rb
278
+ - lib/fakeit/openapi/reference_error.rb
233
279
  - lib/fakeit/openapi/schema.rb
234
280
  - lib/fakeit/openapi/specification.rb
235
281
  - lib/fakeit/validation/validation_error.rb
@@ -239,7 +285,7 @@ homepage: https://github.com/JustinFeng/fakeit
239
285
  licenses:
240
286
  - MIT
241
287
  metadata: {}
242
- post_install_message:
288
+ post_install_message:
243
289
  rdoc_options: []
244
290
  require_paths:
245
291
  - lib
@@ -247,15 +293,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
247
293
  requirements:
248
294
  - - ">="
249
295
  - !ruby/object:Gem::Version
250
- version: 2.7.0
296
+ version: 3.0.0
251
297
  required_rubygems_version: !ruby/object:Gem::Requirement
252
298
  requirements:
253
299
  - - ">="
254
300
  - !ruby/object:Gem::Version
255
301
  version: '0'
256
302
  requirements: []
257
- rubygems_version: 3.1.2
258
- signing_key:
303
+ rubygems_version: 3.2.3
304
+ signing_key:
259
305
  specification_version: 4
260
306
  summary: Create mock server from Openapi specification
261
307
  test_files: []
@@ -1,63 +0,0 @@
1
- module Fakeit
2
- module App
3
- class << self
4
- def create(spec_file, options)
5
- specification = Fakeit::Openapi::Specification.new(spec_file)
6
-
7
- proc do |env|
8
- request = Rack::Request.new(env)
9
- specification
10
- .operation(request.request_method.downcase.to_sym, request.path_info, options)
11
- .then { _1 ? handle(_1, request, options) : not_found }
12
- end
13
- end
14
-
15
- private
16
-
17
- def handle(operation, request, options)
18
- validate(operation, request)
19
- response(operation)
20
- rescue Fakeit::Validation::ValidationError => e
21
- Fakeit::Logger.warn(Rainbow(e.message).red)
22
- options.permissive ? response(operation) : error(e)
23
- end
24
-
25
- def error(err)
26
- [418, { 'Content-Type' => 'application/json' }, [{ message: err.message }.to_json]]
27
- end
28
-
29
- def not_found
30
- [404, {}, ['Not Found']]
31
- end
32
-
33
- def response(operation)
34
- [operation.status, operation.headers, [operation.body]]
35
- end
36
-
37
- def validate(operation, request)
38
- operation.validate(
39
- body: BodyParser.parse(request),
40
- params: parse_query(request.query_string),
41
- headers: headers(request)
42
- )
43
- end
44
-
45
- def headers(request)
46
- request
47
- .each_header
48
- .select { |k, _| k.start_with? 'HTTP_' }
49
- .map { |k, v| [k.sub(/^HTTP_/, '').split('_').map(&:capitalize).join('-'), v] }
50
- .to_h
51
- end
52
-
53
- def parse_query(query_string)
54
- rack_query = Rack::Utils.parse_nested_query(query_string)
55
- cgi_query = CGI.parse(query_string)
56
-
57
- rack_query.merge(cgi_query.slice(*rack_query.keys)) do |_, oldval, newval|
58
- newval.is_a?(Array) && newval.size > 1 ? newval : oldval
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,30 +0,0 @@
1
- module Fakeit
2
- module App
3
- class BodyParser
4
- class << self
5
- def parse(request)
6
- case request.media_type
7
- when %r{^application/.*json}
8
- { media_type: request.media_type, data: parse_json(request.body.read) }
9
- when 'multipart/form-data'
10
- { media_type: request.media_type, data: parse_form_data(request.params) }
11
- else
12
- { media_type: request.media_type, data: request.body.read }
13
- end
14
- end
15
-
16
- private
17
-
18
- def parse_json(body)
19
- body.empty? ? {} : JSON.parse(body)
20
- rescue StandardError
21
- raise Fakeit::Validation::ValidationError, 'Invalid json payload'
22
- end
23
-
24
- def parse_form_data(params)
25
- params.transform_values { |v| v.class == Hash && v[:tempfile] ? v[:tempfile].read : v }
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,13 +0,0 @@
1
- # https://github.com/ota42y/openapi_parser/issues/41
2
- module OpenAPIParser
3
- module Findable
4
- def purge_object_cache
5
- return if @purged
6
-
7
- @find_object_cache = {}
8
- @purged = true
9
-
10
- _openapi_all_child_objects.values.each(&:purge_object_cache)
11
- end
12
- end
13
- end
@@ -1,14 +0,0 @@
1
- # https://github.com/ota42y/openapi_parser/issues/75
2
- module OpenAPIParser
3
- class PathItemFinder
4
- private
5
-
6
- def find_path_and_params(http_method, request_path)
7
- return [request_path, {}] if matches_directly?(request_path, http_method)
8
-
9
- matching = matching_paths_with_params(request_path, http_method)
10
-
11
- matching.min_by { |match| match[1].size }
12
- end
13
- end
14
- end