2020-10-14 20:08:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
class Base < Grape::API::Instance # rubocop:disable API/Base
|
2021-09-28 08:11:10 -04:00
|
|
|
include ::Gitlab::EndpointAttributes
|
2020-10-26 14:08:27 -04:00
|
|
|
|
|
|
|
class << self
|
|
|
|
def feature_category_for_app(app)
|
|
|
|
feature_category_for_action(path_for_app(app))
|
|
|
|
end
|
|
|
|
|
2021-10-05 08:12:58 -04:00
|
|
|
def urgency_for_app(app)
|
|
|
|
urgency_for_action(path_for_app(app))
|
2021-09-28 08:11:10 -04:00
|
|
|
end
|
|
|
|
|
2020-10-26 14:08:27 -04:00
|
|
|
def path_for_app(app)
|
|
|
|
normalize_path(app.namespace, app.options[:path].first)
|
|
|
|
end
|
|
|
|
|
2021-09-21 14:11:18 -04:00
|
|
|
def endpoint_id_for_route(route)
|
|
|
|
"#{route.request_method} #{route.origin}"
|
|
|
|
end
|
|
|
|
|
2020-10-26 14:08:27 -04:00
|
|
|
def route(methods, paths = ['/'], route_options = {}, &block)
|
2021-09-28 08:11:10 -04:00
|
|
|
actions = Array(paths).map { |path| normalize_path(namespace, path) }
|
2020-10-26 14:08:27 -04:00
|
|
|
if category = route_options.delete(:feature_category)
|
2021-09-28 08:11:10 -04:00
|
|
|
feature_category(category, actions)
|
|
|
|
end
|
|
|
|
|
2021-10-05 08:12:58 -04:00
|
|
|
if target = route_options.delete(:urgency)
|
|
|
|
urgency(target, actions)
|
2020-10-26 14:08:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def normalize_path(namespace, path)
|
|
|
|
[namespace.presence, path.to_s.chomp('/').presence].compact.join('/')
|
|
|
|
end
|
|
|
|
end
|
2020-10-14 20:08:42 -04:00
|
|
|
end
|
|
|
|
end
|