fakeit 0.1.4 → 0.1.5

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: 344bca7970fbe31a7642706c26b1d1560089042cc5f85096a997b1b5b61ab602
4
- data.tar.gz: 825a8206331071f7f6d6dfd221f8c7c6a751d07e5df27992d75b6678cf164d8b
3
+ metadata.gz: 54c041ed8f46946a8641f52ae6397b00a5620cf53f813195df6694a1f36c2904
4
+ data.tar.gz: 71d218c8c8aee2d0a9240785e43949a3fd9b3210f6ce817ba6dc224ccbffddd8
5
5
  SHA512:
6
- metadata.gz: 377bbe9ba6b54822f8be4c46364cf91acd29c86c3f28024bdf4912dc3afb1b4b31530b8fa3322cebc667d2799cbf4ed78c0dc8fb3804346db04e2b8a95148051
7
- data.tar.gz: 3eb452a5580253f94d0d7197d65e38e65d60632ec75d86e4add2ea974334fc08db46a5520d4f318c71459496e0f5c4c7dbf04c1993d7192ff86fbd8857a6ea38
6
+ metadata.gz: 88fdba5349cfc8f664bf321030c3e2de2446b2f677a249f5801ed00d8b37ca5291c8b5e59670c4bc5e1bb67327ef43a64f22b2fc22105f50e503b41c6d76724e
7
+ data.tar.gz: 3edc63857c5447b41b8a1e6e8ebeef84ac676216ad0d27531905bcaded11b69da2b468828475d7db43674ac6708d8af800b53e5796f311a281043050b6c1020b
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fakeit (0.1.4)
4
+ fakeit (0.1.5)
5
5
  faker (~> 1.9)
6
6
  openapi_parser (= 0.3.0)
7
7
  rack (~> 2.0)
8
+ rack-cors (~> 1.0)
8
9
  slop (~> 4.6)
9
10
 
10
11
  GEM
@@ -15,8 +16,14 @@ GEM
15
16
  concurrent-ruby (1.1.5)
16
17
  diff-lcs (1.3)
17
18
  docile (1.3.1)
18
- faker (1.9.3)
19
+ equatable (0.6.1)
20
+ faker (1.9.4)
19
21
  i18n (>= 0.7)
22
+ pastel (~> 0.7.2)
23
+ thor (~> 0.20.0)
24
+ tty-pager (~> 0.12.0)
25
+ tty-screen (~> 0.6.5)
26
+ tty-tree (~> 0.3.0)
20
27
  i18n (1.6.0)
21
28
  concurrent-ruby (~> 1.0)
22
29
  jaro_winkler (1.5.2)
@@ -25,8 +32,12 @@ GEM
25
32
  parallel (1.17.0)
26
33
  parser (2.6.2.1)
27
34
  ast (~> 2.4.0)
35
+ pastel (0.7.3)
36
+ equatable (~> 0.6)
37
+ tty-color (~> 0.5)
28
38
  psych (3.1.0)
29
39
  rack (2.0.7)
40
+ rack-cors (1.0.3)
30
41
  rack-test (1.1.0)
31
42
  rack (>= 1.0, < 3)
32
43
  rainbow (3.0.0)
@@ -59,7 +70,22 @@ GEM
59
70
  simplecov-html (~> 0.10.0)
60
71
  simplecov-html (0.10.2)
61
72
  slop (4.6.2)
73
+ strings (0.1.5)
74
+ strings-ansi (~> 0.1)
75
+ unicode-display_width (~> 1.5)
76
+ unicode_utils (~> 1.4)
77
+ strings-ansi (0.1.0)
78
+ thor (0.20.3)
79
+ tty-color (0.5.0)
80
+ tty-pager (0.12.1)
81
+ strings (~> 0.1.4)
82
+ tty-screen (~> 0.6)
83
+ tty-which (~> 0.4)
84
+ tty-screen (0.6.5)
85
+ tty-tree (0.3.0)
86
+ tty-which (0.4.1)
62
87
  unicode-display_width (1.5.0)
88
+ unicode_utils (1.4.0)
63
89
 
64
90
  PLATFORMS
