Skip to content

Commit

Permalink
support cases where the request parameter is not a hash
Browse files Browse the repository at this point in the history
  • Loading branch information
ryu-sato committed Jan 22, 2023
1 parent 9fdc6b9 commit 2bc8b67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/committee/schema_validator/open_api_3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ def request_unpack(request)
request.env[validator_option.path_hash_key] = coerce_path_params

query_param = unpacker.unpack_query_params(request)
param_matches_hash = request.env[validator_option.path_hash_key]

request.env[validator_option.params_key] = Committee::Utils.indifferent_hash
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(query_param))
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(request.env[validator_option.request_body_hash_key]))
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(request.env[validator_option.path_hash_key]))
raise BadRequest, "Invalid JSON input. Require object with parameters as keys when path parameter exists." if !request_param.is_a?(Hash) && (query_param != {} || param_matches_hash != {})

request.env[validator_option.params_key] = Committee::Utils.deep_copy(request_param) || Committee::Utils.indifferent_hash
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(query_param)) if query_param != {}
request.env[validator_option.params_key].merge!(Committee::Utils.deep_copy(param_matches_hash)) if param_matches_hash != {}
end

def copy_coerced_data_to_query_hash(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def validate_post_request_params(params, headers, validator_option)

# bad performance because when we coerce value, same check
schema_validator_options = build_openapi_parser_post_option(validator_option)
request_operation.validate_request_parameter(params, headers, schema_validator_options)
request_operation.validate_request_parameter(params, headers, schema_validator_options) if params.is_a?(Hash)
request_operation.validate_request_body(content_type, params, schema_validator_options)
rescue => e
raise Committee::InvalidRequest.new(e.message, original_error: e)
Expand Down

0 comments on commit 2bc8b67

Please sign in to comment.