committee 3.0.0.beta → 3.0.0.beta2

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: 5019abacff975df04498c8e2f04d04601dd6a99d1f3a621acafa6cf0873170fa
4
- data.tar.gz: 0a08b6be4a680675cd985abf1fad733e55eee9a47368f852148cf732de5f68ff
3
+ metadata.gz: 2a84dd861016ddeaee3ad16d447427f58aa2bca50347412a1ad6096240a85880
4
+ data.tar.gz: 4b7f456688b1be6456af985971c84b1387c0d8af5ef7c4c4545f6fd65c8c8929
5
5
  SHA512:
6
- metadata.gz: 179c89e72e306d1b79317a98ac7d3a1284edbecaaf13a04f9c7ab168724381988dfde7b4d45287c5f44d54f62d02296e959621f56038a55492e841e0d772021c
7
- data.tar.gz: 9668d280fa56807e4101ac150dd04fdc280c0e0db4e04d17bbad26a031dca914388320f1dc7aaaefaeb6d4e41e11a01b51eb0f50254181a298df275eb6e50063
6
+ metadata.gz: e491038b0ef712064edfab1417dc7c57834f501270530638d978a528b7ba4e50d80b757bf0c0533dd5238fc4ac69595f1216bcc64ddddd516cf9a643a7b42c45
7
+ data.tar.gz: 95e05627014f67f46f4bd9976d6895109dbbce41a48ca4cf830120b1ddbd18d4434fb08878d0acbce94fabf3b4354ed3422548c3a406f2af0bf882bdea8981df
@@ -10,7 +10,7 @@ module Committee
10
10
  def get_app(schema, options)
11
11
  cache = {}
12
12
 
13
- raise Committee::NotSupportOpenAPI3.new("OpenAPI3 not support stub") unless schema.support_stub?
13
+ raise Committee::OpenAPI3Unsupported.new("Stubs are not yet supported for OpenAPI 3") unless schema.supports_stub?
14
14
 
