diff --git a/lib/committee/schema_validator/open_api_3.rb b/lib/committee/schema_validator/open_api_3.rb index 0d8b7c27..13c23363 100644 --- a/lib/committee/schema_validator/open_api_3.rb +++ b/lib/committee/schema_validator/open_api_3.rb @@ -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) diff --git a/lib/committee/schema_validator/open_api_3/operation_wrapper.rb b/lib/committee/schema_validator/open_api_3/operation_wrapper.rb index 00fce1bd..908ba0d0 100644 --- a/lib/committee/schema_validator/open_api_3/operation_wrapper.rb +++ b/lib/committee/schema_validator/open_api_3/operation_wrapper.rb @@ -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)