1 class Arvados::V1::SchemaController < ApplicationController
2 skip_before_filter :find_objects_for_index
3 skip_before_filter :find_object_by_uuid
4 skip_before_filter :render_404_if_no_object
5 skip_before_filter :require_auth_scope
8 expires_in 24.hours, public: true
9 discovery = Rails.cache.fetch 'arvados_v1_rest_discovery' do
10 Rails.application.eager_load!
12 kind: "discovery#restDescription",
13 discoveryVersion: "v1",
18 generatedAt: Time.now.iso8601,
20 description: "The API to interact with Arvados.",
21 documentationLink: "http://doc.arvados.org/api/index.html",
23 baseUrl: root_url + "arvados/v1/",
24 basePath: "/arvados/v1/",
26 servicePath: "arvados/v1/",
31 description: "Data format for the response.",
37 "Responses with Content-Type of application/json"
43 description: "Selector specifying which fields to include in a partial response.",
48 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.",
53 description: "OAuth 2.0 token for the current user.",
60 "https://api.clinicalfuture.com/auth/arvados" => {
61 description: "View and manage objects"
63 "https://api.clinicalfuture.com/auth/arvados.readonly" => {
64 description: "View objects"
73 if Rails.application.config.websocket_address
74 discovery[:websocketUrl] = Rails.application.config.websocket_address
75 elsif ENV['ARVADOS_WEBSOCKETS']
76 discovery[:websocketUrl] = (root_url.sub /^http/, 'ws') + "websocket"
79 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
81 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
83 # No controller -> no discovery.
86 object_properties = {}
88 select { |col| col.name != 'id' }.
90 if k.serialized_attributes.has_key? col.name
91 object_properties[col.name] = {
92 type: k.serialized_attributes[col.name].object_class.to_s
95 object_properties[col.name] = {
100 discovery[:schemas][k.to_s + 'List'] = {
102 description: k.to_s + ' list',
107 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
108 default: "arvados##{k.to_s.camelcase(:lower)}List"
112 description: "List version."
116 description: "The list of #{k.to_s.pluralize}.",
123 description: "A link to the next page of #{k.to_s.pluralize}."
127 description: "The page token for the next page of #{k.to_s.pluralize}."
131 description: "A link back to this list."
135 discovery[:schemas][k.to_s] = {
139 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
143 description: "Object ID."
147 description: "Object version."
149 }.merge(object_properties)
151 discovery[:resources][k.to_s.underscore.pluralize] = {
154 id: "arvados.#{k.to_s.underscore.pluralize}.get",
155 path: "#{k.to_s.underscore.pluralize}/{uuid}",
157 description: "Gets a #{k.to_s}'s metadata by UUID.",
161 description: "The UUID of the #{k.to_s} in question.",
173 "https://api.clinicalfuture.com/auth/arvados",
174 "https://api.clinicalfuture.com/auth/arvados.readonly"
178 id: "arvados.#{k.to_s.underscore.pluralize}.list",
179 path: k.to_s.underscore.pluralize,
182 %|List #{k.to_s.pluralize}.
184 The <code>list</code> method returns a
185 <a href="/api/resources.html">resource list</a> of
186 matching #{k.to_s.pluralize}. For example:
190 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
193 "next_page_token":"",
198 "items_available":745,
200 "request_time":0.157236317
206 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
214 description: "Number of #{k.to_s.underscore.pluralize} to skip before first returned record.",
222 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
227 description: "Conditions for filtering #{k.to_s.underscore.pluralize}. (Deprecated. Use filters instead.)",
232 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
237 description: "Select which fields to return",
242 description: "Return each distinct object",
247 "$ref" => "#{k.to_s}List"
250 "https://api.clinicalfuture.com/auth/arvados",
251 "https://api.clinicalfuture.com/auth/arvados.readonly"
255 id: "arvados.#{k.to_s.underscore.pluralize}.create",
256 path: "#{k.to_s.underscore.pluralize}",
258 description: "Create a new #{k.to_s}.",
263 k.to_s.underscore => {
272 "https://api.clinicalfuture.com/auth/arvados"
276 id: "arvados.#{k.to_s.underscore.pluralize}.update",
277 path: "#{k.to_s.underscore.pluralize}/{uuid}",
279 description: "Update attributes of an existing #{k.to_s}.",
283 description: "The UUID of the #{k.to_s} in question.",
291 k.to_s.underscore => {
300 "https://api.clinicalfuture.com/auth/arvados"
304 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
305 path: "#{k.to_s.underscore.pluralize}/{uuid}",
306 httpMethod: "DELETE",
307 description: "Delete an existing #{k.to_s}.",
311 description: "The UUID of the #{k.to_s} in question.",
320 "https://api.clinicalfuture.com/auth/arvados"
325 # Check for Rails routes that don't match the usual actions
327 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
328 Rails.application.routes.routes.each do |route|
329 action = route.defaults[:action]
330 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
331 method if route.verb.match(method)
334 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
335 !d_methods[action.to_sym] and
336 ctl_class.action_methods.include? action and
337 ![:show, :index, :destroy].include?(action.to_sym)
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 if !method[:parameters][k][:default].nil?
370 method[:parameters][k][:default] = 'string'
372 method[:parameters][k][:type] ||= 'string'
373 method[:parameters][k][:description] ||= ''
374 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
375 if method[:parameters][k][:required].nil?
376 method[:parameters][k][:required] = v != false
380 d_methods[route.defaults[:action].to_sym] = method
386 render json: discovery