committee 2.0.0.pre2 → 2.0.0.pre3

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
  SHA1:
3
- metadata.gz: c27dbbfbcb3d316bd61c7056fe0a8f7fec175ab6
4
- data.tar.gz: c3ad5a80a63987ae2f94988ed12b1285e71ee760
3
+ metadata.gz: 1e120c18b8e980fa98259dcb4d874b0dd095224b
4
+ data.tar.gz: de67a03b9afba89cbb0dce7b5654fedfb02a5dc7
5
5
  SHA512:
6
- metadata.gz: 86f1c3e718e6dee210e3c42ba2d1a5ba0b029137adc1be572d5dac9d6048dc7c84cf4274a652360473b9e263662912f5a7a94fc27b2666daf054530f0b44c40f
7
- data.tar.gz: 6dd6d2dc9165ea38e3df05a0d35915809a82447a5708728c192d22ee632692448f6e4996733c165c8f0d6f4895dff7bfa18b952c070b2a8bb1e01d21073ad7c7
6
+ metadata.gz: 59339f5504e9945a8cdc1248eaf47187d0eafb7cfe90c802a3f1e0b391b40154266d157cc3c16b48992ca39fe783c27ef8b8b3f7eeaeff39961c24d7a6e95052
7
+ data.tar.gz: d5252e28f9e64e2e8fd2812189ed425a32d01e55e1949588cf94d98ec537ee9fad7a0aa93be8672d8affd0946fc411ad00abe1d36e0c3a4b11db9b32d94cc5ef
data/bin/committee-stub CHANGED
@@ -12,7 +12,7 @@ options, parser = bin.get_options_parser
12
12
  if $0 == __FILE__
13
13
  parser.parse!(args)
14
14
 
15
- unless args.count == 1 || options[:help]
15
+ unless args.count == 1 || options[:help] || !options[:driver]
16
16
  puts parser.to_s
17
17
  exit
18
18
  end
@@ -25,7 +25,7 @@ module Committee
25
25
  # Gets an option parser for command line arguments.
26
26
  def get_options_parser
