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",
28 defaultCollectionReplication: Rails.configuration.default_collection_replication,
29 gitHttpBase: Rails.configuration.git_http_base,
31 baseUrl: root_url + "arvados/v1/",
32 basePath: "/arvados/v1/",
34 servicePath: "arvados/v1/",
36 defaultTrashLifetime: Rails.application.config.default_trash_lifetime,
37 maxRequestSize: Rails.application.config.max_request_size,
41 description: "Data format for the response.",
47 "Responses with Content-Type of application/json"
53 description: "Selector specifying which fields to include in a partial response.",
58 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.",
63 description: "OAuth 2.0 token for the current user.",
70 "https://api.curoverse.com/auth/arvados" => {
71 description: "View and manage objects"
73 "https://api.curoverse.com/auth/arvados.readonly" => {
74 description: "View objects"
83 if Rails.application.config.websocket_address
84 discovery[:websocketUrl] = Rails.application.config.websocket_address
85 elsif ENV['ARVADOS_WEBSOCKETS']
86 discovery[:websocketUrl] = (root_url.sub /^http/, 'ws') + "websocket"
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] = {
149 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
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.curoverse.com/auth/arvados",
184 "https://api.curoverse.com/auth/arvados.readonly"
188 id: "arvados.#{k.to_s.underscore.pluralize}.list",
189 path: k.to_s.underscore.pluralize,
192 %|List #{k.to_s.pluralize}.
194 The <code>list</code> method returns a
195 <a href="/api/resources.html">resource list</a> of
196 matching #{k.to_s.pluralize}. For example:
200 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
203 "next_page_token":"",
208 "items_available":745,
210 "request_time":0.157236317
216 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
224 description: "Number of #{k.to_s.underscore.pluralize} to skip before first returned record.",
232 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
237 description: "Conditions for filtering #{k.to_s.underscore.pluralize}. (Deprecated. Use filters instead.)",
242 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
247 description: "Select which fields to return",
252 description: "Return each distinct object",
257 "$ref" => "#{k.to_s}List"
260 "https://api.curoverse.com/auth/arvados",
261 "https://api.curoverse.com/auth/arvados.readonly"
265 id: "arvados.#{k.to_s.underscore.pluralize}.create",
266 path: "#{k.to_s.underscore.pluralize}",
268 description: "Create a new #{k.to_s}.",
273 k.to_s.underscore => {
282 "https://api.curoverse.com/auth/arvados"
286 id: "arvados.#{k.to_s.underscore.pluralize}.update",
287 path: "#{k.to_s.underscore.pluralize}/{uuid}",
289 description: "Update attributes of an existing #{k.to_s}.",
293 description: "The UUID of the #{k.to_s} in question.",
301 k.to_s.underscore => {
310 "https://api.curoverse.com/auth/arvados"
314 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
315 path: "#{k.to_s.underscore.pluralize}/{uuid}",
316 httpMethod: "DELETE",
317 description: "Delete an existing #{k.to_s}.",
321 description: "The UUID of the #{k.to_s} in question.",
330 "https://api.curoverse.com/auth/arvados"
335 # Check for Rails routes that don't match the usual actions
337 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
338 Rails.application.routes.routes.each do |route|
339 action = route.defaults[:action]
340 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
341 method if route.verb.match(method)
344 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
345 ctl_class.action_methods.include? action
346 if !d_methods[action.to_sym]
348 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
349 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
350 httpMethod: httpMethod,
351 description: "#{action} #{k.to_s.underscore.pluralize}",
354 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
357 "https://api.curoverse.com/auth/arvados"
360 route.segment_keys.each do |key|
362 key = :uuid if key == :id
363 method[:parameters][key] = {
372 # We already built a generic method description, but we
373 # might find some more required parameters through
375 method = d_methods[action.to_sym]
377 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
378 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
380 method[:parameters][k] = v
382 method[:parameters][k] = {}
384 if !method[:parameters][k][:default].nil?
385 # The JAVA SDK is sensitive to all values being strings
386 method[:parameters][k][:default] = method[:parameters][k][:default].to_s
388 method[:parameters][k][:type] ||= 'string'
389 method[:parameters][k][:description] ||= ''
390 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
391 if method[:parameters][k][:required].nil?
392 method[:parameters][k][:required] = v != false
396 d_methods[action.to_sym] = method