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_action :catch_redirect_hint
7 skip_before_action :find_objects_for_index
8 skip_before_action :find_object_by_uuid
9 skip_before_action :load_filters_param
10 skip_before_action :load_limit_offset_order_params
11 skip_before_action :load_read_auths
12 skip_before_action :load_where_param
13 skip_before_action :render_404_if_no_object
14 skip_before_action :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 sourceVersion: AppVersion.hash, # source_version should be deprecated in the future
37 packageVersion: AppVersion.package_version,
38 generatedAt: db_current_time.iso8601,
40 description: "The API to interact with Arvados.",
41 documentationLink: "http://doc.arvados.org/api/index.html",
42 defaultCollectionReplication: Rails.configuration.default_collection_replication,
44 baseUrl: root_url + "arvados/v1/",
45 basePath: "/arvados/v1/",
47 servicePath: "arvados/v1/",
49 uuidPrefix: Rails.application.config.uuid_prefix,
50 defaultTrashLifetime: Rails.application.config.default_trash_lifetime,
51 blobSignatureTtl: Rails.application.config.blob_signature_ttl,
52 maxRequestSize: Rails.application.config.max_request_size,
53 maxItemsPerResponse: Rails.application.config.max_items_per_response,
54 dockerImageFormats: Rails.application.config.docker_image_formats,
55 crunchLogBytesPerEvent: Rails.application.config.crunch_log_bytes_per_event,
56 crunchLogSecondsBetweenEvents: Rails.application.config.crunch_log_seconds_between_events,
57 crunchLogThrottlePeriod: Rails.application.config.crunch_log_throttle_period,
58 crunchLogThrottleBytes: Rails.application.config.crunch_log_throttle_bytes,
59 crunchLogThrottleLines: Rails.application.config.crunch_log_throttle_lines,
60 crunchLimitLogBytesPerJob: Rails.application.config.crunch_limit_log_bytes_per_job,
61 crunchLogPartialLineThrottlePeriod: Rails.application.config.crunch_log_partial_line_throttle_period,
62 crunchLogUpdatePeriod: Rails.application.config.crunch_log_update_period,
63 crunchLogUpdateSize: Rails.application.config.crunch_log_update_size,
64 remoteHosts: Rails.configuration.remote_hosts,
65 remoteHostsViaDNS: Rails.configuration.remote_hosts_via_dns,
66 websocketUrl: Rails.application.config.websocket_address,
67 workbenchUrl: Rails.application.config.workbench_address,
68 keepWebServiceUrl: Rails.application.config.keep_web_service_url,
69 gitUrl: case Rails.application.config.git_repo_https_base
73 'https://git.%s.arvadosapi.com/' % Rails.configuration.uuid_prefix
75 Rails.application.config.git_repo_https_base
80 description: "Data format for the response.",
86 "Responses with Content-Type of application/json"
92 description: "Selector specifying which fields to include in a partial response.",
97 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.",
102 description: "OAuth 2.0 token for the current user.",
109 "https://api.curoverse.com/auth/arvados" => {
110 description: "View and manage objects"
112 "https://api.curoverse.com/auth/arvados.readonly" => {
113 description: "View objects"
122 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
124 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
126 # No controller -> no discovery.
129 object_properties = {}
131 select { |col| col.name != 'id' && !col.name.start_with?('secret_') }.
133 if k.serialized_attributes.has_key? col.name
134 object_properties[col.name] = {
135 type: k.serialized_attributes[col.name].object_class.to_s
138 object_properties[col.name] = {
143 discovery[:schemas][k.to_s + 'List'] = {
145 description: k.to_s + ' list',
150 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
151 default: "arvados##{k.to_s.camelcase(:lower)}List"
155 description: "List version."
159 description: "The list of #{k.to_s.pluralize}.",
166 description: "A link to the next page of #{k.to_s.pluralize}."
170 description: "The page token for the next page of #{k.to_s.pluralize}."
174 description: "A link back to this list."
178 discovery[:schemas][k.to_s] = {
182 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
186 description: "Object ID."
190 description: "Object version."
192 }.merge(object_properties)
194 discovery[:resources][k.to_s.underscore.pluralize] = {
197 id: "arvados.#{k.to_s.underscore.pluralize}.get",
198 path: "#{k.to_s.underscore.pluralize}/{uuid}",
200 description: "Gets a #{k.to_s}'s metadata by UUID.",
204 description: "The UUID of the #{k.to_s} in question.",
216 "https://api.curoverse.com/auth/arvados",
217 "https://api.curoverse.com/auth/arvados.readonly"
221 id: "arvados.#{k.to_s.underscore.pluralize}.index",
222 path: k.to_s.underscore.pluralize,
225 %|Index #{k.to_s.pluralize}.
227 The <code>index</code> method returns a
228 <a href="/api/resources.html">resource list</a> of
229 matching #{k.to_s.pluralize}. For example:
233 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
236 "next_page_token":"",
241 "items_available":745,
243 "request_time":0.157236317
249 "$ref" => "#{k.to_s}List"
252 "https://api.curoverse.com/auth/arvados",
253 "https://api.curoverse.com/auth/arvados.readonly"
257 id: "arvados.#{k.to_s.underscore.pluralize}.create",
258 path: "#{k.to_s.underscore.pluralize}",
260 description: "Create a new #{k.to_s}.",
265 k.to_s.underscore => {
274 "https://api.curoverse.com/auth/arvados"
278 id: "arvados.#{k.to_s.underscore.pluralize}.update",
279 path: "#{k.to_s.underscore.pluralize}/{uuid}",
281 description: "Update attributes of an existing #{k.to_s}.",
285 description: "The UUID of the #{k.to_s} in question.",
293 k.to_s.underscore => {
302 "https://api.curoverse.com/auth/arvados"
306 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
307 path: "#{k.to_s.underscore.pluralize}/{uuid}",
308 httpMethod: "DELETE",
309 description: "Delete an existing #{k.to_s}.",
313 description: "The UUID of the #{k.to_s} in question.",
322 "https://api.curoverse.com/auth/arvados"
327 # Check for Rails routes that don't match the usual actions
329 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
330 Rails.application.routes.routes.each do |route|
331 action = route.defaults[:action]
332 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
333 method if route.verb.match(method)
336 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
337 ctl_class.action_methods.include? action
338 if !d_methods[action.to_sym]
340 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
341 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
342 httpMethod: httpMethod,
343 description: "#{action} #{k.to_s.underscore.pluralize}",
346 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
349 "https://api.curoverse.com/auth/arvados"
352 route.segment_keys.each do |key|
354 key = :uuid if key == :id
355 method[:parameters][key] = {
364 # We already built a generic method description, but we
365 # might find some more required parameters through
367 method = d_methods[action.to_sym]
369 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
370 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |l, v|
372 method[:parameters][l] = v
374 method[:parameters][l] = {}
376 if !method[:parameters][l][:default].nil?
377 # The JAVA SDK is sensitive to all values being strings
378 method[:parameters][l][:default] = method[:parameters][l][:default].to_s
380 method[:parameters][l][:type] ||= 'string'
381 method[:parameters][l][:description] ||= ''
382 method[:parameters][l][:location] = (route.segment_keys.include?(l) ? 'path' : 'query')
383 if method[:parameters][l][:required].nil?
384 method[:parameters][l][:required] = v != false
388 d_methods[action.to_sym] = method
391 list_method = method.dup
392 list_method[:id].sub!('index', 'list')
393 list_method[:description].sub!('Index', 'List')
394 list_method[:description].sub!('index', 'list')
395 d_methods[:list] = list_method
400 Rails.configuration.disable_api_methods.each do |method|
401 ctrl, action = method.split('.', 2)
402 discovery[:resources][ctrl][:methods].delete(action.to_sym)