2018-09-29 22:34:47 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-04 12:11:15 +00:00
|
|
|
module API
|
|
|
|
module Helpers
|
|
|
|
module CommonHelpers
|
|
|
|
def convert_parameters_from_legacy_format(params)
|
2017-05-08 14:58:42 +00:00
|
|
|
params.tap do |params|
|
2018-01-15 12:24:16 +00:00
|
|
|
assignee_id = params.delete(:assignee_id)
|
|
|
|
|
|
|
|
if assignee_id.present?
|
|
|
|
params[:assignee_ids] = [assignee_id]
|
2017-05-08 14:58:42 +00:00
|
|
|
end
|
2017-05-04 12:11:15 +00:00
|
|
|
end
|
|
|
|
end
|
2020-06-29 21:09:07 +00:00
|
|
|
|
|
|
|
# Grape v1.3.3 no longer automatically coerces an Array
|
|
|
|
# type to an empty array if the value is nil.
|
|
|
|
def coerce_nil_params_to_array!
|
|
|
|
keys_to_coerce = params_with_array_types
|
|
|
|
|
|
|
|
params.each do |key, val|
|
|
|
|
params[key] = Array(val) if val.nil? && keys_to_coerce.include?(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def params_with_array_types
|
|
|
|
options[:route_options][:params].map do |key, val|
|
|
|
|
param_type = val[:type]
|
|
|
|
# Search for parameters with Array types (e.g. "[String]", "[Integer]", etc.)
|
|
|
|
if param_type =~ %r(\[\w*\])
|
|
|
|
key
|
|
|
|
end
|
|
|
|
end.compact.to_set
|
|
|
|
end
|
2021-03-22 15:09:31 +00:00
|
|
|
|
|
|
|
def endpoint_id
|
2021-09-21 18:11:18 +00:00
|
|
|
::API::Base.endpoint_id_for_route(route)
|
2021-03-22 15:09:31 +00:00
|
|
|
end
|
2017-05-04 12:11:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-29 09:06:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
API::Helpers::CommonHelpers.prepend_mod_with('API::Helpers::CommonHelpers')
|