aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/apidocs_controller.rb
blob: 8b8fab8c505384b28628d51e4c6e3789c777a9e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class ApidocsController < ApplicationController
  def all
    apidocs = Rails.cache.fetch("apidocs/all") do
      nss = {}
      Api.routes.each { |route|
        next if route.route_nodoc
        next if route.route_method == "HEAD"
        namespace = route.route_namespace.sub(/^\//, "")
        nss[namespace] ||= []
        nss[namespace] << { method: route.route_method,
                            description: route.route_description,
                            path: route.route_path.sub(/^\//, "").sub(/\(\.:format\)$/, ""),
                            params: route.route_params.map { |n, o| [n, { required: o[:required], description: o[:desc], type: o[:type] }] }.to_h,
                            example_params: route.route_example_params,
        }
      }
      nss
    end

    render_json data: { namespaces: apidocs }
  end
end