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: AppVersion.hash,
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,
40 dockerImageFormats: Rails.application.config.docker_image_formats,
44 description: "Data format for the response.",
50 "Responses with Content-Type of application/json"
56 description: "Selector specifying which fields to include in a partial response.",
61 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.",
66 description: "OAuth 2.0 token for the current user.",
73 "https://api.curoverse.com/auth/arvados" => {
74 description: "View and manage objects"
76 "https://api.curoverse.com/auth/arvados.readonly" => {
77 description: "View objects"
86 if Rails.application.config.websocket_address
87 discovery[:websocketUrl] = Rails.application.config.websocket_address
88 elsif ENV['ARVADOS_WEBSOCKETS']
89 discovery[:websocketUrl] = root_url.sub(/^http/, 'ws') + "websocket"
92 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
94 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
96 # No controller -> no discovery.
99 object_properties = {}
101 select { |col| col.name != 'id' }.
103 if k.serialized_attributes.has_key? col.name
104 object_properties[col.name] = {
105 type: k.serialized_attributes[col.name].object_class.to_s
108 object_properties[col.name] = {
113 discovery[:schemas][k.to_s + 'List'] = {
115 description: k.to_s + ' list',
120 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
121 default: "arvados##{k.to_s.camelcase(:lower)}List"
125 description: "List version."
129 description: "The list of #{k.to_s.pluralize}.",
136 description: "A link to the next page of #{k.to_s.pluralize}."
140 description: "The page token for the next page of #{k.to_s.pluralize}."
144 description: "A link back to this list."
148 discovery[:schemas][k.to_s] = {
152 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
156 description: "Object ID."
160 description: "Object version."
162 }.merge(object_properties)
164 discovery[:resources][k.to_s.underscore.pluralize] = {
167 id: "arvados.#{k.to_s.underscore.pluralize}.get",
168 path: "#{k.to_s.underscore.pluralize}/{uuid}",
170 description: "Gets a #{k.to_s}'s metadata by UUID.",
174 description: "The UUID of the #{k.to_s} in question.",
186 "https://api.curoverse.com/auth/arvados",
187 "https://api.curoverse.com/auth/arvados.readonly"
191 id: "arvados.#{k.to_s.underscore.pluralize}.list",
192 path: k.to_s.underscore.pluralize,
195 %|List #{k.to_s.pluralize}.
197 The <code>list</code> method returns a
198 <a href="/api/resources.html">resource list</a> of
199 matching #{k.to_s.pluralize}. For example:
203 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
206 "next_page_token":"",
211 "items_available":745,
213 "request_time":0.157236317
219 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
227 description: "Number of #{k.to_s.underscore.pluralize} to skip before first returned record.",
235 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
240 description: "Conditions for filtering #{k.to_s.underscore.pluralize}. (Deprecated. Use filters instead.)",
245 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
250 description: "Select which fields to return.",
255 description: "Return each distinct object.",
260 description: "Type of count to return in items_available ('none' or 'exact').",
266 "$ref" => "#{k.to_s}List"
269 "https://api.curoverse.com/auth/arvados",
270 "https://api.curoverse.com/auth/arvados.readonly"
274 id: "arvados.#{k.to_s.underscore.pluralize}.create",
275 path: "#{k.to_s.underscore.pluralize}",
277 description: "Create a new #{k.to_s}.",
282 k.to_s.underscore => {
291 "https://api.curoverse.com/auth/arvados"
295 id: "arvados.#{k.to_s.underscore.pluralize}.update",
296 path: "#{k.to_s.underscore.pluralize}/{uuid}",
298 description: "Update attributes of an existing #{k.to_s}.",
302 description: "The UUID of the #{k.to_s} in question.",
310 k.to_s.underscore => {
319 "https://api.curoverse.com/auth/arvados"
323 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
324 path: "#{k.to_s.underscore.pluralize}/{uuid}",
325 httpMethod: "DELETE",
326 description: "Delete an existing #{k.to_s}.",
330 description: "The UUID of the #{k.to_s} in question.",
339 "https://api.curoverse.com/auth/arvados"
344 # Check for Rails routes that don't match the usual actions
346 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
347 Rails.application.routes.routes.each do |route|
348 action = route.defaults[:action]
349 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
350 method if route.verb.match(method)
353 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
354 ctl_class.action_methods.include? action
355 if !d_methods[action.to_sym]
357 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
358 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
359 httpMethod: httpMethod,
360 description: "#{action} #{k.to_s.underscore.pluralize}",
363 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
366 "https://api.curoverse.com/auth/arvados"
369 route.segment_keys.each do |key|
371 key = :uuid if key == :id
372 method[:parameters][key] = {
381 # We already built a generic method description, but we
382 # might find some more required parameters through
384 method = d_methods[action.to_sym]
386 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
387 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |l, v|
389 method[:parameters][l] = v
391 method[:parameters][l] = {}
393 if !method[:parameters][l][:default].nil?
394 # The JAVA SDK is sensitive to all values being strings
395 method[:parameters][l][:default] = method[:parameters][l][:default].to_s
397 method[:parameters][l][:type] ||= 'string'
398 method[:parameters][l][:description] ||= ''
399 method[:parameters][l][:location] = (route.segment_keys.include?(l) ? 'path' : 'query')
400 if method[:parameters][l][:required].nil?
401 method[:parameters][l][:required] = v != false
405 d_methods[action.to_sym] = method
409 Rails.configuration.disable_api_methods.each do |method|
410 ctrl, action = method.split('.', 2)
411 discovery[:resources][ctrl][:methods].delete(action.to_sym)