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
2 changes: 1 addition & 1 deletion lib/committee/schema_validator/open_api_3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def request_unpack(request)
query_values = validator_option.allow_query_params ? Rack::Utils.parse_query(request.query_string, '&') : {}
# Do not restore query values that were overridden by the request body.
query_values.reject! { |name, _| request.POST.key?(name) } if validator_option.allow_non_get_query_params
query_values.reject! { |name, _| request_param.key?(name) } if request.get? && validator_option.allow_get_body
query_values.reject! { |name, _| request_param.key?(name) } if request.get? && validator_option.allow_get_body && request_param.is_a?(Hash)
query_param = deserializer.deserialize_query_params(query_param, query_values)

headers = request.env[validator_option.headers_key]
Expand Down
24 changes: 24 additions & 0 deletions test/middleware/request_validation_open_api_3_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ def app
assert_equal 400, last_response.status
end

[
['application/json', '[1,2]', [1, 2], { 'type' => 'array', 'items' => { 'type' => 'integer' } }],
['text/plain', 'hello', 'hello', { 'type' => 'string' }],
].each do |content_type, body, expected_body, body_schema|
it "preserves query parameters with an allowed GET #{content_type} body" do
parameter = { 'name' => 'ids', 'in' => 'query', 'required' => true, 'schema' => { 'type' => 'array', 'items' => { 'type' => 'integer' } }, }
document = query_param_document(parameter)
document['paths']['/events']['get']['requestBody'] = { 'required' => true, 'content' => { content_type => { 'schema' => body_schema } } }
schema = Committee::Drivers.load_from_data(document, nil, parser_options: { strict_reference_validation: true })
check_parameter = lambda { |env|
assert_equal expected_body, env['committee.request_body_hash']
assert_equal [3, 4], env['committee.query_hash']['ids']
assert_equal({ 'ids' => [3, 4] }, env['committee.params'])
assert_equal body, env['rack.input'].read
[200, {}, []]
}
@app = new_rack_app_with_lambda(check_parameter, schema: schema, allow_get_body: true)

get '/events?ids=3&ids=4', {}, { input: body, 'CONTENT_TYPE' => content_type }

assert_equal 200, last_response.status, last_response.body
end
end

it "not parameter request" do
check_parameter_string = lambda { |_|
[200, { integer: 1 }, []]
Expand Down
Loading