1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class Arvados::V1::SchemaController < ApplicationController
6 skip_before_filter :catch_redirect_hint
7 skip_before_filter :find_objects_for_index
8 skip_before_filter :find_object_by_uuid
9 skip_before_filter :load_filters_param
10 skip_before_filter :load_limit_offset_order_params
11 skip_before_filter :load_read_auths
12 skip_before_filter :load_where_param
13 skip_before_filter :render_404_if_no_object
14 skip_before_filter :require_auth_scope
19 expires_in 24.hours, public: true
20 send_json discovery_doc
26 Rails.cache.fetch 'arvados_v1_rest_discovery' do
27 Rails.application.eager_load!
29 kind: "discovery#restDescription",
30 discoveryVersion: "v1",
35 source_version: AppVersion.hash,
36 generatedAt: db_current_time.iso8601,
38 description: "The API to interact with Arvados.",
39 documentationLink: "http://doc.arvados.org/api/index.html",
40 defaultCollectionReplication: Rails.configuration.default_collection_replication,
42 baseUrl: root_url + "arvados/v1/",
43 basePath: "/arvados/v1/",
45 servicePath: "arvados/v1/",
47 uuidPrefix: Rails.application.config.uuid_prefix,
48 defaultTrashLifetime: Rails.application.config.default_trash_lifetime,
49 blobSignatureTtl: Rails.application.config.blob_signature_ttl,
50 maxRequestSize: Rails.application.config.max_request_size,
51 dockerImageFormats: Rails.application.config.docker_image_formats,
52 crunchLogBytesPerEvent: Rails.application.config.crunch_log_bytes_per_event,
53 crunchLogSecondsBetweenEvents: Rails.application.config.crunch_log_seconds_between_events,
54 crunchLogThrottlePeriod: Rails.application.config.crunch_log_throttle_period,
55 crunchLogThrottleBytes: Rails.application.config.crunch_log_throttle_bytes,
56 crunchLogThrottleLines: Rails.application.config.crunch_log_throttle_lines,
57 crunchLimitLogBytesPerJob: Rails.application.config.crunch_limit_log_bytes_per_job,
58 crunchLogPartialLineThrottlePeriod: Rails.application.config.crunch_log_partial_line_throttle_period,
59 remoteHosts: Rails.configuration.remote_hosts,
60 remoteHostsViaDNS: Rails.configuration.remote_hosts_via_dns,
61 websocketUrl: Rails.application.config.websocket_address,
62 workbenchUrl: Rails.application.config.workbench_address,
63 keepWebServiceUrl: Rails.application.config.keep_web_service_url,
64 gitUrl: case Rails.application.config.git_repo_https_base
68 'https://git.%s.arvadosapi.com/' % Rails.configuration.uuid_prefix
70 Rails.application.config.git_repo_https_base
75 description: "Data format for the response.",
81 "Responses with Content-Type of application/json"
87 description: "Selector specifying which fields to include in a partial response.",
92 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.",
97 description: "OAuth 2.0 token for the current user.",
104 "https://api.curoverse.com/auth/arvados" => {
105 description: "View and manage objects"
107 "https://api.curoverse.com/auth/arvados.readonly" => {
108 description: "View objects"
117 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
119 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
121 # No controller -> no discovery.
124 object_properties = {}
126 select { |col| col.name != 'id' }.
128 if k.serialized_attributes.has_key? col.name
129 object_properties[col.name] = {
130 type: k.serialized_attributes[col.name].object_class.to_s
133 object_properties[col.name] = {
138 discovery[:schemas][k.to_s + 'List'] = {
140 description: k.to_s + ' list',
145 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
146 default: "arvados##{k.to_s.camelcase(:lower)}List"
150 description: "List version."
154 description: "The list of #{k.to_s.pluralize}.",
161 description: "A link to the next page of #{k.to_s.pluralize}."
165 description: "The page token for the next page of #{k.to_s.pluralize}."
169 description: "A link back to this list."
173 discovery[:schemas][k.to_s] = {
177 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
181 description: "Object ID."
185 description: "Object version."
187 }.merge(object_properties)
189 discovery[:resources][k.to_s.underscore.pluralize] = {
192 id: "arvados.#{k.to_s.underscore.pluralize}.get",
193 path: "#{k.to_s.underscore.pluralize}/{uuid}",
195 description: "Gets a #{k.to_s}'s metadata by UUID.",
199 description: "The UUID of the #{k.to_s} in question.",
211 "https://api.curoverse.com/auth/arvados",
212 "https://api.curoverse.com/auth/arvados.readonly"
216 id: "arvados.#{k.to_s.underscore.pluralize}.index",
217 path: k.to_s.underscore.pluralize,
220 %|Index #{k.to_s.pluralize}.
222 The <code>index</code> method returns a
223 <a href="/api/resources.html">resource list</a> of
224 matching #{k.to_s.pluralize}. For example:
228 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
231 "next_page_token":"",
236 "items_available":745,
238 "request_time":0.157236317
244 "$ref" => "#{k.to_s}List"
247 "https://api.curoverse.com/auth/arvados",
248 "https://api.curoverse.com/auth/arvados.readonly"
252 id: "arvados.#{k.to_s.underscore.pluralize}.create",
253 path: "#{k.to_s.underscore.pluralize}",
255 description: "Create a new #{k.to_s}.",
260 k.to_s.underscore => {
269 "https://api.curoverse.com/auth/arvados"
273 id: "arvados.#{k.to_s.underscore.pluralize}.update",
274 path: "#{k.to_s.underscore.pluralize}/{uuid}",
276 description: "Update attributes of an existing #{k.to_s}.",
280 description: "The UUID of the #{k.to_s} in question.",
288 k.to_s.underscore => {
297 "https://api.curoverse.com/auth/arvados"
301 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
302 path: "#{k.to_s.underscore.pluralize}/{uuid}",
303 httpMethod: "DELETE",
304 description: "Delete an existing #{k.to_s}.",
308 description: "The UUID of the #{k.to_s} in question.",
317 "https://api.curoverse.com/auth/arvados"
322 # Check for Rails routes that don't match the usual actions
324 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
325 Rails.application.routes.routes.each do |route|
326 action = route.defaults[:action]
327 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
328 method if route.verb.match(method)
331 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
332 ctl_class.action_methods.include? action
333 if !d_methods[action.to_sym]
335 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
336 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
337 httpMethod: httpMethod,
338 description: "#{action} #{k.to_s.underscore.pluralize}",
341 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
344 "https://api.curoverse.com/auth/arvados"
347 route.segment_keys.each do |key|
349 key = :uuid if key == :id
350 method[:parameters][key] = {
359 # We already built a generic method description, but we
360 # might find some more required parameters through
362 method = d_methods[action.to_sym]
364 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
365 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |l, v|
367 method[:parameters][l] = v
369 method[:parameters][l] = {}
371 if !method[:parameters][l][:default].nil?
372 # The JAVA SDK is sensitive to all values being strings
373 method[:parameters][l][:default] = method[:parameters][l][:default].to_s
375 method[:parameters][l][:type] ||= 'string'
376 method[:parameters][l][:description] ||= ''
377 method[:parameters][l][:location] = (route.segment_keys.include?(l) ? 'path' : 'query')
378 if method[:parameters][l][:required].nil?
379 method[:parameters][l][:required] = v != false
383 d_methods[action.to_sym] = method
386 list_method = method.dup
387 list_method[:id].sub!('index', 'list')
388 list_method[:description].sub!('Index', 'List')
389 list_method[:description].sub!('index', 'list')
390 d_methods[:list] = list_method
395 Rails.configuration.disable_api_methods.each do |method|
396 ctrl, action = method.split('.', 2)
397 discovery[:resources][ctrl][:methods].delete(action.to_sym)