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
15 expires_in 24.hours, public: true
16 discovery = Rails.cache.fetch 'arvados_v1_rest_discovery' do
17 Rails.application.eager_load!
19 kind: "discovery#restDescription",
20 discoveryVersion: "v1",
25 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 : ''),
26 generatedAt: db_current_time.iso8601,
28 description: "The API to interact with Arvados.",
29 documentationLink: "http://doc.arvados.org/api/index.html",
30 defaultCollectionReplication: Rails.configuration.default_collection_replication,
32 baseUrl: root_url + "arvados/v1/",
33 basePath: "/arvados/v1/",
35 servicePath: "arvados/v1/",
37 defaultTrashLifetime: Rails.application.config.default_trash_lifetime,
38 blobSignatureTtl: Rails.application.config.blob_signature_ttl,
39 maxRequestSize: Rails.application.config.max_request_size,
43 description: "Data format for the response.",
49 "Responses with Content-Type of application/json"
55 description: "Selector specifying which fields to include in a partial response.",
60 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.",
65 description: "OAuth 2.0 token for the current user.",
72 "https://api.curoverse.com/auth/arvados" => {
73 description: "View and manage objects"
75 "https://api.curoverse.com/auth/arvados.readonly" => {
76 description: "View objects"
85 if Rails.application.config.websocket_address
86 discovery[:websocketUrl] = Rails.application.config.websocket_address
87 elsif ENV['ARVADOS_WEBSOCKETS']
88 discovery[:websocketUrl] = (root_url.sub /^http/, 'ws') + "websocket"
91 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
93 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
95 # No controller -> no discovery.
98 object_properties = {}
100 select { |col| col.name != 'id' }.
102 if k.serialized_attributes.has_key? col.name
103 object_properties[col.name] = {
104 type: k.serialized_attributes[col.name].object_class.to_s
107 object_properties[col.name] = {
112 discovery[:schemas][k.to_s + 'List'] = {
114 description: k.to_s + ' list',
119 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
120 default: "arvados##{k.to_s.camelcase(:lower)}List"
124 description: "List version."
128 description: "The list of #{k.to_s.pluralize}.",
135 description: "A link to the next page of #{k.to_s.pluralize}."
139 description: "The page token for the next page of #{k.to_s.pluralize}."
143 description: "A link back to this list."
147 discovery[:schemas][k.to_s] = {
151 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
155 description: "Object ID."
159 description: "Object version."
161 }.merge(object_properties)
163 discovery[:resources][k.to_s.underscore.pluralize] = {
166 id: "arvados.#{k.to_s.underscore.pluralize}.get",
167 path: "#{k.to_s.underscore.pluralize}/{uuid}",
169 description: "Gets a #{k.to_s}'s metadata by UUID.",
173 description: "The UUID of the #{k.to_s} in question.",
185 "https://api.curoverse.com/auth/arvados",
186 "https://api.curoverse.com/auth/arvados.readonly"
190 id: "arvados.#{k.to_s.underscore.pluralize}.list",
191 path: k.to_s.underscore.pluralize,
194 %|List #{k.to_s.pluralize}.
196 The <code>list</code> method returns a
197 <a href="/api/resources.html">resource list</a> of
198 matching #{k.to_s.pluralize}. For example:
202 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
205 "next_page_token":"",
210 "items_available":745,
212 "request_time":0.157236317
218 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
226 description: "Number of #{k.to_s.underscore.pluralize} to skip before first returned record.",
234 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
239 description: "Conditions for filtering #{k.to_s.underscore.pluralize}. (Deprecated. Use filters instead.)",
244 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
249 description: "Select which fields to return",
254 description: "Return each distinct object",
259 "$ref" => "#{k.to_s}List"
262 "https://api.curoverse.com/auth/arvados",
263 "https://api.curoverse.com/auth/arvados.readonly"
267 id: "arvados.#{k.to_s.underscore.pluralize}.create",
268 path: "#{k.to_s.underscore.pluralize}",
270 description: "Create a new #{k.to_s}.",
275 k.to_s.underscore => {
284 "https://api.curoverse.com/auth/arvados"
288 id: "arvados.#{k.to_s.underscore.pluralize}.update",
289 path: "#{k.to_s.underscore.pluralize}/{uuid}",
291 description: "Update attributes of an existing #{k.to_s}.",
295 description: "The UUID of the #{k.to_s} in question.",
303 k.to_s.underscore => {
312 "https://api.curoverse.com/auth/arvados"
316 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
317 path: "#{k.to_s.underscore.pluralize}/{uuid}",
318 httpMethod: "DELETE",
319 description: "Delete an existing #{k.to_s}.",
323 description: "The UUID of the #{k.to_s} in question.",
332 "https://api.curoverse.com/auth/arvados"
337 # Check for Rails routes that don't match the usual actions
339 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
340 Rails.application.routes.routes.each do |route|
341 action = route.defaults[:action]
342 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
343 method if route.verb.match(method)
346 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
347 ctl_class.action_methods.include? action
348 if !d_methods[action.to_sym]
350 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
351 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
352 httpMethod: httpMethod,
353 description: "#{action} #{k.to_s.underscore.pluralize}",
356 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
359 "https://api.curoverse.com/auth/arvados"
362 route.segment_keys.each do |key|
364 key = :uuid if key == :id
365 method[:parameters][key] = {
374 # We already built a generic method description, but we
375 # might find some more required parameters through
377 method = d_methods[action.to_sym]
379 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
380 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
382 method[:parameters][k] = v
384 method[:parameters][k] = {}
386 if !method[:parameters][k][:default].nil?
387 # The JAVA SDK is sensitive to all values being strings
388 method[:parameters][k][:default] = method[:parameters][k][:default].to_s
390 method[:parameters][k][:type] ||= 'string'
391 method[:parameters][k][:description] ||= ''
392 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
393 if method[:parameters][k][:required].nil?
394 method[:parameters][k][:required] = v != false
398 d_methods[action.to_sym] = method