Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ def convert_to_indifferent_hash(hash)
# @return [Hash]
def normalize_raw_params(raw_params, location, params_for_location)
return raw_params unless location == 'query'

normalized = raw_params
params_for_location.each do |param_def|
next unless param_def.name.end_with?('[]') && param_def.schema&.type == 'array'

raw_name = param_def.name.delete_suffix('[]')
next unless normalized[raw_name].is_a?(Array)

normalized = raw_params.dup if normalized.equal?(raw_params)
normalized[param_def.name] = normalized.delete(raw_name)
end

raw_params = normalized
return raw_params unless raw_params.values.any? { |value| value.is_a?(Hash) }
return raw_params unless requires_query_param_flattening?(params_for_location)

Expand Down
14 changes: 14 additions & 0 deletions test/middleware/request_validation_open_api_3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,20 @@ def app
end

describe 'bracket-style query params' do
it 'deserializes array params whose name ends with brackets' do
parameter = { 'name' => 'ids[]', 'in' => 'query', 'required' => true, 'schema' => { 'type' => 'array', 'items' => { 'type' => 'integer' } }, }
check_parameter = lambda { |env|
assert_equal [1, 2], env['committee.query_hash']['ids[]']
assert_equal ['1', '2'], env['rack.request.query_hash']['ids']
[200, {}, []]
}
@app = new_rack_app_with_lambda(check_parameter, schema: query_param_schema(parameter))

get '/events?ids[]=1&ids[]=2'

assert_equal 200, last_response.status
end

it 'validates query params declared with bracket notation names' do
check_parameter = lambda { |env|
assert_equal '/test', env['committee.query_hash']['filter[slug]']
Expand Down
Loading