65
91
  ruby
@@ -75,4 +101,4 @@ DEPENDENCIES
75
101
  simplecov (~> 0.16)
76
102
 
77
103
  BUNDLED WITH
78
- 2.0.1
104
+ 2.0.2
data/bin/fakeit CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'slop'
4
4
  require 'fakeit'
5
+ require 'rack/cors'
5
6
 
6
7
  usage = nil
7
8
  begin
@@ -42,5 +43,13 @@ end
42
43
 
43
44
  options = Fakeit::App::Options.new(permissive: opts.permissive?, use_example: opts.use_example?)
44
45
  app = Fakeit.build(opts[:spec], options)
46
+
47
+ app.use Rack::Cors do
48
+ allow do
49
+ origins '*'
50
+ resource '*', headers: :any, methods: :any
51
+ end
52
+ end
45
53
  app.use(Fakeit::Middleware::Recorder) unless opts.quiet?
54
+
46
55
  server.run(app, Port: opts[:port], Host: '0.0.0.0')
data/fakeit.gemspec CHANGED
@@ -35,5 +35,6 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency 'faker', '~> 1.9'
36
36
  spec.add_dependency 'openapi_parser', '0.3.0'
37
37
  spec.add_dependency 'rack', '~> 2.0'
38
+ spec.add_dependency 'rack-cors', '~> 1.0'
38
39
  spec.add_dependency 'slop', '~> 4.6'
39
40
  end
@@ -13,6 +13,35 @@ module Fakeit
13
13
  def to_example(use_example = false)
14
14
  return example if use_example && example
15
15
 
16
+ return one_of_example(use_example) if one_of
17
+ return all_of_example(use_example) if all_of
18
+ return any_of_example(use_example) if any_of
19
+
20
+ type_based_example(use_example)
21
+ end
22
+
23
+ private
24
+
25
+ def one_of_example(use_example)
26
+ one_of.sample.to_example(use_example)
27
+ end
28
+
29
+ def all_of_example(use_example)
30
+ all_of
31
+ .select { |option| option.type == 'object' }
32
+ .map { |option| option.to_example(use_example) }
33
+ .reduce(&:merge)
34
+ end
35
+
36
+ def any_of_example(use_example)
37
+ any_of
38
+ .select { |option| option.type == 'object' }
39
+ .sample(Faker::Number.between(1, any_of.size))
40
+ .map { |option| option.to_example(use_example) }
41
+ .reduce(&:merge)
42
+ end
43
+
44
+ def type_based_example(use_example)
16
45
  case type
17
46
  when 'string', 'integer', 'number', 'boolean' then send("#{type}_example")
18
47
  when 'array', 'object' then send("#{type}_example", use_example)
@@ -7,9 +7,11 @@ module Fakeit
7
7
 
8
8
  def validate(body: '', params: {}, headers: {})
9
9
  options = OpenAPIParser::SchemaValidator::Options.new(coerce_value: true)
10
- body_data = parse(body)
11
10
 
12
- @operation.validate_request_body(request_content_type, body_data) if need_validate?(body_data)
11
+ if request_content_type
12
+ body_data = parse(body)
13
+ @operation.validate_request_body(request_content_type, body_data)
14
+ end
13
15
  @operation.validate_path_params(options)
14
16
  @operation.validate_request_parameter(params, headers, options)
15
17
  rescue StandardError => e
@@ -18,14 +20,10 @@ module Fakeit
18
20
 
19
21
  private
20
22
 
21
- def need_validate?(body_data)
22
- request_content_type && body_data
23
- end
24
-
25
23
  def parse(body)
26
24
  JSON.parse(body)
27
25
  rescue StandardError
28
- nil
26
+ raise ValidationError, 'Invalid json payload'
29
27
  end
30
28
 
31
29
  def request_content_type
@@ -1,3 +1,3 @@
1
1
  module Fakeit
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.5'.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.1.4
4
+ version: 0.1.5
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-25 00:00:00.000000000 Z
11
+ date: 2019-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '2.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rack-cors
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.0'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: slop
155
169
  requirement: !ruby/object:Gem::Requirement