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 expires_in 24.hours, public: true
27 discovery = Rails.cache.fetch 'arvados_v1_rest_discovery' do
28 Rails.application.eager_load!
30 kind: "discovery#restDescription",
31 discoveryVersion: "v1",
36 generatedAt: Time.now.iso8601,
38 description: "The API to interact with Arvados.",
39 documentationLink: "https://redmine.clinicalfuture.com/projects/arvados/",
41 baseUrl: root_url + "/arvados/v1/",
42 basePath: "/arvados/v1/",
44 servicePath: "arvados/v1/",
49 description: "Data format for the response.",
55 "Responses with Content-Type of application/json"
61 description: "Selector specifying which fields to include in a partial response.",
66 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.",
71 description: "OAuth 2.0 token for the current user.",
78 "https://api.clinicalfuture.com/auth/arvados" => {
79 description: "View and manage objects"
81 "https://api.clinicalfuture.com/auth/arvados.readonly" => {
82 description: "View objects"
91 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
93 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
95 # No controller -> no discovery.
98 object_properties = {}
100 select { |col| col.name != 'id' }.
102 if k.serialized_attributes.has_key? col.name
103 object_properties[col.name] = {
104 type: k.serialized_attributes[col.name].object_class.to_s
107 object_properties[col.name] = {
112 discovery[:schemas][k.to_s + 'List'] = {
114 description: k.to_s + ' list',
119 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
120 default: "arvados##{k.to_s.camelcase(:lower)}List"
124 description: "List version."
128 description: "The list of #{k.to_s.pluralize}.",
135 description: "A link to the next page of #{k.to_s.pluralize}."
139 description: "The page token for the next page of #{k.to_s.pluralize}."
143 description: "A link back to this list."
147 discovery[:schemas][k.to_s] = {
154 description: "Object ID."
158 description: "Object version."
160 }.merge(object_properties)
162 discovery[:resources][k.to_s.underscore.pluralize] = {
165 id: "arvados.#{k.to_s.underscore.pluralize}.get",
166 path: "#{k.to_s.underscore.pluralize}/{uuid}",
168 description: "Gets a #{k.to_s}'s metadata by UUID.",
172 description: "The UUID of the #{k.to_s} in question.",
184 "https://api.clinicalfuture.com/auth/arvados",
185 "https://api.clinicalfuture.com/auth/arvados.readonly"
189 id: "arvados.#{k.to_s.underscore.pluralize}.list",
190 path: k.to_s.underscore.pluralize,
193 %|List #{k.to_s.pluralize}.
195 The <code>list</code> method returns a
196 <a href="/api/resources.html">resource list</a> of
197 matching #{k.to_s.pluralize}. For example:
201 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
204 "next_page_token":"",
209 "items_available":745,
211 "request_time":0.157236317
217 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
225 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
230 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
235 "$ref" => "#{k.to_s}List"
238 "https://api.clinicalfuture.com/auth/arvados",
239 "https://api.clinicalfuture.com/auth/arvados.readonly"
243 id: "arvados.#{k.to_s.underscore.pluralize}.create",
244 path: "#{k.to_s.underscore.pluralize}",
246 description: "Create a new #{k.to_s}.",
248 k.to_s.underscore => {
252 properties: object_properties
258 k.to_s.underscore => {
267 "https://api.clinicalfuture.com/auth/arvados"
271 id: "arvados.#{k.to_s.underscore.pluralize}.update",
272 path: "#{k.to_s.underscore.pluralize}/{uuid}",
274 description: "Update attributes of an existing #{k.to_s}.",
278 description: "The UUID of the #{k.to_s} in question.",
282 k.to_s.underscore => {
286 properties: object_properties
292 k.to_s.underscore => {
301 "https://api.clinicalfuture.com/auth/arvados"
305 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
306 path: "#{k.to_s.underscore.pluralize}/{uuid}",
307 httpMethod: "DELETE",
308 description: "Delete an existing #{k.to_s}.",
312 description: "The UUID of the #{k.to_s} in question.",
321 "https://api.clinicalfuture.com/auth/arvados"
326 # Check for Rails routes that don't match the usual actions
328 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
329 Rails.application.routes.routes.each do |route|
330 action = route.defaults[:action]
331 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
332 method if route.verb.match(method)
335 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
336 !d_methods[action.to_sym] and
337 ctl_class.action_methods.include? action
339 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
340 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
341 httpMethod: httpMethod,
342 description: "#{route.defaults[:action]} #{k.to_s.underscore.pluralize}",
345 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
348 "https://api.clinicalfuture.com/auth/arvados"
351 route.segment_keys.each do |key|
353 key = :uuid if key == :id
354 method[:parameters][key] = {
362 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
363 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
365 method[:parameters][k] = v
367 method[:parameters][k] = {}
369 method[:parameters][k][:type] ||= 'string'
370 method[:parameters][k][:description] ||= ''
371 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
372 if method[:parameters][k][:required].nil?
373 method[:parameters][k][:required] = v != false
377 d_methods[route.defaults[:action].to_sym] = method
383 render json: discovery