1 class Arvados::V1::SchemaController < ApplicationController
2 skip_before_filter :find_object_by_uuid
3 skip_before_filter :require_auth_scope_all
6 classes = Rails.cache.fetch 'arvados_v1_schema' do
7 Rails.application.eager_load!
9 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
10 classes[k] = k.columns.collect do |col|
11 if k.serialized_attributes.has_key? col.name
13 type: k.serialized_attributes[col.name].object_class.to_s }
25 def discovery_rest_description
26 discovery = Rails.cache.fetch 'arvados_v1_rest_discovery' do
27 Rails.application.eager_load!
29 kind: "discovery#restDescription",
30 discoveryVersion: "v1",
35 generatedAt: Time.now.iso8601,
37 description: "The API to interact with Arvados.",
38 documentationLink: "https://redmine.clinicalfuture.com/projects/arvados/",
40 baseUrl: root_url + "/arvados/v1/",
41 basePath: "/arvados/v1/",
43 servicePath: "arvados/v1/",
48 description: "Data format for the response.",
54 "Responses with Content-Type of application/json"
60 description: "Selector specifying which fields to include in a partial response.",
65 description: "API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.",
70 description: "OAuth 2.0 token for the current user.",
77 "https://api.clinicalfuture.com/auth/arvados" => {
78 description: "View and manage objects"
80 "https://api.clinicalfuture.com/auth/arvados.readonly" => {
81 description: "View objects"
90 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
92 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
94 # No controller -> no discovery.
97 object_properties = {}
99 select { |col| col.name != 'id' }.
101 if k.serialized_attributes.has_key? col.name
102 object_properties[col.name] = {
103 type: k.serialized_attributes[col.name].object_class.to_s
106 object_properties[col.name] = {
111 discovery[:schemas][k.to_s + 'List'] = {
113 description: k.to_s + ' list',
118 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
119 default: "arvados##{k.to_s.camelcase(:lower)}List"
123 description: "List version."
127 description: "The list of #{k.to_s.pluralize}.",
134 description: "A link to the next page of #{k.to_s.pluralize}."
138 description: "The page token for the next page of #{k.to_s.pluralize}."
142 description: "A link back to this list."
146 discovery[:schemas][k.to_s] = {
153 description: "Object ID."
157 description: "Object version."
159 }.merge(object_properties)
161 discovery[:resources][k.to_s.underscore.pluralize] = {
164 id: "arvados.#{k.to_s.underscore.pluralize}.get",
165 path: "#{k.to_s.underscore.pluralize}/{uuid}",
167 description: "Gets a #{k.to_s}'s metadata by UUID.",
171 description: "The UUID of the #{k.to_s} in question.",
183 "https://api.clinicalfuture.com/auth/arvados",
184 "https://api.clinicalfuture.com/auth/arvados.readonly"
188 id: "arvados.#{k.to_s.underscore.pluralize}.list",
189 path: k.to_s.underscore.pluralize,
191 description: "List #{k.to_s.underscore.pluralize}.",
195 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
203 description: "Page token.",
208 description: "Query string for searching #{k.to_s.underscore.pluralize}.",
213 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
218 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
223 "$ref" => "#{k.to_s}List"
226 "https://api.clinicalfuture.com/auth/arvados",
227 "https://api.clinicalfuture.com/auth/arvados.readonly"
231 id: "arvados.#{k.to_s.underscore.pluralize}.create",
232 path: "#{k.to_s.underscore.pluralize}",
234 description: "Create a new #{k.to_s}.",
236 k.to_s.underscore => {
240 properties: object_properties
255 "https://api.clinicalfuture.com/auth/arvados"
259 id: "arvados.#{k.to_s.underscore.pluralize}.update",
260 path: "#{k.to_s.underscore.pluralize}/{uuid}",
262 description: "Update attributes of an existing #{k.to_s}.",
266 description: "The UUID of the #{k.to_s} in question.",
270 k.to_s.underscore => {
274 properties: object_properties
289 "https://api.clinicalfuture.com/auth/arvados"
293 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
294 path: "#{k.to_s.underscore.pluralize}/{uuid}",
295 httpMethod: "DELETE",
296 description: "Delete an existing #{k.to_s}.",
300 description: "The UUID of the #{k.to_s} in question.",
309 "https://api.clinicalfuture.com/auth/arvados"
314 # Check for Rails routes that don't match the usual actions
316 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
317 Rails.application.routes.routes.each do |route|
318 action = route.defaults[:action]
319 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
320 method if route.verb.match(method)
323 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
324 !d_methods[action.to_sym] and
325 ctl_class.action_methods.include? action
327 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
328 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
329 httpMethod: httpMethod,
330 description: "#{route.defaults[:action]} #{k.to_s.underscore.pluralize}",
333 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
336 "https://api.clinicalfuture.com/auth/arvados"
339 route.segment_keys.each do |key|
341 key = :uuid if key == :id
342 method[:parameters][key] = {
350 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
351 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
353 method[:parameters][k] = v
355 method[:parameters][k] = {}
357 method[:parameters][k][:type] ||= 'string'
358 method[:parameters][k][:description] ||= ''
359 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
360 if method[:parameters][k][:required].nil?
361 method[:parameters][k][:required] = v != false
365 d_methods[route.defaults[:action].to_sym] = method
371 render json: discovery