committee_firetail 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/committee-stub +23 -0
- data/lib/committee/bin/committee_stub.rb +67 -0
- data/lib/committee/drivers/driver.rb +47 -0
- data/lib/committee/drivers/hyper_schema/driver.rb +105 -0
- data/lib/committee/drivers/hyper_schema/link.rb +68 -0
- data/lib/committee/drivers/hyper_schema/schema.rb +22 -0
- data/lib/committee/drivers/hyper_schema.rb +12 -0
- data/lib/committee/drivers/open_api_2/driver.rb +252 -0
- data/lib/committee/drivers/open_api_2/header_schema_builder.rb +33 -0
- data/lib/committee/drivers/open_api_2/link.rb +36 -0
- data/lib/committee/drivers/open_api_2/parameter_schema_builder.rb +83 -0
- data/lib/committee/drivers/open_api_2/schema.rb +26 -0
- data/lib/committee/drivers/open_api_2/schema_builder.rb +33 -0
- data/lib/committee/drivers/open_api_2.rb +13 -0
- data/lib/committee/drivers/open_api_3/driver.rb +51 -0
- data/lib/committee/drivers/open_api_3/schema.rb +41 -0
- data/lib/committee/drivers/open_api_3.rb +11 -0
- data/lib/committee/drivers/schema.rb +23 -0
- data/lib/committee/drivers.rb +84 -0
- data/lib/committee/errors.rb +36 -0
- data/lib/committee/middleware/base.rb +57 -0
- data/lib/committee/middleware/request_validation.rb +41 -0
- data/lib/committee/middleware/response_validation.rb +58 -0
- data/lib/committee/middleware/stub.rb +75 -0
- data/lib/committee/middleware.rb +11 -0
- data/lib/committee/request_unpacker.rb +91 -0
- data/lib/committee/schema_validator/hyper_schema/parameter_coercer.rb +79 -0
- data/lib/committee/schema_validator/hyper_schema/request_validator.rb +55 -0
- data/lib/committee/schema_validator/hyper_schema/response_generator.rb +102 -0
- data/lib/committee/schema_validator/hyper_schema/response_validator.rb +89 -0
- data/lib/committee/schema_validator/hyper_schema/router.rb +46 -0
- data/lib/committee/schema_validator/hyper_schema/string_params_coercer.rb +105 -0
- data/lib/committee/schema_validator/hyper_schema.rb +119 -0
- data/lib/committee/schema_validator/open_api_3/operation_wrapper.rb +139 -0
- data/lib/committee/schema_validator/open_api_3/request_validator.rb +52 -0
- data/lib/committee/schema_validator/open_api_3/response_validator.rb +29 -0
- data/lib/committee/schema_validator/open_api_3/router.rb +45 -0
- data/lib/committee/schema_validator/open_api_3.rb +120 -0
- data/lib/committee/schema_validator/option.rb +60 -0
- data/lib/committee/schema_validator.rb +23 -0
- data/lib/committee/test/methods.rb +84 -0
- data/lib/committee/test/schema_coverage.rb +101 -0
- data/lib/committee/utils.rb +28 -0
- data/lib/committee/validation_error.rb +26 -0
- data/lib/committee/version.rb +5 -0
- data/lib/committee.rb +40 -0
- data/test/bin/committee_stub_test.rb +57 -0
- data/test/bin_test.rb +25 -0
- data/test/committee_test.rb +77 -0
- data/test/drivers/hyper_schema/driver_test.rb +49 -0
- data/test/drivers/hyper_schema/link_test.rb +56 -0
- data/test/drivers/open_api_2/driver_test.rb +156 -0
- data/test/drivers/open_api_2/header_schema_builder_test.rb +26 -0
- data/test/drivers/open_api_2/link_test.rb +52 -0
- data/test/drivers/open_api_2/parameter_schema_builder_test.rb +195 -0
- data/test/drivers/open_api_3/driver_test.rb +84 -0
- data/test/drivers_test.rb +154 -0
- data/test/middleware/base_test.rb +130 -0
- data/test/middleware/request_validation_open_api_3_test.rb +626 -0
- data/test/middleware/request_validation_test.rb +516 -0
- data/test/middleware/response_validation_open_api_3_test.rb +291 -0
- data/test/middleware/response_validation_test.rb +189 -0
- data/test/middleware/stub_test.rb +145 -0
- data/test/request_unpacker_test.rb +200 -0
- data/test/schema_validator/hyper_schema/parameter_coercer_test.rb +111 -0
- data/test/schema_validator/hyper_schema/request_validator_test.rb +151 -0
- data/test/schema_validator/hyper_schema/response_generator_test.rb +142 -0
- data/test/schema_validator/hyper_schema/response_validator_test.rb +118 -0
- data/test/schema_validator/hyper_schema/router_test.rb +88 -0
- data/test/schema_validator/hyper_schema/string_params_coercer_test.rb +137 -0
- data/test/schema_validator/open_api_3/operation_wrapper_test.rb +218 -0
- data/test/schema_validator/open_api_3/request_validator_test.rb +110 -0
- data/test/schema_validator/open_api_3/response_validator_test.rb +92 -0
- data/test/test/methods_new_version_test.rb +97 -0
- data/test/test/methods_test.rb +363 -0
- data/test/test/schema_coverage_test.rb +216 -0
- data/test/test_helper.rb +120 -0
- data/test/validation_error_test.rb +25 -0
- metadata +328 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Committee
|
4
|
+
class ValidationError
|
5
|
+
attr_reader :id, :message, :status, :request
|
6
|
+
|
7
|
+
def initialize(status, id, message, request = nil)
|
8
|
+
@status = status
|
9
|
+
@id = id
|
10
|
+
@message = message
|
11
|
+
@request = request
|
12
|
+
end
|
13
|
+
|
14
|
+
def error_body
|
15
|
+
{ id: id, message: message }
|
16
|
+
end
|
17
|
+
|
18
|
+
def render
|
19
|
+
[
|
20
|
+
status,
|
21
|
+
{ "Content-Type" => "application/json" },
|
22
|
+
[JSON.generate(error_body)]
|
23
|
+
]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/committee.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "yaml"
|
5
|
+
require "json_schema"
|
6
|
+
require "rack"
|
7
|
+
require 'openapi_parser'
|
8
|
+
|
9
|
+
require_relative "committee/version"
|
10
|
+
|
11
|
+
module Committee
|
12
|
+
def self.debug?
|
13
|
+
ENV["COMMITTEE_DEBUG"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.log_debug(message)
|
17
|
+
$stderr.puts(message) if debug?
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.need_good_option(message)
|
21
|
+
warn(message)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.warn_deprecated_until_6(cond, message)
|
25
|
+
raise "remove deprecated!" unless Committee::VERSION.start_with?("5")
|
26
|
+
warn("[DEPRECATION] #{message}") if cond
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
require_relative "committee/utils"
|
31
|
+
require_relative "committee/drivers"
|
32
|
+
require_relative "committee/errors"
|
33
|
+
require_relative "committee/middleware"
|
34
|
+
require_relative "committee/request_unpacker"
|
35
|
+
require_relative "committee/schema_validator"
|
36
|
+
require_relative "committee/validation_error"
|
37
|
+
|
38
|
+
require_relative "committee/bin/committee_stub"
|
39
|
+
require_relative "committee/test/methods"
|
40
|
+
require_relative "committee/test/schema_coverage"
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe Committee::Bin::CommitteeStub do
|
6
|
+
before do
|
7
|
+
@bin = Committee::Bin::CommitteeStub.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "produces a Rack app" do
|
11
|
+
app = @bin.get_app(hyper_schema, {})
|
12
|
+
assert_kind_of Rack::Builder, app
|
13
|
+
end
|
14
|
+
|
15
|
+
it "parses command line options" do
|
16
|
+
options, parser = @bin.get_options_parser
|
17
|
+
|
18
|
+
parser.parse!(["--help"])
|
19
|
+
assert_equal true, options[:help]
|
20
|
+
|
21
|
+
parser.parse!([
|
22
|
+
"--driver", "open_api_2",
|
23
|
+
"--tolerant", "true",
|
24
|
+
"--port", "1234"
|
25
|
+
])
|
26
|
+
assert_equal :open_api_2, options[:driver]
|
27
|
+
assert_equal true, options[:tolerant]
|
28
|
+
assert_equal "1234", options[:port]
|
29
|
+
end
|
30
|
+
|
31
|
+
it "is not supported in OpenAPI 3" do
|
32
|
+
assert_raises(Committee::OpenAPI3Unsupported) do
|
33
|
+
@bin.get_app(open_api_3_schema, {})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe Committee::Bin::CommitteeStub, "app" do
|
39
|
+
include Rack::Test::Methods
|
40
|
+
|
41
|
+
before do
|
42
|
+
@bin = Committee::Bin::CommitteeStub.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def app
|
46
|
+
options = {}
|
47
|
+
# TODO: delete when 5.0.0 released because default value changed
|
48
|
+
options[:parse_response_by_content_type] = false
|
49
|
+
|
50
|
+
@bin.get_app(hyper_schema, options)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "defaults to a 404" do
|
54
|
+
get "/foos"
|
55
|
+
assert_equal 404, last_response.status
|
56
|
+
end
|
57
|
+
end
|
data/test/bin_test.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
#
|
6
|
+
# The purpose of this sets of tests is just to include our Ruby executables
|
7
|
+
# where possible so that we can get very basic sanity checks on their syntax
|
8
|
+
# (which is something that of course Ruby can't do by default).
|
9
|
+
#
|
10
|
+
# We can do this without actually executing them because they're gated by `if
|
11
|
+
# $0 == __FILE__` statements.
|
12
|
+
#
|
13
|
+
|
14
|
+
describe "executables in bin/" do
|
15
|
+
before do
|
16
|
+
@bin_dir = File.expand_path("../../bin", __FILE__)
|
17
|
+
ARGV[0] = '-h'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "has roughly valid Ruby structure for committee-stub" do
|
21
|
+
assert_output(%r{Usage: rackup \[options\] \[JSON Schema file\]}) do
|
22
|
+
load File.join(@bin_dir, "committee-stub")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe Committee do
|
6
|
+
it "debugs based off env" do
|
7
|
+
old = ENV["COMMITTEE_DEBUG"]
|
8
|
+
begin
|
9
|
+
ENV["COMMITTEE_DEBUG"] = nil
|
10
|
+
refute Committee.debug?
|
11
|
+
ENV["COMMITTEE_DEBUG"] = "true"
|
12
|
+
assert Committee.debug?
|
13
|
+
ensure
|
14
|
+
ENV["COMMITTEE_DEBUG"] = old
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "logs debug messages to stderr" do
|
19
|
+
old_stderr = $stderr
|
20
|
+
$stderr = StringIO.new
|
21
|
+
begin
|
22
|
+
stub(Committee).debug? { false }
|
23
|
+
Committee.log_debug "blah"
|
24
|
+
assert_equal "", $stderr.string
|
25
|
+
|
26
|
+
stub(Committee).debug? { true }
|
27
|
+
Committee.log_debug "blah"
|
28
|
+
assert_equal "blah\n", $stderr.string
|
29
|
+
ensure
|
30
|
+
$stderr = old_stderr
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "warns need_good_option" do
|
35
|
+
old_stderr = $stderr
|
36
|
+
$stderr = StringIO.new
|
37
|
+
begin
|
38
|
+
Committee.need_good_option "show"
|
39
|
+
assert_equal "show\n", $stderr.string
|
40
|
+
ensure
|
41
|
+
$stderr = old_stderr
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "warns on deprecated unless $VERBOSE is nil" do
|
46
|
+
old_stderr = $stderr
|
47
|
+
old_verbose = $VERBOSE
|
48
|
+
$stderr = StringIO.new
|
49
|
+
begin
|
50
|
+
$VERBOSE = nil
|
51
|
+
Committee.warn_deprecated_until_6 true, "blah"
|
52
|
+
assert_equal "", $stderr.string
|
53
|
+
|
54
|
+
$VERBOSE = true
|
55
|
+
Committee.warn_deprecated_until_6 true, "blah"
|
56
|
+
assert_equal "[DEPRECATION] blah\n", $stderr.string
|
57
|
+
ensure
|
58
|
+
$stderr = old_stderr
|
59
|
+
$VERBOSE = old_verbose
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
it "doesn't warns on deprecated if cond is false" do
|
65
|
+
old_stderr = $stderr
|
66
|
+
old_verbose = $VERBOSE
|
67
|
+
$stderr = StringIO.new
|
68
|
+
begin
|
69
|
+
$VERBOSE = true
|
70
|
+
Committee.warn_deprecated_until_6 false, "blah"
|
71
|
+
assert_equal "", $stderr.string
|
72
|
+
ensure
|
73
|
+
$stderr = old_stderr
|
74
|
+
$VERBOSE = old_verbose
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe Committee::Drivers::HyperSchema::Driver do
|
6
|
+
before do
|
7
|
+
@driver = Committee::Drivers::HyperSchema::Driver.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has a name" do
|
11
|
+
assert_equal :hyper_schema, @driver.name
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has a schema class" do
|
15
|
+
assert_equal Committee::Drivers::HyperSchema::Schema, @driver.schema_class
|
16
|
+
end
|
17
|
+
|
18
|
+
it "parses a hyper-schema and builds routes" do
|
19
|
+
schema = @driver.parse(hyper_schema_data)
|
20
|
+
assert_kind_of Committee::Drivers::HyperSchema::Schema, schema
|
21
|
+
assert_equal @driver, schema.driver
|
22
|
+
|
23
|
+
assert_kind_of Hash, schema.routes
|
24
|
+
refute schema.routes.empty?
|
25
|
+
assert(schema.routes.keys.all? { |m|
|
26
|
+
["DELETE", "GET", "PATCH", "POST", "PUT"].include?(m)
|
27
|
+
})
|
28
|
+
|
29
|
+
schema.routes.each do |(_, method_routes)|
|
30
|
+
method_routes.each do |regex, link|
|
31
|
+
assert_kind_of Regexp, regex
|
32
|
+
assert_kind_of Committee::Drivers::HyperSchema::Link, link
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "defaults to not coercing form parameters" do
|
38
|
+
assert_equal false, @driver.default_coerce_form_params
|
39
|
+
end
|
40
|
+
|
41
|
+
it "defaults to no path parameters" do
|
42
|
+
assert_equal false, @driver.default_path_params
|
43
|
+
end
|
44
|
+
|
45
|
+
it "defaults to no query parameters" do
|
46
|
+
assert_equal false, @driver.default_query_params
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe Committee::Drivers::HyperSchema::Link do
|
6
|
+
before do
|
7
|
+
@hyper_schema_link = JsonSchema::Schema::Link.new
|
8
|
+
@hyper_schema_link.enc_type = "application/x-www-form-urlencoded"
|
9
|
+
@hyper_schema_link.href = "/apps"
|
10
|
+
@hyper_schema_link.media_type = "application/json"
|
11
|
+
@hyper_schema_link.method = "GET"
|
12
|
+
@hyper_schema_link.parent = { "title" => "parent" }
|
13
|
+
@hyper_schema_link.rel = "instances"
|
14
|
+
@hyper_schema_link.schema = { "title" => "input" }
|
15
|
+
@hyper_schema_link.target_schema = { "title" => "target" }
|
16
|
+
|
17
|
+
@link = Committee::Drivers::HyperSchema::Link.new(@hyper_schema_link)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "proxies #enc_type" do
|
21
|
+
assert_equal "application/x-www-form-urlencoded", @link.enc_type
|
22
|
+
end
|
23
|
+
|
24
|
+
it "proxies #href" do
|
25
|
+
assert_equal "/apps", @link.href
|
26
|
+
end
|
27
|
+
|
28
|
+
it "proxies #media_type" do
|
29
|
+
assert_equal "application/json", @link.media_type
|
30
|
+
end
|
31
|
+
|
32
|
+
it "proxies #method" do
|
33
|
+
assert_equal "GET", @link.method
|
34
|
+
end
|
35
|
+
|
36
|
+
it "proxies #rel" do
|
37
|
+
assert_equal "instances", @link.rel
|
38
|
+
end
|
39
|
+
|
40
|
+
it "proxies #schema" do
|
41
|
+
assert_equal @hyper_schema_link.schema, @link.schema
|
42
|
+
end
|
43
|
+
|
44
|
+
it "generates 200 #status_success for non-create" do
|
45
|
+
assert_equal 200, @link.status_success
|
46
|
+
end
|
47
|
+
|
48
|
+
it "generates 201 #status_success for create" do
|
49
|
+
@hyper_schema_link.rel = "create"
|
50
|
+
assert_equal 201, @link.status_success
|
51
|
+
end
|
52
|
+
|
53
|
+
it "proxies #target_schema" do
|
54
|
+
assert_equal @hyper_schema_link.target_schema, @link.target_schema
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe Committee::Drivers::OpenAPI2::Driver do
|
6
|
+
before do
|
7
|
+
@driver = Committee::Drivers::OpenAPI2::Driver.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has a name" do
|
11
|
+
assert_equal :open_api_2, @driver.name
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has a schema class" do
|
15
|
+
assert_equal Committee::Drivers::OpenAPI2::Schema, @driver.schema_class
|
16
|
+
end
|
17
|
+
|
18
|
+
it "parses an OpenAPI 2 spec" do
|
19
|
+
schema = @driver.parse(open_api_2_data)
|
20
|
+
assert_kind_of Committee::Drivers::OpenAPI2::Schema, schema
|
21
|
+
assert_kind_of JsonSchema::Schema, schema.definitions
|
22
|
+
assert_equal @driver, schema.driver
|
23
|
+
|
24
|
+
assert_kind_of Hash, schema.routes
|
25
|
+
refute schema.routes.empty?
|
26
|
+
assert(schema.routes.keys.all? { |m|
|
27
|
+
["DELETE", "GET", "PATCH", "POST", "PUT"].include?(m)
|
28
|
+
})
|
29
|
+
|
30
|
+
schema.routes.each do |(_, method_routes)|
|
31
|
+
method_routes.each do |regex, link|
|
32
|
+
assert_kind_of Regexp, regex
|
33
|
+
assert_kind_of Committee::Drivers::OpenAPI2::Link, link
|
34
|
+
|
35
|
+
# verify that we've correct generated a parameters schema for each link
|
36
|
+
if link.target_schema
|
37
|
+
assert_kind_of JsonSchema::Schema, link.schema if link.schema
|
38
|
+
end
|
39
|
+
|
40
|
+
if link.target_schema
|
41
|
+
assert_kind_of JsonSchema::Schema, link.target_schema
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "names capture groups into href regexes" do
|
48
|
+
schema = @driver.parse(open_api_2_data)
|
49
|
+
assert_equal %r{^\/api\/pets\/(?<id>[^\/]+)$}.inspect,
|
50
|
+
schema.routes["DELETE"][0][0].inspect
|
51
|
+
end
|
52
|
+
|
53
|
+
it "prefers a 200 response first" do
|
54
|
+
schema_data = schema_data_with_responses({
|
55
|
+
'201' => { 'schema' => { 'description' => '201 response' } },
|
56
|
+
'200' => { 'schema' => { 'description' => '200 response' } },
|
57
|
+
})
|
58
|
+
|
59
|
+
schema = @driver.parse(schema_data)
|
60
|
+
link = schema.routes['GET'][0][1]
|
61
|
+
assert_equal 200, link.status_success
|
62
|
+
assert_equal({ 'description' => '200 response' }, link.target_schema.data)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "prefers a 201 response next" do
|
66
|
+
schema_data = schema_data_with_responses({
|
67
|
+
'302' => { 'schema' => { 'description' => '302 response' } },
|
68
|
+
'201' => { 'schema' => { 'description' => '201 response' } },
|
69
|
+
})
|
70
|
+
|
71
|
+
schema = @driver.parse(schema_data)
|
72
|
+
link = schema.routes['GET'][0][1]
|
73
|
+
assert_equal 201, link.status_success
|
74
|
+
assert_equal({ 'description' => '201 response' }, link.target_schema.data)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "prefers any three-digit response next" do
|
78
|
+
schema_data = schema_data_with_responses({
|
79
|
+
'default' => { 'schema' => { 'description' => 'default response' } },
|
80
|
+
'302' => { 'schema' => { 'description' => '302 response' } },
|
81
|
+
})
|
82
|
+
|
83
|
+
schema = @driver.parse(schema_data)
|
84
|
+
link = schema.routes['GET'][0][1]
|
85
|
+
assert_equal 302, link.status_success
|
86
|
+
assert_equal({ 'description' => '302 response' }, link.target_schema.data)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "prefers any numeric three-digit response next" do
|
90
|
+
schema_data = schema_data_with_responses({
|
91
|
+
'default' => { 'schema' => { 'description' => 'default response' } },
|
92
|
+
302 => { 'schema' => { 'description' => '302 response' } },
|
93
|
+
})
|
94
|
+
|
95
|
+
schema = @driver.parse(schema_data)
|
96
|
+
link = schema.routes['GET'][0][1]
|
97
|
+
assert_equal 302, link.status_success
|
98
|
+
assert_equal({ 'description' => '302 response' }, link.target_schema.data)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "falls back to no response" do
|
102
|
+
schema_data = schema_data_with_responses({})
|
103
|
+
|
104
|
+
schema = @driver.parse(schema_data)
|
105
|
+
link = schema.routes['GET'][0][1]
|
106
|
+
assert_nil link.status_success
|
107
|
+
assert_nil link.target_schema
|
108
|
+
end
|
109
|
+
|
110
|
+
it "refuses to parse other version of OpenAPI" do
|
111
|
+
data = open_api_2_data
|
112
|
+
data['swagger'] = '3.0'
|
113
|
+
e = assert_raises(ArgumentError) do
|
114
|
+
@driver.parse(data)
|
115
|
+
end
|
116
|
+
assert_equal "Committee: driver requires OpenAPI 2.0.", e.message
|
117
|
+
end
|
118
|
+
|
119
|
+
it "refuses to parse a spec without mandatory fields" do
|
120
|
+
data = open_api_2_data
|
121
|
+
data['definitions'] = nil
|
122
|
+
e = assert_raises(ArgumentError) do
|
123
|
+
@driver.parse(data)
|
124
|
+
end
|
125
|
+
assert_equal "Committee: no definitions section in spec data.", e.message
|
126
|
+
end
|
127
|
+
|
128
|
+
it "defaults to coercing form parameters" do
|
129
|
+
assert_equal true, @driver.default_coerce_form_params
|
130
|
+
end
|
131
|
+
|
132
|
+
it "defaults to path parameters" do
|
133
|
+
assert_equal true, @driver.default_path_params
|
134
|
+
end
|
135
|
+
|
136
|
+
it "defaults to query parameters" do
|
137
|
+
assert_equal true, @driver.default_query_params
|
138
|
+
end
|
139
|
+
|
140
|
+
def schema_data_with_responses(response_data)
|
141
|
+
{
|
142
|
+
'swagger' => '2.0',
|
143
|
+
'consumes' => ['application/json'],
|
144
|
+
'produces' => ['application/json'],
|
145
|
+
'paths' => {
|
146
|
+
'/foos' => {
|
147
|
+
'get' => {
|
148
|
+
'responses' => response_data,
|
149
|
+
},
|
150
|
+
},
|
151
|
+
},
|
152
|
+
'definitions' => {},
|
153
|
+
}
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe Committee::Drivers::OpenAPI2::HeaderSchemaBuilder do
|
6
|
+
it "returns schema data for header" do
|
7
|
+
data = {
|
8
|
+
"parameters" => [
|
9
|
+
{
|
10
|
+
"name" => "AUTH_TOKEN",
|
11
|
+
"type" => "string",
|
12
|
+
"in" => "header",
|
13
|
+
}
|
14
|
+
]
|
15
|
+
}
|
16
|
+
schema = call(data)
|
17
|
+
|
18
|
+
assert_equal ["string"], schema.properties["AUTH_TOKEN"].type
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def call(data)
|
24
|
+
Committee::Drivers::OpenAPI2::HeaderSchemaBuilder.new(data).call
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
describe Committee::Drivers::OpenAPI2::Link do
|
6
|
+
before do
|
7
|
+
@link = Committee::Drivers::OpenAPI2::Link.new
|
8
|
+
@link.enc_type = "application/x-www-form-urlencoded"
|
9
|
+
@link.href = "/apps"
|
10
|
+
@link.media_type = "application/json"
|
11
|
+
@link.method = "GET"
|
12
|
+
@link.status_success = 200
|
13
|
+
@link.schema = { "title" => "input" }
|
14
|
+
@link.target_schema = { "title" => "target" }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "uses set #enc_type" do
|
18
|
+
assert_equal "application/x-www-form-urlencoded", @link.enc_type
|
19
|
+
end
|
20
|
+
|
21
|
+
it "uses set #href" do
|
22
|
+
assert_equal "/apps", @link.href
|
23
|
+
end
|
24
|
+
|
25
|
+
it "uses set #media_type" do
|
26
|
+
assert_equal "application/json", @link.media_type
|
27
|
+
end
|
28
|
+
|
29
|
+
it "uses set #method" do
|
30
|
+
assert_equal "GET", @link.method
|
31
|
+
end
|
32
|
+
|
33
|
+
it "proxies #rel" do
|
34
|
+
e = assert_raises do
|
35
|
+
@link.rel
|
36
|
+
end
|
37
|
+
assert_equal "Committee: rel not implemented for OpenAPI", e.message
|
38
|
+
end
|
39
|
+
|
40
|
+
it "uses set #schema" do
|
41
|
+
assert_equal({ "title" => "input" }, @link.schema)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "uses set #status_success" do
|
45
|
+
assert_equal 200, @link.status_success
|
46
|
+
end
|
47
|
+
|
48
|
+
it "uses set #target_schema" do
|
49
|
+
assert_equal({ "title" => "target" }, @link.target_schema)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|