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",
36 description: "The API to interact with Arvados.",
37 documentationLink: "https://redmine.clinicalfuture.com/projects/arvados/",
39 baseUrl: root_url + "/arvados/v1/",
40 basePath: "/arvados/v1/",
42 servicePath: "arvados/v1/",
47 description: "Data format for the response.",
53 "Responses with Content-Type of application/json"
59 description: "Selector specifying which fields to include in a partial response.",
64 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.",
69 description: "OAuth 2.0 token for the current user.",
76 "https://api.clinicalfuture.com/auth/arvados" => {
77 description: "View and manage objects"
79 "https://api.clinicalfuture.com/auth/arvados.readonly" => {
80 description: "View objects"
89 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
91 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
93 # No controller -> no discovery.
96 object_properties = {}
98 select { |col| col.name != 'id' }.
100 if k.serialized_attributes.has_key? col.name
101 object_properties[col.name] = {
102 type: k.serialized_attributes[col.name].object_class.to_s
105 object_properties[col.name] = {
110 discovery[:schemas][k.to_s + 'List'] = {
112 description: k.to_s + ' list',
117 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
118 default: "arvados##{k.to_s.camelcase(:lower)}List"
122 description: "List version."
126 description: "The list of #{k.to_s.pluralize}.",
133 description: "A link to the next page of #{k.to_s.pluralize}."
137 description: "The page token for the next page of #{k.to_s.pluralize}."
141 description: "A link back to this list."
145 discovery[:schemas][k.to_s] = {
152 description: "Object ID."
156 description: "Object version."
158 }.merge(object_properties)
160 discovery[:resources][k.to_s.underscore.pluralize] = {
163 id: "arvados.#{k.to_s.underscore.pluralize}.get",
164 path: "#{k.to_s.underscore.pluralize}/{uuid}",
166 description: "Gets a #{k.to_s}'s metadata by UUID.",
170 description: "The UUID of the #{k.to_s} in question.",
182 "https://api.clinicalfuture.com/auth/arvados",
183 "https://api.clinicalfuture.com/auth/arvados.readonly"
187 id: "arvados.#{k.to_s.underscore.pluralize}.list",
188 path: k.to_s.underscore.pluralize,
190 description: "List #{k.to_s.underscore.pluralize}.",
194 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
202 description: "Page token.",
207 description: "Query string for searching #{k.to_s.underscore.pluralize}.",
212 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
217 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
222 "$ref" => "#{k.to_s}List"
225 "https://api.clinicalfuture.com/auth/arvados",
226 "https://api.clinicalfuture.com/auth/arvados.readonly"
230 id: "arvados.#{k.to_s.underscore.pluralize}.create",
231 path: "#{k.to_s.underscore.pluralize}",
233 description: "Create a new #{k.to_s}.",
235 k.to_s.underscore => {
239 properties: object_properties
246 "https://api.clinicalfuture.com/auth/arvados"
250 id: "arvados.#{k.to_s.underscore.pluralize}.update",
251 path: "#{k.to_s.underscore.pluralize}/{uuid}",
253 description: "Update attributes of an existing #{k.to_s}.",
257 description: "The UUID of the #{k.to_s} in question.",
261 k.to_s.underscore => {
265 properties: object_properties
272 "https://api.clinicalfuture.com/auth/arvados"
276 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
277 path: "#{k.to_s.underscore.pluralize}/{uuid}",
278 httpMethod: "DELETE",
279 description: "Delete an existing #{k.to_s}.",
283 description: "The UUID of the #{k.to_s} in question.",
292 "https://api.clinicalfuture.com/auth/arvados"
297 # Check for Rails routes that don't match the usual actions
299 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
300 Rails.application.routes.routes.each do |route|
301 action = route.defaults[:action]
302 httpMethod = (route.verb && route.verb.length > 0) ? route.verb : 'GET'
303 if route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
304 !d_methods[action.to_sym] and
305 ctl_class.action_methods.include? action
307 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
308 path: route.path.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
309 httpMethod: httpMethod,
310 description: "#{route.defaults[:action]} #{k.to_s.underscore.pluralize}",
313 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
316 "https://api.clinicalfuture.com/auth/arvados"
319 route.segment_keys.each do |key|
321 key = :uuid if key == :id
322 method[:parameters][key] = {
330 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
331 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
333 method[:parameters][k] = v
335 method[:parameters][k] = {}
337 method[:parameters][k][:type] ||= 'string'
338 method[:parameters][k][:description] ||= ''
339 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
340 if method[:parameters][k][:required].nil?
341 method[:parameters][k][:required] = v != false
345 d_methods[route.defaults[:action].to_sym] = method
351 render json: discovery