fakeit 0.1.3 → 0.1.4
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/README.md +3 -0
- data/lib/fakeit/core_extensions/findable.rb +12 -0
- data/lib/fakeit/openapi/example/array_example.rb +5 -11
- data/lib/fakeit/openapi/example/string_example.rb +6 -1
- data/lib/fakeit/openapi/operation.rb +1 -1
- 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: 344bca7970fbe31a7642706c26b1d1560089042cc5f85096a997b1b5b61ab602
|
4
|
+
data.tar.gz: 825a8206331071f7f6d6dfd221f8c7c6a751d07e5df27992d75b6678cf164d8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 377bbe9ba6b54822f8be4c46364cf91acd29c86c3f28024bdf4912dc3afb1b4b31530b8fa3322cebc667d2799cbf4ed78c0dc8fb3804346db04e2b8a95148051
|
7
|
+
data.tar.gz: 3eb452a5580253f94d0d7197d65e38e65d60632ec75d86e4add2ea974334fc08db46a5520d4f318c71459496e0f5c4c7dbf04c1993d7192ff86fbd8857a6ea38
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -44,6 +44,9 @@ Command line options:
|
|
44
44
|
-v, --version
|
45
45
|
-h, --help
|
46
46
|
|
47
|
+
**Notes:**
|
48
|
+
* 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.
|
49
|
+
|
47
50
|
## Development
|
48
51
|
|
49
52
|
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake` to run the tests.
|
@@ -1,31 +1,25 @@
|
|
1
1
|
module Fakeit
|
2
2
|
module Openapi
|
3
3
|
module Example
|
4
|
-
MAX_SIZE =
|
4
|
+
MAX_SIZE = 3
|
5
5
|
|
6
6
|
def array_example(use_example)
|
7
7
|
size = retries = uniqueItems ? min_array : Faker::Number.between(min_array, max_array)
|
8
|
-
|
9
|
-
generate_items(size, retries, use_example)
|
8
|
+
[].tap { |result| generate_items(size, retries, use_example, result) }
|
10
9
|
end
|
11
10
|
|
12
11
|
private
|
13
12
|
|
14
|
-
def generate_items(size, retries, use_example)
|
15
|
-
result = []
|
16
|
-
|
13
|
+
def generate_items(size, retries, use_example, result)
|
17
14
|
loop do
|
18
15
|
item = items.to_example(use_example)
|
19
16
|
|
20
17
|
if need_retry?(item, result, retries)
|
21
18
|
retries -= 1
|
22
|
-
|
19
|
+
elsif (result << item).size >= size
|
20
|
+
break
|
23
21
|
end
|
24
|
-
|
25
|
-
break if (result << item).size >= size
|
26
22
|
end
|
27
|
-
|
28
|
-
result
|
29
23
|
end
|
30
24
|
|
31
25
|
def need_retry?(item, result, retries)
|
@@ -4,6 +4,7 @@ module Fakeit
|
|
4
4
|
FORMAT_HANDLERS = {
|
5
5
|
'uri' => -> { Faker::Internet.url },
|
6
6
|
'uuid' => -> { SecureRandom.uuid },
|
7
|
+
'guid' => -> { SecureRandom.uuid },
|
7
8
|
'email' => -> { Faker::Internet.email },
|
8
9
|
'date' => -> { Faker::Date.backward(100).iso8601 },
|
9
10
|
'date-time' => -> { Faker::Time.backward(100).iso8601 }
|
@@ -13,13 +14,17 @@ module Fakeit
|
|
13
14
|
if enum then enum.to_a.sample
|
14
15
|
elsif pattern then Faker::Base.regexify(pattern)
|
15
16
|
elsif format then string_format
|
16
|
-
elsif
|
17
|
+
elsif length_constraint then string_with_length
|
17
18
|
else Faker::Book.title
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
private
|
22
23
|
|
24
|
+
def length_constraint
|
25
|
+
minLength || maxLength
|
26
|
+
end
|
27
|
+
|
23
28
|
def string_with_length
|
24
29
|
Faker::Internet.user_name(min_string_length..max_string_length)
|
25
30
|
end
|
@@ -14,8 +14,8 @@ module Fakeit
|
|
14
14
|
def headers
|
15
15
|
response_headers
|
16
16
|
&.map { |k, v| [k, v.schema.to_example(@options.use_example)] }
|
17
|
-
&.tap { |headers| headers.push(['Content-Type', response_content_type]) if response_content_type }
|
18
17
|
.to_h
|
18
|
+
.tap { |headers| headers['Content-Type'] = response_content_type if response_content_type }
|
19
19
|
end
|
20
20
|
|
21
21
|
def 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.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Feng
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -186,6 +186,7 @@ files:
|
|
186
186
|
- lib/fakeit.rb
|
187
187
|
- lib/fakeit/app/app.rb
|
188
188
|
- lib/fakeit/app/options.rb
|
189
|
+
- lib/fakeit/core_extensions/findable.rb
|
189
190
|
- lib/fakeit/core_extensions/schema.rb
|
190
191
|
- lib/fakeit/logger.rb
|
191
192
|
- lib/fakeit/middleware/recorder.rb
|