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 discovery = Rails.cache.fetch 'arvados_v1_rest_discovery' do
21 Rails.application.eager_load!
23 kind: "discovery#restDescription",
24 discoveryVersion: "v1",
29 source_version: AppVersion.hash,
30 generatedAt: db_current_time.iso8601,
32 description: "The API to interact with Arvados.",
33 documentationLink: "http://doc.arvados.org/api/index.html",
34 defaultCollectionReplication: Rails.configuration.default_collection_replication,
36 baseUrl: root_url + "arvados/v1/",
37 basePath: "/arvados/v1/",
39 servicePath: "arvados/v1/",
41 defaultTrashLifetime: Rails.application.config.default_trash_lifetime,
42 blobSignatureTtl: Rails.application.config.blob_signature_ttl,
43 maxRequestSize: Rails.application.config.max_request_size,
44 dockerImageFormats: Rails.application.config.docker_image_formats,
45 crunchLogBytesPerEvent: Rails.application.config.crunch_log_bytes_per_event,
46 crunchLogSecondsBetweenEvents: Rails.application.config.crunch_log_seconds_between_events,
47 crunchLogThrottlePeriod: Rails.application.config.crunch_log_throttle_period,
48 crunchLogThrottleBytes: Rails.application.config.crunch_log_throttle_bytes,
49 crunchLogThrottleLines: Rails.application.config.crunch_log_throttle_lines,
50 crunchLimitLogBytesPerJob: Rails.application.config.crunch_limit_log_bytes_per_job,
51 crunchLogPartialLineThrottlePeriod: Rails.application.config.crunch_log_partial_line_throttle_period,
52 websocketUrl: Rails.application.config.websocket_address,
53 workbenchUrl: Rails.application.config.workbench_address,
54 keepWebServiceUrl: Rails.application.config.keep_web_service_url,
58 description: "Data format for the response.",
64 "Responses with Content-Type of application/json"
70 description: "Selector specifying which fields to include in a partial response.",
75 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.",
80 description: "OAuth 2.0 token for the current user.",
87 "https://api.curoverse.com/auth/arvados" => {
88 description: "View and manage objects"
90 "https://api.curoverse.com/auth/arvados.readonly" => {
91 description: "View objects"
100 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
102 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
104 # No controller -> no discovery.
107 object_properties = {}
109 select { |col| col.name != 'id' }.
111 if k.serialized_attributes.has_key? col.name
112 object_properties[col.name] = {
113 type: k.serialized_attributes[col.name].object_class.to_s
116 object_properties[col.name] = {
121 discovery[:schemas][k.to_s + 'List'] = {
123 description: k.to_s + ' list',
128 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
129 default: "arvados##{k.to_s.camelcase(:lower)}List"
133 description: "List version."
137 description: "The list of #{k.to_s.pluralize}.",
144 description: "A link to the next page of #{k.to_s.pluralize}."
148 description: "The page token for the next page of #{k.to_s.pluralize}."
152 description: "A link back to this list."
156 discovery[:schemas][k.to_s] = {
160 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
164 description: "Object ID."
168 description: "Object version."
170 }.merge(object_properties)
172 discovery[:resources][k.to_s.underscore.pluralize] = {
175 id: "arvados.#{k.to_s.underscore.pluralize}.get",
176 path: "#{k.to_s.underscore.pluralize}/{uuid}",
178 description: "Gets a #{k.to_s}'s metadata by UUID.",
182 description: "The UUID of the #{k.to_s} in question.",
194 "https://api.curoverse.com/auth/arvados",
195 "https://api.curoverse.com/auth/arvados.readonly"
199 id: "arvados.#{k.to_s.underscore.pluralize}.index",
200 path: k.to_s.underscore.pluralize,
203 %|Index #{k.to_s.pluralize}.
205 The <code>index</code> method returns a
206 <a href="/api/resources.html">resource list</a> of
207 matching #{k.to_s.pluralize}. For example:
211 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
214 "next_page_token":"",
219 "items_available":745,
221 "request_time":0.157236317
227 "$ref" => "#{k.to_s}List"
230 "https://api.curoverse.com/auth/arvados",
231 "https://api.curoverse.com/auth/arvados.readonly"
235 id: "arvados.#{k.to_s.underscore.pluralize}.create",
236 path: "#{k.to_s.underscore.pluralize}",
238 description: "Create a new #{k.to_s}.",
243 k.to_s.underscore => {
252 "https://api.curoverse.com/auth/arvados"
256 id: "arvados.#{k.to_s.underscore.pluralize}.update",
257 path: "#{k.to_s.underscore.pluralize}/{uuid}",
259 description: "Update attributes of an existing #{k.to_s}.",
263 description: "The UUID of the #{k.to_s} in question.",
271 k.to_s.underscore => {
280 "https://api.curoverse.com/auth/arvados"
284 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
285 path: "#{k.to_s.underscore.pluralize}/{uuid}",
286 httpMethod: "DELETE",
287 description: "Delete an existing #{k.to_s}.",
291 description: "The UUID of the #{k.to_s} in question.",
300 "https://api.curoverse.com/auth/arvados"
305 # Check for Rails routes that don't match the usual actions
307 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
308 Rails.application.routes.routes.each do |route|
309 action = route.defaults[:action]
310 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
311 method if route.verb.match(method)
314 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
315 ctl_class.action_methods.include? action
316 if !d_methods[action.to_sym]
318 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
319 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
320 httpMethod: httpMethod,
321 description: "#{action} #{k.to_s.underscore.pluralize}",
324 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
327 "https://api.curoverse.com/auth/arvados"
330 route.segment_keys.each do |key|
332 key = :uuid if key == :id
333 method[:parameters][key] = {
342 # We already built a generic method description, but we
343 # might find some more required parameters through
345 method = d_methods[action.to_sym]
347 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
348 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |l, v|
350 method[:parameters][l] = v
352 method[:parameters][l] = {}
354 if !method[:parameters][l][:default].nil?
355 # The JAVA SDK is sensitive to all values being strings
356 method[:parameters][l][:default] = method[:parameters][l][:default].to_s
358 method[:parameters][l][:type] ||= 'string'
359 method[:parameters][l][:description] ||= ''
360 method[:parameters][l][:location] = (route.segment_keys.include?(l) ? 'path' : 'query')
361 if method[:parameters][l][:required].nil?
362 method[:parameters][l][:required] = v != false
366 d_methods[action.to_sym] = method
369 list_method = method.dup
370 list_method[:id].sub!('index', 'list')
371 list_method[:description].sub!('Index', 'List')
372 list_method[:description].sub!('index', 'list')
373 d_methods[:list] = list_method
378 Rails.configuration.disable_api_methods.each do |method|
379 ctrl, action = method.split('.', 2)
380 discovery[:resources][ctrl][:methods].delete(action.to_sym)