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 maxRequestSize: Rails.application.config.max_request_size,
42 description: "Data format for the response.",
48 "Responses with Content-Type of application/json"
54 description: "Selector specifying which fields to include in a partial response.",
59 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.",
64 description: "OAuth 2.0 token for the current user.",
71 "https://api.curoverse.com/auth/arvados" => {
72 description: "View and manage objects"
74 "https://api.curoverse.com/auth/arvados.readonly" => {
75 description: "View objects"
84 if Rails.application.config.websocket_address
85 discovery[:websocketUrl] = Rails.application.config.websocket_address
86 elsif ENV['ARVADOS_WEBSOCKETS']
87 discovery[:websocketUrl] = (root_url.sub /^http/, 'ws') + "websocket"
90 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
92 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
94 # No controller -> no discovery.
97 object_properties = {}
99 select { |col| col.name != 'id' }.
101 if k.serialized_attributes.has_key? col.name
102 object_properties[col.name] = {
103 type: k.serialized_attributes[col.name].object_class.to_s
106 object_properties[col.name] = {
111 discovery[:schemas][k.to_s + 'List'] = {
113 description: k.to_s + ' list',
118 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
119 default: "arvados##{k.to_s.camelcase(:lower)}List"
123 description: "List version."
127 description: "The list of #{k.to_s.pluralize}.",
134 description: "A link to the next page of #{k.to_s.pluralize}."
138 description: "The page token for the next page of #{k.to_s.pluralize}."
142 description: "A link back to this list."
146 discovery[:schemas][k.to_s] = {
150 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
154 description: "Object ID."
158 description: "Object version."
160 }.merge(object_properties)
162 discovery[:resources][k.to_s.underscore.pluralize] = {
165 id: "arvados.#{k.to_s.underscore.pluralize}.get",
166 path: "#{k.to_s.underscore.pluralize}/{uuid}",
168 description: "Gets a #{k.to_s}'s metadata by UUID.",
172 description: "The UUID of the #{k.to_s} in question.",
184 "https://api.curoverse.com/auth/arvados",
185 "https://api.curoverse.com/auth/arvados.readonly"
189 id: "arvados.#{k.to_s.underscore.pluralize}.list",
190 path: k.to_s.underscore.pluralize,
193 %|List #{k.to_s.pluralize}.
195 The <code>list</code> method returns a
196 <a href="/api/resources.html">resource list</a> of
197 matching #{k.to_s.pluralize}. For example:
201 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
204 "next_page_token":"",
209 "items_available":745,
211 "request_time":0.157236317
217 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
225 description: "Number of #{k.to_s.underscore.pluralize} to skip before first returned record.",
233 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
238 description: "Conditions for filtering #{k.to_s.underscore.pluralize}. (Deprecated. Use filters instead.)",
243 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
248 description: "Select which fields to return",
253 description: "Return each distinct object",
258 "$ref" => "#{k.to_s}List"
261 "https://api.curoverse.com/auth/arvados",
262 "https://api.curoverse.com/auth/arvados.readonly"
266 id: "arvados.#{k.to_s.underscore.pluralize}.create",
267 path: "#{k.to_s.underscore.pluralize}",
269 description: "Create a new #{k.to_s}.",
274 k.to_s.underscore => {
283 "https://api.curoverse.com/auth/arvados"
287 id: "arvados.#{k.to_s.underscore.pluralize}.update",
288 path: "#{k.to_s.underscore.pluralize}/{uuid}",
290 description: "Update attributes of an existing #{k.to_s}.",
294 description: "The UUID of the #{k.to_s} in question.",
302 k.to_s.underscore => {
311 "https://api.curoverse.com/auth/arvados"
315 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
316 path: "#{k.to_s.underscore.pluralize}/{uuid}",
317 httpMethod: "DELETE",
318 description: "Delete an existing #{k.to_s}.",
322 description: "The UUID of the #{k.to_s} in question.",
331 "https://api.curoverse.com/auth/arvados"
336 # Check for Rails routes that don't match the usual actions
338 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
339 Rails.application.routes.routes.each do |route|
340 action = route.defaults[:action]
341 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
342 method if route.verb.match(method)
345 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
346 ctl_class.action_methods.include? action
347 if !d_methods[action.to_sym]
349 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
350 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
351 httpMethod: httpMethod,
352 description: "#{action} #{k.to_s.underscore.pluralize}",
355 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
358 "https://api.curoverse.com/auth/arvados"
361 route.segment_keys.each do |key|
363 key = :uuid if key == :id
364 method[:parameters][key] = {
373 # We already built a generic method description, but we
374 # might find some more required parameters through
376 method = d_methods[action.to_sym]
378 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
379 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
381 method[:parameters][k] = v
383 method[:parameters][k] = {}
385 if !method[:parameters][k][:default].nil?
386 # The JAVA SDK is sensitive to all values being strings
387 method[:parameters][k][:default] = method[:parameters][k][:default].to_s
389 method[:parameters][k][:type] ||= 'string'
390 method[:parameters][k][:description] ||= ''
391 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
392 if method[:parameters][k][:required].nil?
393 method[:parameters][k][:required] = v != false
397 d_methods[action.to_sym] = method