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: db_current_time.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,
30 baseUrl: root_url + "arvados/v1/",
31 basePath: "/arvados/v1/",
33 servicePath: "arvados/v1/",
35 defaultTrashLifetime: Rails.application.config.default_trash_lifetime,
36 maxRequestSize: Rails.application.config.max_request_size,
40 description: "Data format for the response.",
46 "Responses with Content-Type of application/json"
52 description: "Selector specifying which fields to include in a partial response.",
57 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.",
62 description: "OAuth 2.0 token for the current user.",
69 "https://api.curoverse.com/auth/arvados" => {
70 description: "View and manage objects"
72 "https://api.curoverse.com/auth/arvados.readonly" => {
73 description: "View objects"
82 if Rails.application.config.websocket_address
83 discovery[:websocketUrl] = Rails.application.config.websocket_address
84 elsif ENV['ARVADOS_WEBSOCKETS']
85 discovery[:websocketUrl] = (root_url.sub /^http/, 'ws') + "websocket"
88 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
90 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
92 # No controller -> no discovery.
95 object_properties = {}
97 select { |col| col.name != 'id' }.
99 if k.serialized_attributes.has_key? col.name
100 object_properties[col.name] = {
101 type: k.serialized_attributes[col.name].object_class.to_s
104 object_properties[col.name] = {
109 discovery[:schemas][k.to_s + 'List'] = {
111 description: k.to_s + ' list',
116 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
117 default: "arvados##{k.to_s.camelcase(:lower)}List"
121 description: "List version."
125 description: "The list of #{k.to_s.pluralize}.",
132 description: "A link to the next page of #{k.to_s.pluralize}."
136 description: "The page token for the next page of #{k.to_s.pluralize}."
140 description: "A link back to this list."
144 discovery[:schemas][k.to_s] = {
148 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
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.curoverse.com/auth/arvados",
183 "https://api.curoverse.com/auth/arvados.readonly"
187 id: "arvados.#{k.to_s.underscore.pluralize}.list",
188 path: k.to_s.underscore.pluralize,
191 %|List #{k.to_s.pluralize}.
193 The <code>list</code> method returns a
194 <a href="/api/resources.html">resource list</a> of
195 matching #{k.to_s.pluralize}. For example:
199 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
202 "next_page_token":"",
207 "items_available":745,
209 "request_time":0.157236317
215 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
223 description: "Number of #{k.to_s.underscore.pluralize} to skip before first returned record.",
231 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
236 description: "Conditions for filtering #{k.to_s.underscore.pluralize}. (Deprecated. Use filters instead.)",
241 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
246 description: "Select which fields to return",
251 description: "Return each distinct object",
256 "$ref" => "#{k.to_s}List"
259 "https://api.curoverse.com/auth/arvados",
260 "https://api.curoverse.com/auth/arvados.readonly"
264 id: "arvados.#{k.to_s.underscore.pluralize}.create",
265 path: "#{k.to_s.underscore.pluralize}",
267 description: "Create a new #{k.to_s}.",
272 k.to_s.underscore => {
281 "https://api.curoverse.com/auth/arvados"
285 id: "arvados.#{k.to_s.underscore.pluralize}.update",
286 path: "#{k.to_s.underscore.pluralize}/{uuid}",
288 description: "Update attributes of an existing #{k.to_s}.",
292 description: "The UUID of the #{k.to_s} in question.",
300 k.to_s.underscore => {
309 "https://api.curoverse.com/auth/arvados"
313 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
314 path: "#{k.to_s.underscore.pluralize}/{uuid}",
315 httpMethod: "DELETE",
316 description: "Delete an existing #{k.to_s}.",
320 description: "The UUID of the #{k.to_s} in question.",
329 "https://api.curoverse.com/auth/arvados"
334 # Check for Rails routes that don't match the usual actions
336 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
337 Rails.application.routes.routes.each do |route|
338 action = route.defaults[:action]
339 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
340 method if route.verb.match(method)
343 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
344 ctl_class.action_methods.include? action
345 if !d_methods[action.to_sym]
347 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
348 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
349 httpMethod: httpMethod,
350 description: "#{action} #{k.to_s.underscore.pluralize}",
353 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
356 "https://api.curoverse.com/auth/arvados"
359 route.segment_keys.each do |key|
361 key = :uuid if key == :id
362 method[:parameters][key] = {
371 # We already built a generic method description, but we
372 # might find some more required parameters through
374 method = d_methods[action.to_sym]
376 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
377 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
379 method[:parameters][k] = v
381 method[:parameters][k] = {}
383 if !method[:parameters][k][:default].nil?
384 # The JAVA SDK is sensitive to all values being strings
385 method[:parameters][k][:default] = method[:parameters][k][:default].to_s
387 method[:parameters][k][:type] ||= 'string'
388 method[:parameters][k][:description] ||= ''
389 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
390 if method[:parameters][k][:required].nil?
391 method[:parameters][k][:required] = v != false
395 d_methods[action.to_sym] = method