diff --git a/CHANGELOG.md b/CHANGELOG.md index e18eba809..3c7d9d49c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - OpenAPI users endpoint offer ability to filter by created_after - Fix a bug: providing an array of attributes to filter OpenApi data, results in error - Fix a bug: unable to manage stocks on new products +- Fix a bug: unsupported param[] syntax in OpenAPI - Updated react-modal to 3.16.1 - Updated tiptap editor and its dependencies to 2.0.0-beta.204 - [TODO DEPLOY] `rails fablab:setup:build_accounting_lines` diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 954945ebf..f6302438b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -85,6 +85,8 @@ module ApplicationHelper # Return the given parameter as it, or as an array if it can be parsed as an array def may_array(param) + return param if param.is_a?(Array) + return param unless param&.chars&.first == '[' && param&.chars&.last == ']' param.gsub(/[\[\]]/i, '').split(',') diff --git a/test/integration/open_api/users_test.rb b/test/integration/open_api/users_test.rb index 494d1b63a..40eb80e7e 100644 --- a/test/integration/open_api/users_test.rb +++ b/test/integration/open_api/users_test.rb @@ -38,6 +38,16 @@ class OpenApi::UsersTest < ActionDispatch::IntegrationTest assert(users[:users].all? { |user| [3, 4, 5].include?(user[:id]) }) end + test 'list all users filtering by IDs other syntax' do + get '/open_api/v1/users?user_id[]=3&user_id[]=4&user_id[]=5', headers: open_api_headers(@token) + assert_response :success + assert_equal Mime[:json], response.content_type + + users = json_response(response.body) + assert users[:users].count.positive? + assert(users[:users].all? { |user| [3, 4, 5].include?(user[:id]) }) + end + test 'list a user filtering by ID' do get '/open_api/v1/users?user_id=2', headers: open_api_headers(@token) assert_response :success