debian-mirror-gitlab/lib/api/helpers/common_helpers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module API
module Helpers
module CommonHelpers
def convert_parameters_from_legacy_format(params)
params.tap do |params|
2018-03-17 18:26:18 +05:30
assignee_id = params.delete(:assignee_id)
if assignee_id.present?
params[:assignee_ids] = [assignee_id]
2017-08-17 22:00:37 +05:30
end
end
end
2020-07-28 23:09:34 +05:30
# 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-04-29 21:17:54 +05:30
def endpoint_id
2021-11-18 22:05:49 +05:30
::API::Base.endpoint_id_for_route(route)
2021-04-29 21:17:54 +05:30
end
2017-08-17 22:00:37 +05:30
end
end
end
2020-01-01 13:55:28 +05:30
2021-06-08 01:23:25 +05:30
API::Helpers::CommonHelpers.prepend_mod_with('API::Helpers::CommonHelpers')