fakeit 0.8.1 → 0.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b596171f4bdda96b6782f7292abbadee787e56f045d75449792f64c86b370abf
4
- data.tar.gz: f9d429ed7328142a0b7f53e3352d782bf5b096ce449e88ada902b6205b916010
3
+ metadata.gz: 12f260511e656b09583cd6c2d2dba67d5b7f947c3242eca95c7b3cf2cec34c0a
4
+ data.tar.gz: 48625a13975517595721666508dbaa4f151a421ed24bae0e8a6c053e94e995c3
5
5
  SHA512:
6
- metadata.gz: 9ee0a08eae71abb26ee679615022fe3eb363e90233714f0eb34bccca973a1d68dbc16badcd0520456a30fc7e0966df7405bb551e27664c101fea8482ce3d78d6
7
- data.tar.gz: de08d3b1e0f0118c85bc61d8e22d812ac591a439dace0a7dc5279a9801d21a50cdf1f6f8baf6378e35487ac9ba565e30630e949e179ec2e10f8f3092e4df1840
6
+ metadata.gz: 82d5e751a1591754f540d4fad85caffc8d697d4a81cb92a0d0ce000c4571a08613565aef6e43919db5712579162f96b676541129b071acaf95c55c3da4ffb200
7
+ data.tar.gz: f480f86e2f9fda5944ee31996b641f1bc0fb3384cab6df126ce2b238cb3759aeb6b2d53dee7d881239369a2f3d8233b315ad3a6e7a592c8f2eb39509b63cd3d9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.9.2](https://github.com/JustinFeng/fakeit/tree/v0.9.2) (2021-08-14)
4
+
5
+ [Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.9.1...v0.9.2)
6
+
7
+ **Closed issues:**
8
+
9
+ - "Tried to load unspecified class: Date" error is given when spec contains a text that resembles a date [\#25](https://github.com/JustinFeng/fakeit/issues/25)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Bump rexml from 3.2.4 to 3.2.5 [\#24](https://github.com/JustinFeng/fakeit/pull/24) ([dependabot[bot]](https://github.com/apps/dependabot))
14
+
15
+ ## [v0.9.1](https://github.com/JustinFeng/fakeit/tree/v0.9.1) (2021-04-18)
16
+
17
+ [Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.9.0...v0.9.1)
18
+
19
+ **Fixed bugs:**
20
+
21
+ - Query parameter array [\#23](https://github.com/JustinFeng/fakeit/issues/23)
22
+
23
+ ## [v0.9.0](https://github.com/JustinFeng/fakeit/tree/v0.9.0) (2021-03-18)
24
+
25
+ [Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.8.1...v0.9.0)
26
+
27
+ **Implemented enhancements:**
28
+
29
+ - Experimental feature to support plain text and binary response, e.g. application/pdf
30
+
31
+ ## [v0.8.1](https://github.com/JustinFeng/fakeit/tree/v0.8.1) (2021-03-01)
32
+
33
+ [Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.8.0...v0.8.1)
34
+
35
+ **Fixed bugs:**
36
+
37
+ - Cannot load spec file from url [\#21](https://github.com/JustinFeng/fakeit/issues/21)
38
+
3
39
  ## [v0.8.0](https://github.com/JustinFeng/fakeit/tree/v0.8.0) (2021-02-27)
4
40
 
5
41
  [Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.7.1...v0.8.0)
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fakeit (0.8.1)
5
- faker (= 2.13.0)
6
- openapi_parser (= 0.12.1)
4
+ fakeit (0.10.0)
5
+ faker (= 2.18.0)
6
+ openapi_parser (= 0.14.1)
7
7
  rack (~> 2.0)
8
8
  rack-cors (~> 1.0)
9
9
  rainbow (~> 3.0)
@@ -16,16 +16,16 @@ GEM
16
16
  specs:
17
17
  ast (2.4.2)
18
18
  byebug (11.1.3)
19
- concurrent-ruby (1.1.8)
19
+ concurrent-ruby (1.1.9)
20
20
  diff-lcs (1.4.4)
21
- docile (1.3.5)
22
- faker (2.13.0)
21
+ docile (1.4.0)
22
+ faker (2.18.0)
23
23
  i18n (>= 1.6, < 2)
24
- i18n (1.8.9)
24
+ i18n (1.8.11)
25
25
  concurrent-ruby (~> 1.0)
26
- openapi_parser (0.12.1)
26
+ openapi_parser (0.14.1)
27
27
  parallel (1.20.1)
28
- parser (3.0.0.0)
28
+ parser (3.0.2.0)
29
29
  ast (~> 2.4.1)
30
30
  rack (2.2.3)
31
31
  rack-cors (1.1.1)
@@ -33,10 +33,10 @@ GEM
33
33
  rack-test (1.1.0)
34
34
  rack (>= 1.0, < 3)
35
35
  rainbow (3.0.0)
36
- rake (13.0.3)
36
+ rake (13.0.6)
37
37
  regexp-examples (1.5.1)
38
38
  regexp_parser (2.1.1)
39
- rexml (3.2.4)
39
+ rexml (3.2.5)
40
40
  rspec (3.10.0)
41
41
  rspec-core (~> 3.10.0)
42
42
  rspec-expectations (~> 3.10.0)
@@ -50,27 +50,27 @@ GEM
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
51
  rspec-support (~> 3.10.0)
52
52
  rspec-support (3.10.2)
53
- rubocop (1.10.0)
53
+ rubocop (1.19.0)
54
54
  parallel (~> 1.10)
55
55
  parser (>= 3.0.0.0)
56
56
  rainbow (>= 2.2.2, < 4.0)
57
57
  regexp_parser (>= 1.8, < 3.0)
58
58
  rexml
59
- rubocop-ast (>= 1.2.0, < 2.0)
59
+ rubocop-ast (>= 1.9.1, < 2.0)
60
60
  ruby-progressbar (~> 1.7)
61
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
62
+ rubocop-ast (1.10.0)
63
+ parser (>= 3.0.1.1)
64
+ rubocop-rake (0.6.0)
65
+ rubocop (~> 1.0)
66
66
  ruby-progressbar (1.11.0)
67
67
  simplecov (0.21.2)
68
68
  docile (~> 1.1)
69
69
  simplecov-html (~> 0.11)
70
70
  simplecov_json_formatter (~> 0.1)
71
71
  simplecov-html (0.12.3)
72
- simplecov_json_formatter (0.1.2)
73
- slop (4.8.2)
72
+ simplecov_json_formatter (0.1.3)
73
+ slop (4.9.1)
74
74
  unicode-display_width (2.0.0)
75
75
  webrick (1.7.0)
76
76
 
@@ -89,4 +89,4 @@ DEPENDENCIES
89
89
  simplecov (~> 0.18)
90
90
 
91
91
  BUNDLED WITH
92
- 2.2.11
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
 
@@ -61,11 +62,18 @@ Or use the [docker image](https://hub.docker.com/r/realfengjia/fakeit)
61
62
  --static generate static response
62
63
  --static-types generate static value for specified types, e.g. --static-types integer,string
63
64
  --static-properties generate static value for specified properties, e.g. --static-properties id,uuid
65
+ --base-path mounts the mock server at the given path, e.g. --base-path /api
64
66
 
65
67
  other options:
66
68
  -v, --version
67
69
  -h, --help
68
70
 
71
+ **Notes:**
72
+ * See [here](docs/random.md) for Openapi properties supported in random response generation
73
+ * See [here](docs/static.md) for default value in static response generation
74
+ * Regarding `--use-example` mode, property without example specified will still be randomly or statically generated
75
+ * 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.
76
+
69
77
  ### Configuration endpoint
70
78
 
71
79
  Mock server behaviour can be changed on the fly
@@ -89,16 +97,11 @@ Request and response:
89
97
  ],
90
98
  "static_properties": [
91
99
  "id"
92
- ]
100
+ ],
101
+ "base_path": "/"
93
102
  }
94
103
  ```
95
104
 
96
- **Notes:**
97
- * See [here](docs/random.md) for Openapi properties supported in random response generation
98
- * See [here](docs/static.md) for default value in static response generation
99
- * Regarding `--use-example` mode, property without example specified will still be randomly or statically generated
100
- * 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.
101
-
102
105
  ## Development
103
106
 
104
107
  After checking out the repo, run `bundle install` to install dependencies. Then, run `rake` to run the tests.
data/bin/fakeit CHANGED
@@ -16,6 +16,7 @@ begin
16
16
  o.bool '--static', 'generate static response'
17
17
  o.array '--static-types', 'generate static value for specified types, e.g. --static-types integer,string'
18
18
  o.array '--static-properties', 'generate static value for specified properties, e.g. --static-properties id,uuid'
19
+ o.string '--base-path', 'mounts the mock server at the given path, e.g. --base-path /api'
19
20
  o.separator ''
20
21
  o.separator 'other options:'
21
22
  o.on '-v', '--version' do
@@ -50,7 +51,8 @@ options = Fakeit::App::Options.new(
50
51
  use_example: opts.use_example?,
51
52
  static: opts.static?,
52
53
  static_types: opts[:static_types],
53
- static_properties: opts[:static_properties]
54
+ static_properties: opts[:static_properties],
55
+ base_path: opts[:base_path]
54
56
  )
55
57
  app = Fakeit.build(opts[:spec], options)
56
58
 
data/fakeit.gemspec CHANGED
@@ -33,8 +33,8 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'rubocop-rake', '~> 0.5'
34
34
  spec.add_development_dependency 'simplecov', '~> 0.18'
35
35
 
36
- spec.add_dependency 'faker', '2.13.0'
37
- spec.add_dependency 'openapi_parser', '0.12.1'
36
+ spec.add_dependency 'faker', '2.18.0'
37
+ spec.add_dependency 'openapi_parser', '0.14.1'
38
38
  spec.add_dependency 'rack', '~> 2.0'
39
39
  spec.add_dependency 'rack-cors', '~> 1.0'
40
40
  spec.add_dependency 'rainbow', '~> 3.0'
@@ -2,6 +2,7 @@ module Fakeit
2
2
  module App
3
3
  class AppBuilder
4
4
  def initialize(spec_file, options)
5
+ @options = options
5
6
  @config_route = Routes::ConfigRoute.new(options)
6
7
  @openapi_route = Routes::OpenapiRoute.new(spec_file)
7
8
  end
@@ -14,10 +15,21 @@ module Fakeit
14
15
  when '/__fakeit_config__'
15
16
  @config_route.call(request)
16
17
  else
18
+ request.path_info = trim_base_from_path(request.path_info)
17
19
  @openapi_route.call(request, @config_route.options)
18
20
  end
19
21
  end
20
22
  end
23
+
24
+ private
25
+
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)
30
+
31
+ path[@options.base_path.length-1..]
32
+ end
21
33
  end
22
34
  end
23
35
  end
@@ -1,14 +1,17 @@
1
1
  module Fakeit
2
2
  module App
3
3
  class Options
4
- attr_reader :permissive, :use_example
4
+ attr_reader :permissive, :use_example, :base_path
5
5
 
6
- def initialize(permissive: false, use_example: false, static: false, static_types: [], static_properties: [])
6
+ def initialize(permissive: false, use_example: false, static: false, static_types: [], static_properties: [], base_path: "/")
7
7
  @permissive = permissive
8
8
  @use_example = use_example
9
9
  @static = static
10
10
  @static_types = static_types
11
11
  @static_properties = static_properties
12
+ # Standardize the base path to include trailing slash
13
+ # so that `/base` matches `/base/path` but doesn't match `/basement/path`
14
+ @base_path = base_path[-1] == '/' ? base_path : "#{base_path}/"
12
15
  end
13
16
 
14
17
  def use_static?(type: nil, property: nil)
@@ -21,7 +24,8 @@ module Fakeit
21
24
  use_example: @use_example,
22
25
  static: @static,
23
26
  static_types: @static_types,
24
- static_properties: @static_properties
27
+ static_properties: @static_properties,
28
+ base_path: @base_path
25
29
  }
26
30
  end
27
31
  end
@@ -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
@@ -2,22 +2,20 @@ module Fakeit
2
2
  module Openapi
3
3
  class << self
4
4
  def load(src)
5
- parse_method = parse_method(src)
6
-
7
5
  URI
8
6
  .open(src, &:read)
9
- .then(&parse_method)
7
+ .then { parse(src, _1) }
10
8
  .then(&OpenAPIParser.method(:parse))
11
9
  end
12
10
 
13
11
  private
14
12
 
15
- def parse_method(src)
13
+ def parse(src, content)
16
14
  case File.extname(src)
17
15
  when '.json'
18
- JSON.method(:parse)
16
+ JSON.parse(content)
19
17
  when '.yml', '.yaml'
20
- YAML.method(:safe_load)
18
+ YAML.safe_load(content, [Date, Time])
21
19
  else
22
20
  raise 'Invalid openapi specification file'
23
21
  end
@@ -20,7 +20,7 @@ module Fakeit
20
20
  response_schema
21
21
  &.schema
22
22
  &.to_example(example_options)
23
- &.then(&JSON.method(:generate))
23
+ &.then(&method(:serialise))
24
24
  .to_s
25
25
  end
26
26
 
@@ -28,11 +28,15 @@ module Fakeit
28
28
 
29
29
  private
30
30
 
31
+ def serialise(body) = body.is_a?(String) ? body : JSON.generate(body)
32
+
31
33
  def example_options
32
34
  { use_example: @app_options.use_example, use_static: @app_options.method(:use_static?), depth: 0 }
33
35
  end
34
36
 
35
- def response_content = response.last.content&.find { |k, _| k =~ %r{^application/.*json} }
37
+ def response_content
38
+ response.last.content&.find { |k, _| k =~ %r{^application/.*json} || k == 'application/pdf' }
39
+ end
36
40
 
37
41
  def response_schema = response_content&.last
38
42
 
@@ -1,3 +1,3 @@
1
1
  module Fakeit
2
- VERSION = '0.8.1'.freeze
2
+ VERSION = '0.10.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.8.1
4
+ version: 0.10.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-03-01 00:00:00.000000000 Z
11
+ date: 2021-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,28 +128,28 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 2.13.0
131
+ version: 2.18.0
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 2.13.0
138
+ version: 2.18.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: openapi_parser
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 0.12.1
145
+ version: 0.14.1
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
- version: 0.12.1
152
+ version: 0.14.1
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rack
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -263,6 +263,7 @@ files:
263
263
  - lib/fakeit/app/options.rb
264
264
  - lib/fakeit/app/routes/config_route.rb
265
265
  - lib/fakeit/app/routes/openapi_route.rb
266
+ - lib/fakeit/core_extensions/array_validator.rb
266
267
  - lib/fakeit/core_extensions/reference.rb
267
268
  - lib/fakeit/core_extensions/schema.rb
268
269
  - lib/fakeit/logger.rb