27
27
  options = {
28
- :driver => :hyper_schema,
28
+ :driver => nil,
29
29
  :help => false,
30
30
  :port => 9292,
31
31
  :tolerant => false,
@@ -37,14 +37,15 @@ module Committee
37
37
  opts.separator ""
38
38
  opts.separator "Options:"
39
39
 
40
- opts.on_tail("-h", "-?", "--help", "Show this message") {
41
- options[:help] = true
42
- }
43
-
40
+ # required
44
41
  opts.on("-d", "--driver NAME", "name of driver [open_api_2|hyper_schema]") { |name|
45
42
  options[:driver] = name.to_sym
46
43
  }
47
44
 
45
+ opts.on_tail("-h", "-?", "--help", "Show this message") {
46
+ options[:help] = true
47
+ }
48
+
48
49
  opts.on("-t", "--tolerant", "don't perform request/response validations") {
49
50
  options[:tolerant] = true
50
51
  }
@@ -1,5 +1,10 @@
1
1
  module Committee::Drivers
2
2
  class HyperSchema < Committee::Drivers::Driver
3
+ # Whether parameters that were form-encoded will be coerced by default.
4
+ def default_coerce_form_params
5
+ false
6
+ end
7
+
3
8
  # Whether parameters in a request's path will be considered and coerced by
4
9
  # default.
5
10
  def default_path_params
@@ -1,5 +1,10 @@
1
1
  module Committee::Drivers
2
2
  class OpenAPI2 < Committee::Drivers::Driver
3
+ # Whether parameters that were form-encoded will be coerced by default.
4
+ def default_coerce_form_params
5
+ true
6
+ end
7
+
3
8
  # Whether parameters in a request's path will be considered and coerced by
4
9
  # default.
5
10
  def default_path_params
@@ -15,6 +15,11 @@ module Committee
15
15
 
16
16
  # Driver is a base class for driver implementations.
17
17
  class Driver
18
+ # Whether parameters that were form-encoded will be coerced by default.
19
+ def default_coerce_form_params
20
+ raise "needs implementation"
21
+ end
22
+
18
23
  # Whether parameters in a request's path will be considered and coerced
19
24
  # by default.
20
25
  def default_path_params
@@ -9,6 +9,8 @@ module Committee::Middleware
9
9
  @optimistic_json = options.fetch(:optimistic_json, false)
10
10
  @strict = options[:strict]
11
11
 
12
+ @coerce_form_params = options.fetch(:coerce_form_params,
13
+ @schema.driver.default_coerce_form_params)
12
14
  @coerce_path_params = options.fetch(:coerce_path_params,
13
15
  @schema.driver.default_path_params)
14
16
  @coerce_query_params = options.fetch(:coerce_query_params,
@@ -50,7 +52,9 @@ module Committee::Middleware
50
52
  request,
51
53
  allow_form_params: @allow_form_params,
52
54
  allow_query_params: @allow_query_params,
53
- optimistic_json: @optimistic_json
55
+ coerce_form_params: @coerce_form_params,
56
+ optimistic_json: @optimistic_json,
57
+ schema: link ? link.schema : nil
54
58
  ).call
55
59
 
56
60
  request.env[@params_key].merge!(path_params)
@@ -5,7 +5,9 @@ module Committee
5
5
 
6
6
  @allow_form_params = options[:allow_form_params]
7
7
  @allow_query_params = options[:allow_query_params]
8
+ @coerce_form_params = options[:coerce_form_params]
8
9
  @optimistic_json = options[:optimistic_json]
10
+ @schema = options[:schema]
9
11
  end
10
12
 
11
13
  def call
@@ -26,7 +28,16 @@ module Committee
26
28
  elsif @allow_form_params && @request.media_type == "application/x-www-form-urlencoded"
27
29
  # Actually, POST means anything in the request body, could be from
28
30
  # PUT or PATCH too. Silly Rack.
29
- indifferent_params(@request.POST)
31
+ p = @request.POST
32
+
33
+ if @coerce_form_params && @schema
34
+ p.merge!(Committee::StringParamsCoercer.new(
35
+ p,
36
+ @schema
37
+ ).call)
38
+ end
39
+
40
+ p
30
41
  else
31
42
  {}
32
43
  end
@@ -32,6 +32,10 @@ describe Committee::Drivers::HyperSchema do
32
32
  end
33
33
  end
34
34
 
35
+ it "defaults to not coercing form parameters" do
36
+ assert_equal false, @driver.default_coerce_form_params
37
+ end
38
+
35
39
  it "defaults to no path parameters" do
36
40
  assert_equal false, @driver.default_path_params
37
41
  end
@@ -111,6 +111,10 @@ describe Committee::Drivers::OpenAPI2 do
111
111
  assert_equal "Committee: no definitions section in spec data.", e.message
112
112
  end
113
113
 
114
+ it "defaults to coercing form parameters" do
115
+ assert_equal true, @driver.default_coerce_form_params
116
+ end
117
+
114
118
  it "defaults to path parameters" do
115
119
  assert_equal true, @driver.default_path_params
116
120
  end
data/test/drivers_test.rb CHANGED
@@ -23,11 +23,12 @@ end
23
23
 
24
24
  describe Committee::Drivers::Driver do
25
25
  DRIVER_METHODS = {
26
- :default_path_params => [],
27
- :default_query_params => [],
28
- :name => [],
29
- :parse => [nil],
30
- :schema_class => [],
26
+ :default_coerce_form_params => [],
27
+ :default_path_params => [],
28
+ :default_query_params => [],
29
+ :name => [],
30
+ :parse => [nil],
31
+ :schema_class => [],
31
32
  }
32
33
 
33
34
  it "has a set of abstract methods" do
@@ -82,6 +82,25 @@ describe Committee::RequestUnpacker do
82
82
  assert_equal({ "x" => "y" }, params)
83
83
  end
84
84
 
85
+ it "coerces form params with coerce_form_params and a schema" do
86
+ schema = JsonSchema::Schema.new
87
+ schema.properties = { "x" => JsonSchema::Schema.new }
88
+ schema.properties["x"].type = ["integer"]
89
+
90
+ env = {
91
+ "CONTENT_TYPE" => "application/x-www-form-urlencoded",
92
+ "rack.input" => StringIO.new("x=1"),
93
+ }
94
+ request = Rack::Request.new(env)
95
+ params = Committee::RequestUnpacker.new(
96
+ request,
97
+ allow_form_params: true,
98
+ coerce_form_params: true,
99
+ schema: schema
100
+ ).call
101
+ assert_equal({ "x" => 1 }, params)
102
+ end
103
+
85
104
  it "unpacks form & query params with allow_form_params and allow_query_params" do
86
105
  env = {
87
106
  "CONTENT_TYPE" => "application/x-www-form-urlencoded",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: committee
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre2
4
+ version: 2.0.0.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-13 00:00:00.000000000 Z
12
+ date: 2016-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_schema
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '0.14'
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.14.1
23
+ version: 0.14.3
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '0.14'
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.14.1
33
+ version: 0.14.3
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rack
36
36
  requirement: !ruby/object:Gem::Requirement