Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions committee.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "rubocop-performance"
s.add_development_dependency "simplecov"

s.metadata = {
"bug_tracker_uri" => "https://github.com/interagent/committee/issues",
"changelog_uri" => "https://github.com/interagent/committee/blob/master/CHANGELOG.md",
"rubygems_mfa_required" => "true",
"source_code_uri" => "https://github.com/interagent/committee"
}
s.metadata = { "bug_tracker_uri" => "https://github.com/interagent/committee/issues", "changelog_uri" => "https://github.com/interagent/committee/blob/master/CHANGELOG.md", "rubygems_mfa_required" => "true", "source_code_uri" => "https://github.com/interagent/committee" }
end
4 changes: 1 addition & 3 deletions lib/committee/drivers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def self.load_from_data(hash, schema_path = nil, parser_options: {})
# if it is not explicitly set. See: https://github.com/interagent/committee/issues/343#issuecomment-997400329
opts = parser_options.dup

Committee.warn_deprecated_until_6(!opts.key?(:strict_reference_validation), 'openapi_parser will default to strict reference validation ' +
'from next version. Pass config `strict_reference_validation: true` (or false, if you must) ' +
'to quiet this warning.')
Committee.warn_deprecated_until_6(!opts.key?(:strict_reference_validation), 'openapi_parser will default to strict reference validation ' + 'from next version. Pass config `strict_reference_validation: true` (or false, if you must) ' + 'to quiet this warning.')
opts[:strict_reference_validation] ||= false

openapi = OpenAPIParser.parse_with_filepath(hash, schema_path, opts)
Expand Down
15 changes: 2 additions & 13 deletions lib/committee/schema_validator/hyper_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ def coerce_query_params(request)
end

def request_unpack(request)
unpacker = Committee::RequestUnpacker.new(
allow_form_params: validator_option.allow_form_params,
allow_get_body: validator_option.allow_get_body,
allow_query_params: validator_option.allow_query_params,
allow_non_get_query_params: validator_option.allow_non_get_query_params,
optimistic_json: validator_option.optimistic_json,
)
unpacker = Committee::RequestUnpacker.new(allow_form_params: validator_option.allow_form_params, allow_get_body: validator_option.allow_get_body, allow_query_params: validator_option.allow_query_params, allow_non_get_query_params: validator_option.allow_non_get_query_params, optimistic_json: validator_option.optimistic_json,)

request.env[validator_option.headers_key] = unpacker.unpack_headers(request)

Expand Down Expand Up @@ -109,12 +103,7 @@ def request_schema_validation(request)
def parameter_coerce!(request, link, coerce_key)
return unless link_exist?

Committee::SchemaValidator::HyperSchema::ParameterCoercer.
new(request.env[coerce_key],
link.schema,
coerce_date_times: validator_option.coerce_date_times,
coerce_recursive: validator_option.coerce_recursive).
call!
Committee::SchemaValidator::HyperSchema::ParameterCoercer.new(request.env[coerce_key], link.schema, coerce_date_times: validator_option.coerce_date_times, coerce_recursive: validator_option.coerce_recursive).call!
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ def generate_properties(link, schema)
{}

