fakeit 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12f260511e656b09583cd6c2d2dba67d5b7f947c3242eca95c7b3cf2cec34c0a
4
- data.tar.gz: 48625a13975517595721666508dbaa4f151a421ed24bae0e8a6c053e94e995c3
3
+ metadata.gz: 9ea17f6b5e42fc32d82440e4198d5402d2ba51b02dc36182d50db13d33fea840
4
+ data.tar.gz: '09f5e2290f08d07a71b539b80cff919a37d0be2a8567b315a280c8c6699e07f7'
5
5
  SHA512:
6
- metadata.gz: 82d5e751a1591754f540d4fad85caffc8d697d4a81cb92a0d0ce000c4571a08613565aef6e43919db5712579162f96b676541129b071acaf95c55c3da4ffb200
7
- data.tar.gz: f480f86e2f9fda5944ee31996b641f1bc0fb3384cab6df126ce2b238cb3759aeb6b2d53dee7d881239369a2f3d8233b315ad3a6e7a592c8f2eb39509b63cd3d9
6
+ metadata.gz: c139f4c1654a3e4261b31c7cbed720819e3f9aaa74c54042bb297d4e587412811542c7d8fb35d294a66b0bf27bb0ce0328835ed5b47d61a9c02abc45b7708d4a
7
+ data.tar.gz: cbf4746fbcbfe72714f50af0afcc242f49b6de65056cb7d1edf5058de3a8ed488d9e20314475ae5aefbfc8a4cb132f6d561b52c4a12424700775354d9e15b06b
data/.circleci/config.yml CHANGED
@@ -12,7 +12,7 @@ jobs:
12
12
 
13
13
  docker:
14
14
  # specify the version you desire here
15
- - image: circleci/ruby:3.0.0
15
+ - image: cimg/ruby:3.1.2
16
16
 
17
17
  # Specify service dependencies here if necessary
18
18
  # CircleCI maintains a library of pre-built images
data/.gitignore CHANGED
@@ -10,6 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
 
13
- .byebug_history
14
-
15
13
  .idea
data/.rubocop.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  AllCops:
2
- TargetRubyVersion: 3.0
2
+ TargetRubyVersion: 3.1
3
3
  NewCops: enable
4
+ SuggestExtensions: false
4
5
 
5
6
  Style/Documentation:
6
7
  Enabled: false
@@ -21,3 +22,9 @@ Security/Open:
21
22
 
22
23
  Style/HashTransformKeys:
23
24
  Enabled: false
25
+
26
+ Metrics/ParameterLists:
27
+ CountKeywordArgs: false
28
+
29
+ Metrics/MethodLength:
30
+ Max: 20
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fakeit (0.10.0)
5
- faker (= 2.18.0)
6
- openapi_parser (= 0.14.1)
4
+ fakeit (0.11.0)
5
+ faker (= 2.22.0)
6
+ openapi_parser (= 1.0.0)
7
7
  rack (~> 2.0)
8
8
  rack-cors (~> 1.0)
9
9
  rainbow (~> 3.0)
@@ -15,52 +15,53 @@ GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
17
  ast (2.4.2)
18
- byebug (11.1.3)
19
- concurrent-ruby (1.1.9)
20
- diff-lcs (1.4.4)
18
+ concurrent-ruby (1.1.10)
19
+ diff-lcs (1.5.0)
21
20
  docile (1.4.0)
22
- faker (2.18.0)
23
- i18n (>= 1.6, < 2)
24
- i18n (1.8.11)
21
+ faker (2.22.0)
22
+ i18n (>= 1.8.11, < 2)
23
+ i18n (1.12.0)
25
24
  concurrent-ruby (~> 1.0)
26
- openapi_parser (0.14.1)
27
- parallel (1.20.1)
28
- parser (3.0.2.0)
25
+ json (2.6.2)
26
+ openapi_parser (1.0.0)
27
+ parallel (1.22.1)
28
+ parser (3.1.2.1)
29
29
  ast (~> 2.4.1)
30
- rack (2.2.3)
30
+ rack (2.2.4)
31
31
  rack-cors (1.1.1)
32
32
  rack (>= 2.0.0)
33
- rack-test (1.1.0)
34
- rack (>= 1.0, < 3)
35
- rainbow (3.0.0)
33
+ rack-test (2.0.2)
34
+ rack (>= 1.3)
35
+ rainbow (3.1.1)
36
36
  rake (13.0.6)
