1 class Arvados::V1::SchemaController < ApplicationController
2 skip_before_filter :catch_redirect_hint
3 skip_before_filter :find_objects_for_index
4 skip_before_filter :find_object_by_uuid
5 skip_before_filter :load_filters_param
6 skip_before_filter :load_limit_offset_order_params
7 skip_before_filter :load_read_auths
8 skip_before_filter :load_where_param
9 skip_before_filter :render_404_if_no_object
10 skip_before_filter :require_auth_scope
13 expires_in 24.hours, public: true
14 discovery = Rails.cache.fetch 'arvados_v1_rest_discovery' do
15 Rails.application.eager_load!
17 kind: "discovery#restDescription",
18 discoveryVersion: "v1",
23 source_version: (Rails.application.config.source_version ? Rails.application.config.source_version : "No version information available") + (Rails.application.config.local_modified ? Rails.application.config.local_modified.to_s : ''),
24 generatedAt: Time.now.iso8601,
26 description: "The API to interact with Arvados.",
27 documentationLink: "http://doc.arvados.org/api/index.html",
29 baseUrl: root_url + "arvados/v1/",
30 basePath: "/arvados/v1/",
32 servicePath: "arvados/v1/",
34 defaultTrashLifetime: Rails.application.config.default_trash_lifetime,
38 description: "Data format for the response.",
44 "Responses with Content-Type of application/json"
50 description: "Selector specifying which fields to include in a partial response.",
55 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.",
60 description: "OAuth 2.0 token for the current user.",
67 "https://api.curoverse.com/auth/arvados" => {
68 description: "View and manage objects"
70 "https://api.curoverse.com/auth/arvados.readonly" => {
71 description: "View objects"
80 if Rails.application.config.websocket_address
81 discovery[:websocketUrl] = Rails.application.config.websocket_address
82 elsif ENV['ARVADOS_WEBSOCKETS']
83 discovery[:websocketUrl] = (root_url.sub /^http/, 'ws') + "websocket"
86 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
88 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
90 # No controller -> no discovery.
93 object_properties = {}
95 select { |col| col.name != 'id' }.
97 if k.serialized_attributes.has_key? col.name
98 object_properties[col.name] = {
99 type: k.serialized_attributes[col.name].object_class.to_s
102 object_properties[col.name] = {
107 discovery[:schemas][k.to_s + 'List'] = {
109 description: k.to_s + ' list',
114 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
115 default: "arvados##{k.to_s.camelcase(:lower)}List"
119 description: "List version."
123 description: "The list of #{k.to_s.pluralize}.",
130 description: "A link to the next page of #{k.to_s.pluralize}."
134 description: "The page token for the next page of #{k.to_s.pluralize}."
138 description: "A link back to this list."
142 discovery[:schemas][k.to_s] = {
146 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
150 description: "Object ID."
154 description: "Object version."
156 }.merge(object_properties)
158 discovery[:resources][k.to_s.underscore.pluralize] = {
161 id: "arvados.#{k.to_s.underscore.pluralize}.get",
162 path: "#{k.to_s.underscore.pluralize}/{uuid}",
164 description: "Gets a #{k.to_s}'s metadata by UUID.",
168 description: "The UUID of the #{k.to_s} in question.",
180 "https://api.curoverse.com/auth/arvados",
181 "https://api.curoverse.com/auth/arvados.readonly"
185 id: "arvados.#{k.to_s.underscore.pluralize}.list",
186 path: k.to_s.underscore.pluralize,
189 %|List #{k.to_s.pluralize}.
191 The <code>list</code> method returns a
192 <a href="/api/resources.html">resource list</a> of
193 matching #{k.to_s.pluralize}. For example:
197 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
200 "next_page_token":"",
205 "items_available":745,
207 "request_time":0.157236317
213 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
221 description: "Number of #{k.to_s.underscore.pluralize} to skip before first returned record.",
229 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
234 description: "Conditions for filtering #{k.to_s.underscore.pluralize}. (Deprecated. Use filters instead.)",
239 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
244 description: "Select which fields to return",
249 description: "Return each distinct object",
254 "$ref" => "#{k.to_s}List"
257 "https://api.curoverse.com/auth/arvados",
258 "https://api.curoverse.com/auth/arvados.readonly"
262 id: "arvados.#{k.to_s.underscore.pluralize}.create",
263 path: "#{k.to_s.underscore.pluralize}",
265 description: "Create a new #{k.to_s}.",
270 k.to_s.underscore => {
279 "https://api.curoverse.com/auth/arvados"
283 id: "arvados.#{k.to_s.underscore.pluralize}.update",
284 path: "#{k.to_s.underscore.pluralize}/{uuid}",
286 description: "Update attributes of an existing #{k.to_s}.",
290 description: "The UUID of the #{k.to_s} in question.",
298 k.to_s.underscore => {
307 "https://api.curoverse.com/auth/arvados"
311 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
312 path: "#{k.to_s.underscore.pluralize}/{uuid}",
313 httpMethod: "DELETE",
314 description: "Delete an existing #{k.to_s}.",
318 description: "The UUID of the #{k.to_s} in question.",
327 "https://api.curoverse.com/auth/arvados"
332 # Check for Rails routes that don't match the usual actions
334 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
335 Rails.application.routes.routes.each do |route|
336 action = route.defaults[:action]
337 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
338 method if route.verb.match(method)
341 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
342 ctl_class.action_methods.include? action
343 if !d_methods[action.to_sym]
345 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
346 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
347 httpMethod: httpMethod,
348 description: "#{action} #{k.to_s.underscore.pluralize}",
351 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
354 "https://api.curoverse.com/auth/arvados"
357 route.segment_keys.each do |key|
359 key = :uuid if key == :id
360 method[:parameters][key] = {
369 # We already built a generic method description, but we
370 # might find some more required parameters through
372 method = d_methods[action.to_sym]
374 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
375 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
377 method[:parameters][k] = v
379 method[:parameters][k] = {}
381 if !method[:parameters][k][:default].nil?
382 # The JAVA SDK is sensitive to all values being strings
383 method[:parameters][k][:default] = method[:parameters][k][:default].to_s
385 method[:parameters][k][:type] ||= 'string'
386 method[:parameters][k][:description] ||= ''
387 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
388 if method[:parameters][k][:required].nil?
389 method[:parameters][k][:required] = v != false
393 d_methods[action.to_sym] = method