fakeit 0.8.0 → 0.9.2

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: 285f5035e5fbd29cc124715beb4a901f63641eace09deda6b42a520222bc706c
4
- data.tar.gz: 4dcacbd9adbfabdb80e265e740829afc920e9653563c047206197f39716336e6
3
+ metadata.gz: b6a7f204912168334397f27d77e2c94a8b29a748b19c2e2e6d5b8aff656c1c88
4
+ data.tar.gz: 35140a1ac79a93701b7b9047aa641e4ae3eeca482ada20889d5a8eb2c26354e9
5
5
  SHA512:
6
- metadata.gz: 8b07445c0ddc4b8d21918b0ee6ede3108d1fcd01ff0babe8ae8aed1cc3686f4953d7ee0486247dd6f77195abafcd1a1584c44fe0a2e7030f24fba476883f256f
7
- data.tar.gz: ecf3f4325a81c3ca550ff08f4738385ae9ae3d4de46bd32262dc58d303ac40f80ecd505ef29b411e59c25f360ca38c3f09c7839e75e538c33828d86b5872bef2
6
+ metadata.gz: 46497c7741b4e7e411260492b3c3d452ff0dbcd6ecce1177e7290646f945b5bb2f6bf19f21d80b3bcac4197623bb605be6f99d61223f25c1ff73bf0da69bd8e0
7
+ data.tar.gz: 14730bd843f9c48a0544435d48f297f8403b553a85a80eb7b882bdc41f92977a94f33205d8d8b5bb3ed35a8282edda6f5dbbe0efcd7a62fb7eee52d6b2ad4200
data/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.9.1](https://github.com/JustinFeng/fakeit/tree/v0.9.1) (2021-04-18)
4
+
5
+ [Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.9.0...v0.9.1)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - Query parameter array [\#23](https://github.com/JustinFeng/fakeit/issues/23)
10
+
11
+ ## [v0.9.0](https://github.com/JustinFeng/fakeit/tree/v0.9.0) (2021-03-18)
12
+
13
+ [Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.8.1...v0.9.0)
14
+
15
+ **Implemented enhancements:**
16
+
17
+ - Experimental feature to support plain text and binary response, e.g. application/pdf
18
+
19
+ ## [v0.8.1](https://github.com/JustinFeng/fakeit/tree/v0.8.1) (2021-03-01)
20
+
21
+ [Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.8.0...v0.8.1)
22
+
23
+ **Fixed bugs:**
24
+
25
+ - Cannot load spec file from url [\#21](https://github.com/JustinFeng/fakeit/issues/21)
26
+
27
+ ## [v0.8.0](https://github.com/JustinFeng/fakeit/tree/v0.8.0) (2021-02-27)
28
+
29
+ [Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.7.1...v0.8.0)
30
+
31
+ **Implemented enhancements:**
32
+
33
+ - Upgraded to ruby 3.0.0
34
+
3
35
  ## [v0.7.1](https://github.com/JustinFeng/fakeit/tree/v0.7.1) (2021-02-07)
4
36
 
5
37
  [Full Changelog](https://github.com/JustinFeng/fakeit/compare/v0.7.0...v0.7.1)
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fakeit (0.8.0)
5
- faker (= 2.13.0)
6
- openapi_parser (= 0.12.1)
4
+ fakeit (0.9.2)
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.10)
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
 
@@ -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
@@ -93,12 +100,6 @@ Request and response:
93
100
  }
94
101
  ```
95
102
 
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
103
  ## Development
103
104
 
104
105
  After checking out the repo, run `bundle install` to install dependencies. Then, run `rake` to run the tests.
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'
@@ -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,21 +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
- open(src, &:read)
8
- .then(&parse_method)
5
+ URI
6
+ .open(src, &:read)
7
+ .then { parse(src, _1) }
9
8
  .then(&OpenAPIParser.method(:parse))
10
9
  end
11
10
 
12
11
  private
13
12
 
14
- def parse_method(src)
13
+ def parse(src, content)
15
14
  case File.extname(src)
16
15
  when '.json'
17
- JSON.method(:parse)
16
+ JSON.parse(content)
18
17
  when '.yml', '.yaml'
19
- YAML.method(:safe_load)
18
+ YAML.safe_load(content, [Date, Time])
20
19
  else
21
20
  raise 'Invalid openapi specification file'
22
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.0'.freeze
2
+ VERSION = '0.9.2'.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.0
4
+ version: 0.9.2
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-02-27 00:00:00.000000000 Z
11
+ date: 2021-08-14 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