37
37
  regexp-examples (1.5.1)
38
- regexp_parser (2.1.1)
38
+ regexp_parser (2.6.0)
39
39
  rexml (3.2.5)
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)
40
+ rspec (3.11.0)
41
+ rspec-core (~> 3.11.0)
42
+ rspec-expectations (~> 3.11.0)
43
+ rspec-mocks (~> 3.11.0)
44
+ rspec-core (3.11.0)
45
+ rspec-support (~> 3.11.0)
46
+ rspec-expectations (3.11.1)
47
47
  diff-lcs (>= 1.2.0, < 2.0)
48
- rspec-support (~> 3.10.0)
49
- rspec-mocks (3.10.2)
48
+ rspec-support (~> 3.11.0)
49
+ rspec-mocks (3.11.1)
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.10.0)
52
- rspec-support (3.10.2)
53
- rubocop (1.19.0)
51
+ rspec-support (~> 3.11.0)
52
+ rspec-support (3.11.1)
53
+ rubocop (1.36.0)
54
+ json (~> 2.3)
54
55
  parallel (~> 1.10)
55
- parser (>= 3.0.0.0)
56
+ parser (>= 3.1.2.1)
56
57
  rainbow (>= 2.2.2, < 4.0)
57
58
  regexp_parser (>= 1.8, < 3.0)
58
- rexml
59
- rubocop-ast (>= 1.9.1, < 2.0)
59
+ rexml (>= 3.2.5, < 4.0)
60
+ rubocop-ast (>= 1.20.1, < 2.0)
60
61
  ruby-progressbar (~> 1.7)
61
62
  unicode-display_width (>= 1.4.0, < 3.0)
62
- rubocop-ast (1.10.0)
63
- parser (>= 3.0.1.1)
63
+ rubocop-ast (1.21.0)
64
+ parser (>= 3.1.1.0)
64
65
  rubocop-rake (0.6.0)
65
66
  rubocop (~> 1.0)
66
67
  ruby-progressbar (1.11.0)
@@ -69,9 +70,9 @@ GEM
69
70
  simplecov-html (~> 0.11)
70
71
  simplecov_json_formatter (~> 0.1)
71
72
  simplecov-html (0.12.3)
72
- simplecov_json_formatter (0.1.3)
73
- slop (4.9.1)
74
- unicode-display_width (2.0.0)
73
+ simplecov_json_formatter (0.1.4)
74
+ slop (4.9.3)
75
+ unicode-display_width (2.3.0)
75
76
  webrick (1.7.0)
76
77
 
77
78
  PLATFORMS
@@ -79,9 +80,8 @@ PLATFORMS
79
80
 
80
81
  DEPENDENCIES
81
82
  bundler (~> 2.0)
82
- byebug (~> 11.0)
83
83
  fakeit!
84
- rack-test (~> 1.1)
84
+ rack-test (~> 2.0)
85
85
  rake (~> 13.0)
86
86
  rspec (~> 3.0)
87
87
  rubocop (~> 1.10)
@@ -89,4 +89,4 @@ DEPENDENCIES
89
89
  simplecov (~> 0.18)
90
90
 
91
91
  BUNDLED WITH
92
- 2.2.15
92
+ 2.3.7
data/README.md CHANGED
@@ -98,7 +98,7 @@ Request and response:
98
98
  "static_properties": [
99
99
  "id"
100
100
  ],
101
- "base_path": "/"
101
+ "base_path": "/api"
102
102
  }