15
15
  Rack::Builder.new {
16
16
  unless options[:tolerant]
@@ -1,5 +1,9 @@
1
1
  module Committee::Drivers
2
2
  class HyperSchema < Committee::Drivers::Driver
3
+ def default_coerce_date_times
4
+ false
5
+ end
6
+
3
7
  # Whether parameters that were form-encoded will be coerced by default.
4
8
  def default_coerce_form_params
5
9
  false
@@ -17,10 +21,6 @@ module Committee::Drivers
17
21
  false
18
22
  end
19
23
 
20
- def default_coerce_date_times
21
- false
22
- end
23
-
24
24
  def default_validate_success_only
25
25
  true
26
26
  end
@@ -1,5 +1,9 @@
1
1
  module Committee::Drivers
2
2
  class OpenAPI2 < Committee::Drivers::Driver
3
+ def default_coerce_date_times
4
+ false
5
+ end
6
+
3
7
  # Whether parameters that were form-encoded will be coerced by default.
4
8
  def default_coerce_form_params
5
9
  true
@@ -17,10 +21,6 @@ module Committee::Drivers
17
21
  true
18
22
  end
19
23
 
20
- def default_coerce_date_times
21
- false
22
- end
23
-
24
24
  def default_validate_success_only
25
25
  true
26
26
  end
@@ -1,5 +1,9 @@
1
1
  module Committee::Drivers
2
2
  class OpenAPI3 < Committee::Drivers::Driver
3
+ def default_coerce_date_times
4
+ true
5
+ end
6
+
3
7
  # Whether parameters that were form-encoded will be coerced by default.
4
8
  def default_coerce_form_params
5
9
  true
@@ -17,10 +21,6 @@ module Committee::Drivers
17
21
  true
18
22
  end
19
23
 
20
- def default_coerce_date_times
21
- true
22
- end
23
-
24
24
  def default_validate_success_only
25
25
  false
26
26
  end
@@ -29,15 +29,15 @@ module Committee::Drivers
29
29
  :open_api_3
30
30
  end
31
31
 
32
- def schema_class
33
- Committee::Drivers::OpenAPI3::Schema
34
- end
35
-
36
32
  # @return [Committee::Drivers::OpenAPI3::Schema]
37
33
  def parse(open_api)
38
34
  schema_class.new(self, open_api)
39
35
  end
40
36
 
37
+ def schema_class
38
+ Committee::Drivers::OpenAPI3::Schema
39
+ end
40
+
41
41
  class Schema < Committee::Drivers::Schema
42
42
  attr_reader :open_api
43
43
  attr_reader :validator_option
@@ -50,7 +50,7 @@ module Committee::Drivers
50
50
  @driver = driver
51
51
  end
52
52
 
53
- def support_stub?
53
+ def supports_stub?
54
54
  false
55
55
  end
56
56
 
@@ -16,30 +16,30 @@ module Committee
16
16
  end
17
17
 
18
18
  # load and build drive from JSON file
19
- # @param [String] filepath
19
+ # @param [String] schema_path
20
20
  # @return [Committee::Driver]
21
- def self.load_from_json(filepath)
22
- load_from_data(JSON.parse(File.read(filepath)))
21
+ def self.load_from_json(schema_path)
22
+ load_from_data(JSON.parse(File.read(schema_path)))
23
23
  end
24
24
 
25
25
  # load and build drive from YAML file
26
- # @param [String] filepath
26
+ # @param [String] schema_path
27
27
  # @return [Committee::Driver]
28
- def self.load_from_yaml(filepath)
29
- load_from_data(YAML.load_file(filepath))
28
+ def self.load_from_yaml(schema_path)
29
+ load_from_data(YAML.load_file(schema_path))
30
30
  end
31
31
 
32
32
  # load and build drive from file
33
- # @param [String] filepath
33
+ # @param [String] schema_path
34
34
  # @return [Committee::Driver]
35
- def self.load_from_file(filepath)
36
- case File.extname(filepath)
35
+ def self.load_from_file(schema_path)
36
+ case File.extname(schema_path)
37
37
  when '.json'
38
- load_from_json(filepath)
38
+ load_from_json(schema_path)
39
39
  when '.yaml', '.yml'
40
- load_from_yaml(filepath)
40
+ load_from_yaml(schema_path)
41
41
  else
42
- raise "committee filepath option support '.yaml', '.yml', '.json' files only"
42
+ raise "Committee only supports the following file extensions: '.json', '.yaml', '.yml'"
43
43
  end
44
44
  end
45
45
 
@@ -110,8 +110,8 @@ module Committee
110
110
  raise "needs implementation"
111
111
  end
112
112
 
113
- # OpenAPI3 not support stub but JSON Hyper-Schema and OpenAPI2 support
114
- def support_stub?
113
+ # Stubs are supported in JSON Hyper-Schema and OpenAPI 2, but not yet in OpenAPI 3
114
+ def supports_stub?
115
115
  true
116
116
  end
117
117
  end
@@ -17,6 +17,6 @@ module Committee
17
17
  class ReferenceNotFound < Error
18
18
  end
19
19
 
20
- class NotSupportOpenAPI3 < Error
20
+ class OpenAPI3Unsupported < Error
21
21
  end
22
22
  end
@@ -25,7 +25,7 @@ module Committee::Middleware
25
25
  def get_schema(options)
26
26
  schema = options[:schema]
27
27
  unless schema
28
- schema = Committee::Drivers::load_from_file(options[:filepath]) if options[:filepath]
28
+ schema = Committee::Drivers::load_from_file(options[:schema_path]) if options[:schema_path]
29
29
 
30
30
  raise(ArgumentError, "Committee: need option `schema` or `filepath`") unless schema
31
31
  end
@@ -1,4 +1,4 @@
1
- # Don't Support OpenAPI3
1
+ # Stub is not yet supported in OpenAPI 3
2
2
 
3
3
  module Committee::Middleware
4
4
  class Stub < Base
@@ -15,7 +15,7 @@ module Committee::Middleware
15
15
 
16
16
  @call = options[:call]
17
17
 
18
- raise Committee::NotSupportOpenAPI3.new("OpenAPI3 not support stub") unless @schema.support_stub?
18
+ raise Committee::OpenAPI3Unsupported.new("Stubs are not yet supported for OpenAPI 3") unless @schema.supports_stub?
19
19
  end
20
20
 
21
21
  def handle(request)
@@ -10,7 +10,6 @@ class Committee::SchemaValidator
10
10
 
11
11
  def request_validate(request)
12
12
  path_params = validator_option.coerce_path_params ? coerce_path_params : {}
13
- # coerce_query_params(request) if validator_option.coerce_query_params
14
13
 
15
14
  request_unpack(request)
16
15
 
@@ -39,7 +38,7 @@ class Committee::SchemaValidator
39
38
  end
40
39
 
41
40
  def coerce_form_params(_parameter)
42
- # nothing because when request_schema_validation, check and coerce
41
+ # Empty because request_schema_validation checks and coerces
43
42
  end
44
43
 
45
44
  private
@@ -26,8 +26,8 @@ describe Committee::Bin::CommitteeStub do
26
26
  assert_equal "1234", options[:port]
27
27
  end
28
28
 
29
- it "OpenAPI3 not support Stub" do
30
- assert_raises(Committee::NotSupportOpenAPI3) do
29
+ it "is not supported in OpenAPI 3" do
30
+ assert_raises(Committee::OpenAPI3Unsupported) do
31
31
  @bin.get_app(open_api_3_schema, {})
32
32
  end
33
33
  end
@@ -37,41 +37,41 @@ describe Committee::Drivers::OpenAPI3 do
37
37
  describe "Schema" do
38
38
  describe "#operation_object" do
39
39
  describe "path template" do
40
- it "get normal path" do
40
+ it "gets a normal path" do
41
41
  obj = open_api_3_schema.operation_object("/path_template_test/no_template", "get")
42
42
  assert_equal "/path_template_test/no_template", obj.original_path
43
43
  end
44
44
 
45
- it "get template path" do
45
+ it "gets a template path" do
46
46
  obj = open_api_3_schema.operation_object("/path_template_test/test", "get")
47
47
  assert_equal "/path_template_test/{template_name}", obj.original_path
48
48
  end
49
49
 
50
- it "get nested template path" do
50
+ it "gets a nested template path" do
51
51
  obj = open_api_3_schema.operation_object("/path_template_test/abc/nested", "get")
52
52
  assert_equal "/path_template_test/{template_name}/nested", obj.original_path
53
53
  assert_equal({"template_name"=>"abc"}, obj.path_params)
54
54
  end
55
55
 
56
- it "get double nested template path" do
56
+ it "gets a double nested template path" do
57
57
  obj = open_api_3_schema.operation_object("/path_template_test/test/nested/abc", "get")
58
58
  assert_equal "/path_template_test/{template_name}/nested/{nested_parameter}", obj.original_path
59
59
  assert_equal({"template_name"=>"test", "nested_parameter" => "abc"}, obj.path_params)
60
60
  end
61
61
 
62
- it "get twice nested template path" do
62
+ it "gets a twice nested template path" do
63
63
  obj = open_api_3_schema.operation_object("/path_template_test/test/abc", "get")
64
64
  assert_equal "/path_template_test/{template_name}/{nested_parameter}", obj.original_path
65
65
  assert_equal({"template_name"=>"test", "nested_parameter" => "abc"}, obj.path_params)
66
66
  end
67
67
 
68
- it "get twice nested concrete path" do
68
+ it "gets a twice nested concrete path" do
69
69
  obj = open_api_3_schema.operation_object("/path_template_test/test/abc/finish", "get")
70
70
  assert_equal "/path_template_test/{template_name}/{nested_parameter}/finish", obj.original_path
71
71
  assert_equal({"template_name"=>"test", "nested_parameter" => "abc"}, obj.path_params)
72
72
  end
73
73
 
74
- it "get ambiguous path" do
74
+ it "gets an ambiguous path" do
75
75
  obj = open_api_3_schema.operation_object("/ambiguous/no_template", "get")
76
76
  assert_equal "/{ambiguous}/no_template", obj.original_path
77
77
  assert_equal({"ambiguous"=>"ambiguous"}, obj.path_params)
data/test/drivers_test.rb CHANGED
@@ -21,69 +21,69 @@ describe Committee::Drivers do
21
21
  assert_equal %{Committee: unknown driver "blueprint".}, e.message
22
22
  end
23
23
 
24
- describe 'load_from_file(filepath)' do
25
- it 'load OpenAPI2' do
26
- s = Committee::Drivers.load_from_file(open_api_2_filepath)
24
+ describe 'load_from_file(schema_path)' do
25
+ it 'loads OpenAPI2' do
26
+ s = Committee::Drivers.load_from_file(open_api_2_schema_path)
27
27
  assert_kind_of Committee::Drivers::Schema, s
28
28
  assert_kind_of Committee::Drivers::OpenAPI2::Schema, s
29
29
  end
30
30
 
31
- it 'load Hyper-Schema' do
32
- s = Committee::Drivers.load_from_file(hyper_schema_filepath)
31
+ it 'loads Hyper-Schema' do
32
+ s = Committee::Drivers.load_from_file(hyper_schema_schema_path)
33
33
  assert_kind_of Committee::Drivers::Schema, s
34
34
  assert_kind_of Committee::Drivers::HyperSchema::Schema, s
35
35
  end
36
36
 
37
- it 'load OpenAPI3' do
38
- s = Committee::Drivers.load_from_file(open_api_3_filepath)
37
+ it 'loads OpenAPI 3' do
38
+ s = Committee::Drivers.load_from_file(open_api_3_schema_path)
39
39
  assert_kind_of Committee::Drivers::Schema, s
40
40
  assert_kind_of Committee::Drivers::OpenAPI3::Schema, s
41
41
  end
42
42
 
43
- it 'load unsupported file extension' do
43
+ it 'errors on an unsupported file extension' do
44
44
  e = assert_raises(StandardError) do
45
45
  Committee::Drivers.load_from_file('test.xml')
46
46
  end
47
- assert_equal "committee filepath option support '.yaml', '.yml', '.json' files only", e.message
47
+ assert_equal "Committee only supports the following file extensions: '.json', '.yaml', '.yml'", e.message
48
48
  end
49
49
  end
50
50
 
51
- describe 'load_from_json(filepath)' do
52
- it 'load OpenAPI2' do
53
- s = Committee::Drivers.load_from_json(open_api_2_filepath)
51
+ describe 'load_from_json(schema_path)' do
52
+ it 'loads OpenAPI2' do
53
+ s = Committee::Drivers.load_from_json(open_api_2_schema_path)
54
54
  assert_kind_of Committee::Drivers::Schema, s
55
55
  assert_kind_of Committee::Drivers::OpenAPI2::Schema, s
56
56
  end
57
57
 
58
- it 'load Hyper-Schema' do
59
- s = Committee::Drivers.load_from_json(hyper_schema_filepath)
58
+ it 'loads Hyper-Schema' do
59
+ s = Committee::Drivers.load_from_json(hyper_schema_schema_path)
60
60
  assert_kind_of Committee::Drivers::Schema, s
61
61
  assert_kind_of Committee::Drivers::HyperSchema::Schema, s
62
62
  end
63
63
  end
64
64
 
65
- describe 'load_from_yaml(filepath)' do
66
- it 'load OpenAPI3' do
67
- s = Committee::Drivers.load_from_yaml(open_api_3_filepath)
65
+ describe 'load_from_yaml(schema_path)' do
66
+ it 'loads OpenAPI3' do
67
+ s = Committee::Drivers.load_from_yaml(open_api_3_schema_path)
68
68
  assert_kind_of Committee::Drivers::Schema, s
69
69
  assert_kind_of Committee::Drivers::OpenAPI3::Schema, s
70
70
  end
71
71
  end
72
72
 
73
- describe 'load_from_data(filepath)' do
74
- it 'load OpenAPI3' do
73
+ describe 'load_from_data(schema_path)' do
74
+ it 'loads OpenAPI3' do
75
75
  s = Committee::Drivers.load_from_data(open_api_3_data)
76
76
  assert_kind_of Committee::Drivers::Schema, s
77
77
  assert_kind_of Committee::Drivers::OpenAPI3::Schema, s
78
78
  end
79
79
 
80
- it 'load OpenAPI2' do
80
+ it 'loads OpenAPI2' do
81
81
  s = Committee::Drivers.load_from_data(open_api_2_data)
82
82
  assert_kind_of Committee::Drivers::Schema, s
83
83
  assert_kind_of Committee::Drivers::OpenAPI2::Schema, s
84
84
  end
85
85
 
86
- it 'load Hyper-Schema' do
86
+ it 'loads Hyper-Schema' do
87
87
  s = Committee::Drivers.load_from_data(hyper_schema_data)
88
88
  assert_kind_of Committee::Drivers::Schema, s
89
89
  assert_kind_of Committee::Drivers::HyperSchema::Schema, s
@@ -29,7 +29,7 @@ describe Committee::Middleware::Base do
29
29
  assert_equal 200, last_response.status
30
30
  end
31
31
 
32
- it "don't accepts schema string" do
32
+ it "doesn't accept a schema string" do
33
33
  @app = new_rack_app(
34
34
  schema: JSON.dump(hyper_schema_data)
35
35
  )
@@ -46,7 +46,7 @@ describe Committee::Middleware::Base do
46
46
  "of Committee::Drivers::Schema.", e.message
47
47
  end
48
48
 
49
- it "don't accepts schema hash" do
49
+ it "doesn't accept a schema hash" do
50
50
  @app = new_rack_app(
51
51
  schema: hyper_schema_data
52
52
  )
@@ -63,7 +63,7 @@ describe Committee::Middleware::Base do
63
63
  "of Committee::Drivers::Schema.", e.message
64
64
  end
65
65
 
66
- it "don't accepts schema JsonSchema::Schema object" do
66
+ it "doesn't accept a JsonSchema::Schema object" do
67
67
  @app = new_rack_app(
68
68
  schema: JsonSchema.parse!(hyper_schema_data)
69
69
  )
@@ -90,7 +90,7 @@ describe Committee::Middleware::Base do
90
90
  assert_equal "Committee: schema expected to be an instance of Committee::Drivers::Schema.", e.message
91
91
  end
92
92
 
93
- it "schema not exist" do
93
+ it "errors when no schema is specified" do
94
94
  @app = new_rack_app
95
95
  e = assert_raises(ArgumentError) do
96
96
  post "/apps"
@@ -100,18 +100,18 @@ describe Committee::Middleware::Base do
100
100
  end
101
101
 
102
102
  describe 'initialize option' do
103
- it "filepath option with hyper-schema" do
104
- b = Committee::Middleware::Base.new(nil, filepath: hyper_schema_filepath)
103
+ it "schema_path option with hyper-schema" do
104
+ b = Committee::Middleware::Base.new(nil, schema_path: hyper_schema_schema_path)
105
105
  assert_kind_of Committee::Drivers::HyperSchema::Schema, b.instance_variable_get(:@schema)
106
106
  end
107
107
 
108
- it "filepath option with OpenAPI2" do
109
- b = Committee::Middleware::Base.new(nil, filepath: open_api_2_filepath)
108
+ it "schema_path option with OpenAPI2" do
109
+ b = Committee::Middleware::Base.new(nil, schema_path: open_api_2_schema_path)
110
110
  assert_kind_of Committee::Drivers::OpenAPI2::Schema, b.instance_variable_get(:@schema)
111
111
  end
112
112
 
113
113
  it "filepath option with OpenAPI3" do
114
- b = Committee::Middleware::Base.new(nil, filepath: open_api_3_filepath)
114
+ b = Committee::Middleware::Base.new(nil, schema_path: open_api_3_schema_path)
115
115
  assert_kind_of Committee::Drivers::OpenAPI3::Schema, b.instance_variable_get(:@schema)
116
116
  end
117
117
  end
@@ -18,7 +18,7 @@ describe Committee::Middleware::RequestValidation do
18
18
  assert_equal 200, last_response.status
19
19
  end
20
20
 
21
- it "not parameter requset" do
21
+ it "not parameter request" do
22
22
  check_parameter_string = lambda { |_|
23
23
  [200, {integer: 1}, []]
24
24
  }
@@ -100,7 +100,7 @@ describe Committee::Middleware::Stub do
100
100
  cache = {}
101
101
  @app = new_rack_app(cache: cache, schema: open_api_3_schema)
102
102
 
103
- assert_raises(Committee::NotSupportOpenAPI3) do
103
+ assert_raises(Committee::OpenAPI3Unsupported) do
104
104
  get "/characters"
105
105
  end
106
106
  end
@@ -122,7 +122,7 @@ describe Committee::RequestUnpacker do
122
122
  end
123
123
  end
124
124
 
125
- it "coerces form params with coerce_form_params and a OpenAPI3 schema" do
125
+ it "coerces form params with coerce_form_params and an OpenAPI3 schema" do
126
126
  %w[application/x-www-form-urlencoded multipart/form-data].each do |content_type|
127
127
  env = {
128
128
  "CONTENT_TYPE" => content_type,
data/test/test_helper.rb CHANGED
@@ -48,11 +48,11 @@ ValidPet = {
48
48
  }.freeze
49
49
 
50
50
  def hyper_schema
51
- @hyper_schema ||= Committee::Drivers.load_from_json(hyper_schema_filepath)
51
+ @hyper_schema ||= Committee::Drivers.load_from_json(hyper_schema_schema_path)
52
52
  end
53
53
 
54
54
  def open_api_2_schema
55
- @open_api_2_schema ||= Committee::Drivers.load_from_file(open_api_2_filepath)
55
+ @open_api_2_schema ||= Committee::Drivers.load_from_file(open_api_2_schema_path)
56
56
  end
57
57
 
58
58
  def open_api_3_schema
@@ -61,26 +61,27 @@ end
61
61
 
62
62
  # Don't cache this because we'll often manipulate the created hash in tests.
63
63
  def hyper_schema_data
64
- JSON.parse(File.read(hyper_schema_filepath))
64
+ JSON.parse(File.read(hyper_schema_schema_path))
65
65
  end
66
66
 
67
67
  # Don't cache this because we'll often manipulate the created hash in tests.
68
68
  def open_api_2_data
69
- JSON.parse(File.read(open_api_2_filepath))
69
+ JSON.parse(File.read(open_api_2_schema_path))
70
70
  end
71
71
 
72
72
  def open_api_3_data
73
- YAML.load_file(open_api_3_filepath)
73
+ YAML.load_file(open_api_3_schema_path)
74
74
  end
75
75
 
76
- def hyper_schema_filepath
76
+ def hyper_schema_schema_path
77
77
  "./test/data/hyperschema/paas.json"
78
78
  end
79
79
 
80
- def open_api_2_filepath
80
+ def open_api_2_schema_path
81
81
  "./test/data/openapi2/petstore-expanded.json"
82
82
  end
83
83
 
84
- def open_api_3_filepath
85
- "./test/data/openapi3/normal.yml"
84
+ def open_api_3_schema_path
85
+ "./test/data/openapi3/normal.yaml"
86
86
  end
87
+
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: 3.0.0.beta
4
+ version: 3.0.0.beta2
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: 2019-01-19 00:00:00.000000000 Z
12
+ date: 2019-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json_schema
@@ -242,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
242
  version: 1.3.1
243
243
  requirements: []
244
244
  rubyforge_project:
245
- rubygems_version: 2.7.3
245
+ rubygems_version: 2.7.7
246
246
  signing_key:
247
247
  specification_version: 4
248
248
  summary: A collection of Rack middleware to support JSON Schema.