fakeit 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/docs/static.md +1 -0
- data/lib/fakeit/app/app.rb +1 -1
- data/lib/fakeit/app/body_parser.rb +30 -0
- data/lib/fakeit/openapi/example/array_example.rb +8 -4
- data/lib/fakeit/validation/validator.rb +15 -11
- data/lib/fakeit/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08e498097efdfb3a803d5fcafc2f755b37f74ade0b0d409ba9ea36cd0ffbc0fd'
|
4
|
+
data.tar.gz: 77abcf6e9aa8db912d6b6a158a2cc8a95bbced90311617692e1f67f99e1d7249
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cce0c415a9e2fb40b9b55178dd9b85b8b8f643453ab3e3d4a2203269af0ca7650adca35b464c30f7e82c3b29e8f2319ff1a8543ee8f3d0f793dfa28945f038f5
|
7
|
+
data.tar.gz: ac9ca06debd2181ee4332edbd30e7a3413f1cf4caeec7981340c6189258615411928364836601b8772be3d8efa87dd72e69e18870b8bd1e0c5dbcf3eb5ee821c
|
data/Gemfile.lock
CHANGED
data/docs/static.md
CHANGED
data/lib/fakeit/app/app.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
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
|
+
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
|
@@ -18,17 +18,17 @@ module Fakeit
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def random_array_size(example_options)
|
21
|
-
uniqueItems ?
|
21
|
+
uniqueItems ? unique_array_size : Faker::Number.between(from: min_array, to: max_array(example_options[:depth]))
|
22
22
|
end
|
23
23
|
|
24
24
|
def generate_items(size, retries, example_options, result)
|
25
|
-
|
25
|
+
while result.size < size
|
26
26
|
item = items.to_example(example_options)
|
27
27
|
|
28
28
|
if need_retry?(item, result, retries)
|
29
29
|
retries -= 1
|
30
|
-
|
31
|
-
|
30
|
+
else
|
31
|
+
result << item
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -41,6 +41,10 @@ module Fakeit
|
|
41
41
|
uniqueItems && result.include?(item) && retries.positive?
|
42
42
|
end
|
43
43
|
|
44
|
+
def unique_array_size
|
45
|
+
[min_array, 1].max
|
46
|
+
end
|
47
|
+
|
44
48
|
def min_array
|
45
49
|
minItems || 1
|
46
50
|
end
|
@@ -5,13 +5,10 @@ module Fakeit
|
|
5
5
|
@operation = operation
|
6
6
|
end
|
7
7
|
|
8
|
-
def validate(body:
|
8
|
+
def validate(body: {}, params: {}, headers: {})
|
9
9
|
options = OpenAPIParser::SchemaValidator::Options.new(coerce_value: true)
|
10
10
|
|
11
|
-
|
12
|
-
body_data = parse(body)
|
13
|
-
@operation.validate_request_body(request_content_type, body_data)
|
14
|
-
end
|
11
|
+
validate_body(body) unless request_content_types.empty?
|
15
12
|
@operation.validate_path_params(options)
|
16
13
|
@operation.validate_request_parameter(params, headers, options)
|
17
14
|
rescue StandardError => e
|
@@ -20,14 +17,21 @@ module Fakeit
|
|
20
17
|
|
21
18
|
private
|
22
19
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
def validate_body(body)
|
21
|
+
if request_content_types.include?(body[:media_type])
|
22
|
+
@operation.validate_request_body(body[:media_type], body[:data]) if can_validate?(body[:media_type])
|
23
|
+
else
|
24
|
+
raise ValidationError, 'Invalid request content type' if body[:media_type]
|
25
|
+
raise ValidationError, 'Request body is required' if request_body.required
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def can_validate?(media_type)
|
30
|
+
media_type =~ %r{^application/.*json} || media_type == 'multipart/form-data'
|
27
31
|
end
|
28
32
|
|
29
|
-
def
|
30
|
-
request_body&.content&.
|
33
|
+
def request_content_types
|
34
|
+
request_body&.content&.keys.to_a
|
31
35
|
end
|
32
36
|
|
33
37
|
def request_body
|
data/lib/fakeit/version.rb
CHANGED
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.
|
4
|
+
version: 0.6.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: 2020-
|
11
|
+
date: 2020-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- fakeit.gemspec
|
216
216
|
- lib/fakeit.rb
|
217
217
|
- lib/fakeit/app/app.rb
|
218
|
+
- lib/fakeit/app/body_parser.rb
|
218
219
|
- lib/fakeit/app/options.rb
|
219
220
|
- lib/fakeit/core_extensions/findable.rb
|
220
221
|
- lib/fakeit/core_extensions/path_item_finder.rb
|