else
raise(%{At "#{link.method} #{link.href}" "#{schema.pointer}": no } +
%{"example" attribute and "null" } +
%{is not allowed; don't know how to generate property.})
raise(%{At "#{link.method} #{link.href}" "#{schema.pointer}": no } + %{"example" attribute and "null" } + %{is not allowed; don't know how to generate property.})
end
end

Expand Down
13 changes: 2 additions & 11 deletions lib/committee/schema_validator/open_api_3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def response_validate(status, headers, response, test_method = false, custom_bod

# TODO: refactoring name
strict = test_method
Committee::SchemaValidator::OpenAPI3::ResponseValidator.
new(@operation_object, validator_option).
call(status, headers, data, strict)
Committee::SchemaValidator::OpenAPI3::ResponseValidator.new(@operation_object, validator_option).call(status, headers, data, strict)
end

def link_exist?
Expand Down Expand Up @@ -85,14 +83,7 @@ def header(request)
end

def request_unpack(request)
unpacker = Committee::RequestUnpacker.new(
allow_empty_date_and_datetime: validator_option.allow_empty_date_and_datetime,
allow_form_params: validator_option.allow_form_params,
allow_get_body: validator_option.allow_get_body,
allow_query_params: validator_option.allow_query_params,
allow_non_get_query_params: validator_option.allow_non_get_query_params,
optimistic_json: validator_option.optimistic_json,
)
unpacker = Committee::RequestUnpacker.new(allow_empty_date_and_datetime: validator_option.allow_empty_date_and_datetime, allow_form_params: validator_option.allow_form_params, allow_get_body: validator_option.allow_get_body, allow_query_params: validator_option.allow_query_params, allow_non_get_query_params: validator_option.allow_non_get_query_params, optimistic_json: validator_option.optimistic_json,)

request.env[validator_option.headers_key] = unpacker.unpack_headers(request)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def coerce_path_parameter(validator_option)
def validate_response_params(status_code, headers, response_data, strict, check_header, validator_options: {})
response_body = OpenAPIParser::RequestOperation::ValidatableResponseBody.new(status_code, response_data, headers)

return request_operation.validate_response_body(
response_body,
response_validate_options(strict, check_header, validator_options: validator_options))
return request_operation.validate_response_body(response_body, response_validate_options(strict, check_header, validator_options: validator_options))
rescue OpenAPIParser::OpenAPIError => e
raise Committee::InvalidResponse.new(e.message, original_error: e)
end
Expand Down
18 changes: 1 addition & 17 deletions lib/committee/schema_validator/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@ module Committee
module SchemaValidator
class Option
# Boolean Options
attr_reader :allow_blank_structures,
:allow_empty_date_and_datetime,
:allow_form_params,
:allow_get_body,
:allow_query_params,
:allow_non_get_query_params,
:check_content_type,
:check_header,
:coerce_date_times,
:coerce_form_params,
:coerce_path_params,
:coerce_query_params,
:coerce_recursive,
:optimistic_json,
:validate_success_only,
:parse_response_by_content_type,
:parameter_overwrite_by_rails_rule
attr_reader :allow_blank_structures, :allow_empty_date_and_datetime, :allow_form_params, :allow_get_body, :allow_query_params, :allow_non_get_query_params, :check_content_type, :check_header, :coerce_date_times, :coerce_form_params, :coerce_path_params, :coerce_query_params, :coerce_recursive, :optimistic_json, :validate_success_only, :parse_response_by_content_type, :parameter_overwrite_by_rails_rule

# Non-boolean options:
attr_reader :headers_key, :params_key, :query_hash_key, :request_body_hash_key, :path_hash_key, :prefix
Expand Down
20 changes: 4 additions & 16 deletions test/drivers/open_api_2/driver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
end

it "prefers a 200 response first" do
schema_data = schema_data_with_responses({
'201' => { 'schema' => { 'description' => '201 response' } },
'200' => { 'schema' => { 'description' => '200 response' } },
})
schema_data = schema_data_with_responses({ '201' => { 'schema' => { 'description' => '201 response' } }, '200' => { 'schema' => { 'description' => '200 response' } }, })

schema = @driver.parse(schema_data)
link = schema.routes['GET'][0][1]
Expand All @@ -62,10 +59,7 @@
end

it "prefers a 201 response next" do
schema_data = schema_data_with_responses({
'302' => { 'schema' => { 'description' => '302 response' } },
'201' => { 'schema' => { 'description' => '201 response' } },
})
schema_data = schema_data_with_responses({ '302' => { 'schema' => { 'description' => '302 response' } }, '201' => { 'schema' => { 'description' => '201 response' } }, })

schema = @driver.parse(schema_data)
link = schema.routes['GET'][0][1]
Expand All @@ -74,10 +68,7 @@
end

it "prefers any three-digit response next" do
schema_data = schema_data_with_responses({
'default' => { 'schema' => { 'description' => 'default response' } },
'302' => { 'schema' => { 'description' => '302 response' } },
})
schema_data = schema_data_with_responses({ 'default' => { 'schema' => { 'description' => 'default response' } }, '302' => { 'schema' => { 'description' => '302 response' } }, })

schema = @driver.parse(schema_data)
link = schema.routes['GET'][0][1]
Expand All @@ -86,10 +77,7 @@
end

it "prefers any numeric three-digit response next" do
schema_data = schema_data_with_responses({
'default' => { 'schema' => { 'description' => 'default response' } },
302 => { 'schema' => { 'description' => '302 response' } },
})
schema_data = schema_data_with_responses({ 'default' => { 'schema' => { 'description' => 'default response' } }, 302 => { 'schema' => { 'description' => '302 response' } }, })

schema = @driver.parse(schema_data)
link = schema.routes['GET'][0][1]
Expand Down
54 changes: 4 additions & 50 deletions test/drivers/open_api_2/parameter_schema_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,7 @@
end

it "reflects an array with an items schema into a schema" do
data = {
"parameters" => [
{
"name" => "tags",
"type" => "array",
"minItems" => 1,
"maxItems" => 10,
"uniqueItems" => true,
"items" => {
"type" => "string"
}
}
]
}
data = { "parameters" => [{ "name" => "tags", "type" => "array", "minItems" => 1, "maxItems" => 10, "uniqueItems" => true, "items" => { "type" => "string" } }] }
schema, schema_data = call(data)

assert_nil schema_data
Expand All @@ -71,18 +58,7 @@
end

it "reflects string properties into a schema" do
data = {
"parameters" => [
{
"name" => "password",
"type" => "string",
"format" => "password",
"pattern" => "[a-zA-Z0-9]+",
"minLength" => 6,
"maxLength" => 30
}
]
}
data = { "parameters" => [{ "name" => "password", "type" => "string", "format" => "password", "pattern" => "[a-zA-Z0-9]+", "minLength" => 6, "maxLength" => 30 }] }
schema, schema_data = call(data)

assert_nil schema_data
Expand All @@ -93,19 +69,7 @@
end

it "reflects number properties into a schema" do
data = {
"parameters" => [
{
"name" => "limit",
"type" => "integer",
"minimum" => 20,
"exclusiveMinimum" => true,
"maximum" => 100,
"exclusiveMaximum" => false,
"multipleOf" => 10
}
]
}
data = { "parameters" => [{ "name" => "limit", "type" => "integer", "minimum" => 20, "exclusiveMinimum" => true, "maximum" => 100, "exclusiveMaximum" => false, "multipleOf" => 10 }] }
schema, schema_data = call(data)

assert_nil schema_data
Expand All @@ -117,17 +81,7 @@
end

it "returns schema data for a body parameter" do
data = {
"parameters" => [
{
"name" => "payload",
"in" => "body",
"schema" => {
"$ref" => "#/definitions/foo",
}
}
]
}
data = { "parameters" => [{ "name" => "payload", "in" => "body", "schema" => { "$ref" => "#/definitions/foo", } }] }
schema, schema_data = call(data)

assert_nil schema
Expand Down
25 changes: 4 additions & 21 deletions test/drivers_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,18 @@
describe 'cache behavior' do
describe 'when loading the same file' do
it 'returns the same object when the options are identical' do
assert_equal(
Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id,
Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id,
)
assert_equal(Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id, Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id,)
end

it 'returns different objects if the options are different' do
refute_equal(
Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id,
Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: false }).object_id,
)
refute_equal(Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id, Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: false }).object_id,)
end

it 'returns different objects if the file contents have changed' do
object_id = Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id
original_file_contents = File.read(open_api_3_schema_path)
File.write(open_api_3_schema_path, original_file_contents + "\n")
refute_equal(
Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id,
object_id,
)
refute_equal(Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options: { strict_reference_validation: true }).object_id, object_id,)
File.write(open_api_3_schema_path, original_file_contents)
end
end
Expand Down Expand Up @@ -152,15 +143,7 @@
end

describe Committee::Drivers::Driver do
DRIVER_METHODS = {
default_allow_get_body: [],
default_coerce_form_params: [],
default_path_params: [],
default_query_params: [],
name: [],
parse: [nil],
schema_class: [],
}
DRIVER_METHODS = { default_allow_get_body: [], default_coerce_form_params: [], default_path_params: [], default_query_params: [], name: [], parse: [nil], schema_class: [], }

it "has a set of abstract methods" do
driver = Committee::Drivers::Driver.new
Expand Down
Loading