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 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 : ''),
19 generatedAt: Time.now.iso8601,
21 description: "The API to interact with Arvados.",
22 documentationLink: "http://doc.arvados.org/api/index.html",
23 defaultCollectionReplication: Rails.configuration.default_collection_replication,
25 baseUrl: root_url + "arvados/v1/",
26 basePath: "/arvados/v1/",
28 servicePath: "arvados/v1/",
30 defaultTrashLifetime: Rails.application.config.default_trash_lifetime,
34 description: "Data format for the response.",
40 "Responses with Content-Type of application/json"
46 description: "Selector specifying which fields to include in a partial response.",
51 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.",
56 description: "OAuth 2.0 token for the current user.",
63 "https://api.curoverse.com/auth/arvados" => {
64 description: "View and manage objects"
66 "https://api.curoverse.com/auth/arvados.readonly" => {
67 description: "View objects"
76 if Rails.application.config.websocket_address
77 discovery[:websocketUrl] = Rails.application.config.websocket_address
78 elsif ENV['ARVADOS_WEBSOCKETS']
79 discovery[:websocketUrl] = (root_url.sub /^http/, 'ws') + "websocket"
82 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
84 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
86 # No controller -> no discovery.
89 object_properties = {}
91 select { |col| col.name != 'id' }.
93 if k.serialized_attributes.has_key? col.name
94 object_properties[col.name] = {
95 type: k.serialized_attributes[col.name].object_class.to_s
98 object_properties[col.name] = {
103 discovery[:schemas][k.to_s + 'List'] = {
105 description: k.to_s + ' list',
110 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
111 default: "arvados##{k.to_s.camelcase(:lower)}List"
115 description: "List version."
119 description: "The list of #{k.to_s.pluralize}.",
126 description: "A link to the next page of #{k.to_s.pluralize}."
130 description: "The page token for the next page of #{k.to_s.pluralize}."
134 description: "A link back to this list."
138 discovery[:schemas][k.to_s] = {
142 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
146 description: "Object ID."
150 description: "Object version."
152 }.merge(object_properties)
154 discovery[:resources][k.to_s.underscore.pluralize] = {
157 id: "arvados.#{k.to_s.underscore.pluralize}.get",
158 path: "#{k.to_s.underscore.pluralize}/{uuid}",
160 description: "Gets a #{k.to_s}'s metadata by UUID.",
164 description: "The UUID of the #{k.to_s} in question.",
176 "https://api.curoverse.com/auth/arvados",
177 "https://api.curoverse.com/auth/arvados.readonly"
181 id: "arvados.#{k.to_s.underscore.pluralize}.list",
182 path: k.to_s.underscore.pluralize,
185 %|List #{k.to_s.pluralize}.
187 The <code>list</code> method returns a
188 <a href="/api/resources.html">resource list</a> of
189 matching #{k.to_s.pluralize}. For example:
193 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
196 "next_page_token":"",
201 "items_available":745,
203 "request_time":0.157236317
209 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
217 description: "Number of #{k.to_s.underscore.pluralize} to skip before first returned record.",
225 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
230 description: "Conditions for filtering #{k.to_s.underscore.pluralize}. (Deprecated. Use filters instead.)",
235 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
240 description: "Select which fields to return",
245 description: "Return each distinct object",
250 "$ref" => "#{k.to_s}List"
253 "https://api.curoverse.com/auth/arvados",
254 "https://api.curoverse.com/auth/arvados.readonly"
258 id: "arvados.#{k.to_s.underscore.pluralize}.create",
259 path: "#{k.to_s.underscore.pluralize}",
261 description: "Create a new #{k.to_s}.",
266 k.to_s.underscore => {
275 "https://api.curoverse.com/auth/arvados"
279 id: "arvados.#{k.to_s.underscore.pluralize}.update",
280 path: "#{k.to_s.underscore.pluralize}/{uuid}",
282 description: "Update attributes of an existing #{k.to_s}.",
286 description: "The UUID of the #{k.to_s} in question.",
294 k.to_s.underscore => {
303 "https://api.curoverse.com/auth/arvados"
307 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
308 path: "#{k.to_s.underscore.pluralize}/{uuid}",
309 httpMethod: "DELETE",
310 description: "Delete an existing #{k.to_s}.",
314 description: "The UUID of the #{k.to_s} in question.",
323 "https://api.curoverse.com/auth/arvados"
328 # Check for Rails routes that don't match the usual actions
330 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
331 Rails.application.routes.routes.each do |route|
332 action = route.defaults[:action]
333 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
334 method if route.verb.match(method)
337 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
338 ctl_class.action_methods.include? action
339 if !d_methods[action.to_sym]
341 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
342 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
343 httpMethod: httpMethod,
344 description: "#{action} #{k.to_s.underscore.pluralize}",
347 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
350 "https://api.curoverse.com/auth/arvados"
353 route.segment_keys.each do |key|
355 key = :uuid if key == :id
356 method[:parameters][key] = {
365 # We already built a generic method description, but we
366 # might find some more required parameters through
368 method = d_methods[action.to_sym]
370 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
371 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
373 method[:parameters][k] = v
375 method[:parameters][k] = {}
377 if !method[:parameters][k][:default].nil?
378 # The JAVA SDK is sensitive to all values being strings
379 method[:parameters][k][:default] = method[:parameters][k][:default].to_s
381 method[:parameters][k][:type] ||= 'string'
382 method[:parameters][k][:description] ||= ''
383 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
384 if method[:parameters][k][:required].nil?
385 method[:parameters][k][:required] = v != false
389 d_methods[action.to_sym] = method