Merge branch '9964-output-glob-acr' refs #9964
[arvados.git] / services / api / app / controllers / arvados / v1 / schema_controller.rb
index 0a0e664b0995762c0ee4a0573762c82d3967214a..f1184571573620867fa6e43e9223550e5ea1038d 100644 (file)
@@ -23,6 +23,12 @@ class Arvados::V1::SchemaController < ApplicationController
 
   protected
 
+  ActionNameMap = {
+    'destroy' => 'delete',
+    'index' => 'list',
+    'show' => 'get',
+  }
+
   def discovery_doc
     Rails.application.eager_load!
     remoteHosts = {}
@@ -216,14 +222,14 @@ class Arvados::V1::SchemaController < ApplicationController
               "https://api.arvados.org/auth/arvados.readonly"
             ]
           },
-          index: {
-            id: "arvados.#{k.to_s.underscore.pluralize}.index",
+          list: {
+            id: "arvados.#{k.to_s.underscore.pluralize}.list",
             path: k.to_s.underscore.pluralize,
             httpMethod: "GET",
             description:
-              %|Index #{k.to_s.pluralize}.
+              %|List #{k.to_s.pluralize}.
 
-                   The <code>index</code> method returns a
+                   The <code>list</code> method returns a
                    <a href="/api/resources.html">resource list</a> of
                    matching #{k.to_s.pluralize}. For example:
 
@@ -331,18 +337,20 @@ class Arvados::V1::SchemaController < ApplicationController
         httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
           method if route.verb.match(method)
         }.compact.first
-        if httpMethod and
-          route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
-          ctl_class.action_methods.include? action
-          if !d_methods[action.to_sym]
+        if httpMethod &&
+          route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize &&
+          ctl_class.action_methods.include?(action)
+          method_name = ActionNameMap[action] || action
+          method_key = method_name.to_sym
+          if !d_methods[method_key]
             method = {
-              id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
+              id: "arvados.#{k.to_s.underscore.pluralize}.#{method_name}",
               path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
               httpMethod: httpMethod,
-              description: "#{action} #{k.to_s.underscore.pluralize}",
+              description: "#{method_name} #{k.to_s.underscore.pluralize}",
               parameters: {},
               response: {
-                "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
+                "$ref" => (method_name == 'list' ? "#{k.to_s}List" : k.to_s)
               },
               scopes: [
                 "https://api.arvados.org/auth/arvados"
@@ -363,7 +371,7 @@ class Arvados::V1::SchemaController < ApplicationController
             # We already built a generic method description, but we
             # might find some more required parameters through
             # introspection.
-            method = d_methods[action.to_sym]
+            method = d_methods[method_key]
           end
           if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
             ctl_class.send("_#{action}_requires_parameters".to_sym).each do |l, v|
@@ -384,15 +392,7 @@ class Arvados::V1::SchemaController < ApplicationController
               end
             end
           end
-          d_methods[action.to_sym] = method
-
-          if action == 'index'
-            list_method = method.dup
-            list_method[:id].sub!('index', 'list')
-            list_method[:description].sub!('Index', 'List')
-            list_method[:description].sub!('index', 'list')
-            d_methods[:list] = list_method
-          end
+          d_methods[method_key] = method
         end
       end
     end