103
103
  ```
104
104
 
data/fakeit.gemspec CHANGED
@@ -22,23 +22,23 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = 'fakeit'
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.required_ruby_version = '>= 3.0.0'
25
+ spec.required_ruby_version = '>= 3.1.2'
26
26
 
27
27
  spec.add_development_dependency 'bundler', '~> 2.0'
28
- spec.add_development_dependency 'byebug', '~> 11.0'
29
- spec.add_development_dependency 'rack-test', '~> 1.1'
28
+ spec.add_development_dependency 'rack-test', '~> 2.0'
30
29
  spec.add_development_dependency 'rake', '~> 13.0'
31
30
  spec.add_development_dependency 'rspec', '~> 3.0'
32
31
  spec.add_development_dependency 'rubocop', '~> 1.10'
33
32
  spec.add_development_dependency 'rubocop-rake', '~> 0.5'
34
33
  spec.add_development_dependency 'simplecov', '~> 0.18'
35
34
 
36
- spec.add_dependency 'faker', '2.18.0'
37
- spec.add_dependency 'openapi_parser', '0.14.1'
35
+ spec.add_dependency 'faker', '2.22.0'
36
+ spec.add_dependency 'openapi_parser', '1.0.0'
38
37
  spec.add_dependency 'rack', '~> 2.0'
39
38
  spec.add_dependency 'rack-cors', '~> 1.0'
40
39
  spec.add_dependency 'rainbow', '~> 3.0'
41
40
  spec.add_dependency 'regexp-examples', '1.5.1'
42
41
  spec.add_dependency 'slop', '~> 4.8'
43
42
  spec.add_dependency 'webrick', '~> 1.7'
43
+ spec.metadata['rubygems_mfa_required'] = 'true'
44
44
  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
- case request.path_info
15
- when '/__fakeit_config__'
16
- @config_route.call(request)
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
- request.path_info = trim_base_from_path(request.path_info)
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 trim_base_from_path(path)
27
- return path if @options.base_path == '/'
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
- path[@options.base_path.length-1..]
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
@@ -3,7 +3,14 @@ module Fakeit
3
3
  class Options
4
4
  attr_reader :permissive, :use_example, :base_path
5
5
 
6
- def initialize(permissive: false, use_example: false, static: false, static_types: [], static_properties: [], base_path: "/")
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 = base_path[-1] == '/' ? base_path : "#{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)
@@ -34,8 +34,7 @@ module Fakeit
34
34
  request
35
35
  .each_header
36
36
  .select { |k, _| k.start_with? 'HTTP_' }
37
- .map { |k, v| [k.sub(/^HTTP_/, '').split('_').map(&:capitalize).join('-'), v] }
38
- .to_h
37
+ .to_h { |k, v| [k.sub(/^HTTP_/, '').split('_').map(&:capitalize).join('-'), v] }
39
38
  end
40
39
 
41
40
  def parse_query(query_string)
@@ -15,7 +15,7 @@ module Fakeit
15
15
  def log_request(env)
16
16
  env['rack.input']
17
17
  &.tap { |body| Logger.info("Request body: #{body.read}") }
18
- &.tap { |body| body.rewind }
18
+ &.tap(&:rewind)
19
19
  end
20
20
 
21
21
  def log_response(response) = Logger.info("Response body: #{response[2].first}")
@@ -41,7 +41,7 @@ module Fakeit
41
41
 
42
42
  def min_array = minItems || 1
43
43
 
44
- def max_array(depth) = maxItems || min_array + (depth > 1 ? 2 : 9)
44
+ def max_array(depth) = maxItems || (min_array + (depth > 1 ? 2 : 9))
45
45
  end
46
46
  end
47
47
  end
@@ -29,7 +29,7 @@ module Fakeit
29
29
  end
30
30
  end
31
31
 
32
- def int_rand_begin = min_int / int_multiple + int_rand_begin_adjust
32
+ def int_rand_begin = (min_int / int_multiple) + int_rand_begin_adjust
33
33
 
34
34
  def int_rand_end = max_int / int_multiple
35
35
 
@@ -49,7 +49,7 @@ module Fakeit
49
49
  if maximum
50
50
  exclusiveMaximum ? maximum - 1 : maximum
51
51
  else
52
- 2**(int_bits - 1) - 1
52
+ (2**(int_bits - 1)) - 1
53
53
  end
54
54
  end
55
55
 
@@ -2,7 +2,7 @@ module Fakeit
2
2
  module Openapi
3
3
  module Example
4
4
  MIN_NUM = -2**31
5
- MAX_NUM = 2**31 - 1
5
+ MAX_NUM = (2**31) - 1
6
6
 
7
7
  def number_example(example_options)
8
8
  if example_options[:use_static][type: 'number', property: example_options[:property]]
@@ -44,7 +44,8 @@ module Fakeit
44
44
  elsif pattern then static_string_pattern
45
45
  elsif format then static_string_format
46
46
  elsif length_constraint then static_string_with_length
47
- else 'string'
47
+ else
48
+ 'string'
48
49
  end
49
50
  end
50
51
  end
@@ -61,7 +62,8 @@ module Fakeit
61
62
  elsif pattern then random_string_pattern
62
63
  elsif format then random_string_format
63
64
  elsif length_constraint then string_with_length
64
- else Faker::Book.title
65
+ else
66
+ Faker::Book.title
65
67
  end
66
68
  end
67
69
 
@@ -81,7 +83,7 @@ module Fakeit
81
83
 
82
84
  def min_string_length = minLength || 0
83
85
 
84
- def max_string_length = maxLength || min_string_length + 10
86
+ def max_string_length = maxLength || (min_string_length + 10)
85
87
 
86
88
  def random_string_format = (RANDOM_FORMAT_HANDLERS[format] || method(:unknown_format))[]
87
89
 
@@ -5,7 +5,7 @@ module Fakeit
5
5
  URI
6
6
  .open(src, &:read)
7
7
  .then { parse(src, _1) }
8
- .then(&OpenAPIParser.method(:parse))
8
+ .then { OpenAPIParser.parse(_1, { strict_reference_validation: true }) }
9
9
  end
10
10
 
11
11
  private
@@ -1,3 +1,3 @@
1
1
  module Fakeit
2
- VERSION = '0.10.0'.freeze
2
+ VERSION = '0.11.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.10.0
4
+ version: 0.11.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-11-21 00:00:00.000000000 Z
11
+ date: 2022-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,34 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
- - !ruby/object:Gem::Dependency
28
- name: byebug
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '11.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '11.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rack-test
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '1.1'
33
+ version: '2.0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '1.1'
40
+ version: '2.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rake
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -128,28 +114,28 @@ dependencies:
128
114
  requirements:
129
115
  - - '='
130
116
  - !ruby/object:Gem::Version
131
- version: 2.18.0
117
+ version: 2.22.0
132
118
  type: :runtime
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - '='
137
123
  - !ruby/object:Gem::Version
138
- version: 2.18.0
124
+ version: 2.22.0
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: openapi_parser
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
129
  - - '='
144
130
  - !ruby/object:Gem::Version
145
- version: 0.14.1
131
+ version: 1.0.0
146
132
  type: :runtime
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
136
  - - '='
151
137
  - !ruby/object:Gem::Version
152
- version: 0.14.1
138
+ version: 1.0.0
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: rack
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -264,7 +250,6 @@ files:
264
250
  - lib/fakeit/app/routes/config_route.rb
265
251
  - lib/fakeit/app/routes/openapi_route.rb
266
252
  - lib/fakeit/core_extensions/array_validator.rb
267
- - lib/fakeit/core_extensions/reference.rb
268
253
  - lib/fakeit/core_extensions/schema.rb
269
254
  - lib/fakeit/logger.rb
270
255
  - lib/fakeit/middleware/recorder.rb
@@ -276,7 +261,6 @@ files:
276
261
  - lib/fakeit/openapi/example/string_example.rb
277
262
  - lib/fakeit/openapi/loader.rb
278
263
  - lib/fakeit/openapi/operation.rb
279
- - lib/fakeit/openapi/reference_error.rb
280
264
  - lib/fakeit/openapi/schema.rb
281
265
  - lib/fakeit/openapi/specification.rb
282
266
  - lib/fakeit/validation/validation_error.rb
@@ -285,7 +269,8 @@ files:
285
269
  homepage: https://github.com/JustinFeng/fakeit
286
270
  licenses:
287
271
  - MIT
288
- metadata: {}
272
+ metadata:
273
+ rubygems_mfa_required: 'true'
289
274
  post_install_message:
290
275
  rdoc_options: []
291
276
  require_paths:
@@ -294,14 +279,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
294
279
  requirements:
295
280
  - - ">="
296
281
  - !ruby/object:Gem::Version
297
- version: 3.0.0
282
+ version: 3.1.2
298
283
  required_rubygems_version: !ruby/object:Gem::Requirement
299
284
  requirements:
300
285
  - - ">="
301
286
  - !ruby/object:Gem::Version
302
287
  version: '0'
303
288
  requirements: []
304
- rubygems_version: 3.2.3
289
+ rubygems_version: 3.3.7
305
290
  signing_key:
306
291
  specification_version: 4
307
292
  summary: Create mock server from Openapi specification
@@ -1,9 +0,0 @@
1
- require 'fakeit/openapi/schema'
2
-
3
- module OpenAPIParser
4
- module Schemas
5
- class Reference
6
- def to_example(_) = raise(Fakeit::Openapi::ReferenceError, "Invalid $ref at \"#{ref}\"")
7
- end
8
- end
9
- end
@@ -1,6 +0,0 @@
1
- module Fakeit
2
- module Openapi
3
- class ReferenceError < StandardError
4
- end
5
- end
6
- end