Skip to content

Commit

Permalink
Rename options from permit_blank_structures to allow_blank_structures
Browse files Browse the repository at this point in the history
  • Loading branch information
chibicco committed May 11, 2024
1 parent d1488a8 commit 6de7583
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/committee/schema_validator/hyper_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def response_validate(status, headers, response, _test_method = false)
data = JSON.parse(full_body) if parse_to_json
end

Committee::SchemaValidator::HyperSchema::ResponseValidator.new(link, validate_success_only: validator_option.validate_success_only, permit_blank_structures: validator_option.permit_blank_structures).call(status, headers, data)
Committee::SchemaValidator::HyperSchema::ResponseValidator.new(link, validate_success_only: validator_option.validate_success_only, allow_blank_structures: validator_option.allow_blank_structures).call(status, headers, data)
end

def link_exist?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module Committee
module SchemaValidator
class HyperSchema
class ResponseValidator
attr_reader :validate_success_only, :permit_blank_structures
attr_reader :allow_blank_structures, :validate_success_only

def initialize(link, options = {})
@link = link
@validate_success_only = options[:validate_success_only]
@permit_blank_structures = options[:permit_blank_structures]
@allow_blank_structures = options[:allow_blank_structures]

@validator = JsonSchema::Validator.new(target_schema(link))
end
Expand Down Expand Up @@ -40,7 +40,7 @@ def call(status, headers, data)
return if data == nil
end

if permit_blank_structures && @link.is_a?(Committee::Drivers::OpenAPI2::Link) && !@link.target_schema
if allow_blank_structures && @link.is_a?(Committee::Drivers::OpenAPI2::Link) && !@link.target_schema
return if data.nil?
end

Expand Down
8 changes: 4 additions & 4 deletions lib/committee/schema_validator/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module Committee
module SchemaValidator
class Option
# Boolean Options
attr_reader :allow_form_params,
attr_reader :allow_blank_structures,
:allow_form_params,
:allow_get_body,
:allow_query_params,
:check_content_type,
Expand All @@ -17,8 +18,7 @@ class Option
:optimistic_json,
:validate_success_only,
:parse_response_by_content_type,
:parameter_overwite_by_rails_rule,
:permit_blank_structures
:parameter_overwite_by_rails_rule

# Non-boolean options:
attr_reader :headers_key,
Expand All @@ -39,6 +39,7 @@ def initialize(options, schema, schema_type)
@prefix = options[:prefix]

# Boolean options and have a common value by default
@allow_blank_structures = options.fetch(:allow_blank_structures, false)
@allow_form_params = options.fetch(:allow_form_params, true)
@allow_query_params = options.fetch(:allow_query_params, true)
@check_content_type = options.fetch(:check_content_type, true)
Expand All @@ -47,7 +48,6 @@ def initialize(options, schema, schema_type)
@optimistic_json = options.fetch(:optimistic_json, false)
@parse_response_by_content_type = options.fetch(:parse_response_by_content_type, true)
@parameter_overwite_by_rails_rule = options.fetch(:parameter_overwite_by_rails_rule, true)
@permit_blank_structures = options.fetch(:permit_blank_structures, false)

# Boolean options and have a different value by default
@allow_get_body = options.fetch(:allow_get_body, schema.driver.default_allow_get_body)
Expand Down
12 changes: 6 additions & 6 deletions test/middleware/response_validation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,24 @@ def app
assert_equal 200, last_response.status
end

it "passes through a valid response for OpenAPI when data=nil, target_schema=empty, permit_blank_structures=true" do
it "passes through a valid response for OpenAPI when data=nil, target_schema=empty, allow_blank_structures=true" do
@app = new_rack_app("null", {},
permit_blank_structures: true, schema: open_api_2_schema)
allow_blank_structures: true, schema: open_api_2_schema)
get "/api/pets/cat"
assert_equal 200, last_response.status
end

it "invalid responses for OpenAPI when data=nil, target_schema=empty, permit_blank_structures=false" do
it "invalid responses for OpenAPI when data=nil, target_schema=empty, allow_blank_structures=false" do
@app = new_rack_app("null", {},
permit_blank_structures: false, schema: open_api_2_schema)
allow_blank_structures: false, schema: open_api_2_schema)
get "/api/pets/cat"
assert_equal 500, last_response.status
assert_match(/Invalid response/i, last_response.body)
end

it "passes through a valid response for OpenAPI when data=nil, target_schema=present, permit_blank_structures=true" do
it "passes through a valid response for OpenAPI when data=nil, target_schema=present, allow_blank_structures=true" do
@app = new_rack_app("null", {},
permit_blank_structures: true, schema: open_api_2_schema)
allow_blank_structures: true, schema: open_api_2_schema)
get "/api/pets/dog"
assert_equal 500, last_response.status
assert_match(/nil is not an array/i, last_response.body)
Expand Down

0 comments on commit 6de7583

Please sign in to comment.