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,
41 crunchLogBytesPerEvent: Rails.application.config.crunch_log_bytes_per_event,
42 crunchLogSecondsBetweenEvents: Rails.application.config.crunch_log_seconds_between_events,
43 crunchLogThrottlePeriod: Rails.application.config.crunch_log_throttle_period,
44 crunchLogThrottleBytes: Rails.application.config.crunch_log_throttle_bytes,
45 crunchLogThrottleLines: Rails.application.config.crunch_log_throttle_lines,
46 crunchLimitLogBytesPerJob: Rails.application.config.crunch_limit_log_bytes_per_job,
47 crunchLogPartialLineThrottlePeriod: Rails.application.config.crunch_log_partial_line_throttle_period,
48 websocketUrl: Rails.application.config.websocket_address,
52 description: "Data format for the response.",
58 "Responses with Content-Type of application/json"
64 description: "Selector specifying which fields to include in a partial response.",
69 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.",
74 description: "OAuth 2.0 token for the current user.",
81 "https://api.curoverse.com/auth/arvados" => {
82 description: "View and manage objects"
84 "https://api.curoverse.com/auth/arvados.readonly" => {
85 description: "View objects"
94 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
96 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
98 # No controller -> no discovery.
101 object_properties = {}
103 select { |col| col.name != 'id' }.
105 if k.serialized_attributes.has_key? col.name
106 object_properties[col.name] = {
107 type: k.serialized_attributes[col.name].object_class.to_s
110 object_properties[col.name] = {
115 discovery[:schemas][k.to_s + 'List'] = {
117 description: k.to_s + ' list',
122 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
123 default: "arvados##{k.to_s.camelcase(:lower)}List"
127 description: "List version."
131 description: "The list of #{k.to_s.pluralize}.",
138 description: "A link to the next page of #{k.to_s.pluralize}."
142 description: "The page token for the next page of #{k.to_s.pluralize}."
146 description: "A link back to this list."
150 discovery[:schemas][k.to_s] = {
154 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
158 description: "Object ID."
162 description: "Object version."
164 }.merge(object_properties)
166 discovery[:resources][k.to_s.underscore.pluralize] = {
169 id: "arvados.#{k.to_s.underscore.pluralize}.get",
170 path: "#{k.to_s.underscore.pluralize}/{uuid}",
172 description: "Gets a #{k.to_s}'s metadata by UUID.",
176 description: "The UUID of the #{k.to_s} in question.",
188 "https://api.curoverse.com/auth/arvados",
189 "https://api.curoverse.com/auth/arvados.readonly"
193 id: "arvados.#{k.to_s.underscore.pluralize}.index",
194 path: k.to_s.underscore.pluralize,
197 %|Index #{k.to_s.pluralize}.
199 The <code>index</code> method returns a
200 <a href="/api/resources.html">resource list</a> of
201 matching #{k.to_s.pluralize}. For example:
205 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
208 "next_page_token":"",
213 "items_available":745,
215 "request_time":0.157236317
221 "$ref" => "#{k.to_s}List"
224 "https://api.curoverse.com/auth/arvados",
225 "https://api.curoverse.com/auth/arvados.readonly"
229 id: "arvados.#{k.to_s.underscore.pluralize}.create",
230 path: "#{k.to_s.underscore.pluralize}",
232 description: "Create a new #{k.to_s}.",
237 k.to_s.underscore => {
246 "https://api.curoverse.com/auth/arvados"
250 id: "arvados.#{k.to_s.underscore.pluralize}.update",
251 path: "#{k.to_s.underscore.pluralize}/{uuid}",
253 description: "Update attributes of an existing #{k.to_s}.",
257 description: "The UUID of the #{k.to_s} in question.",
265 k.to_s.underscore => {
274 "https://api.curoverse.com/auth/arvados"
278 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
279 path: "#{k.to_s.underscore.pluralize}/{uuid}",
280 httpMethod: "DELETE",
281 description: "Delete an existing #{k.to_s}.",
285 description: "The UUID of the #{k.to_s} in question.",
294 "https://api.curoverse.com/auth/arvados"
299 # Check for Rails routes that don't match the usual actions
301 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
302 Rails.application.routes.routes.each do |route|
303 action = route.defaults[:action]
304 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
305 method if route.verb.match(method)
308 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
309 ctl_class.action_methods.include? action
310 if !d_methods[action.to_sym]
312 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
313 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
314 httpMethod: httpMethod,
315 description: "#{action} #{k.to_s.underscore.pluralize}",
318 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
321 "https://api.curoverse.com/auth/arvados"
324 route.segment_keys.each do |key|
326 key = :uuid if key == :id
327 method[:parameters][key] = {
336 # We already built a generic method description, but we
337 # might find some more required parameters through
339 method = d_methods[action.to_sym]
341 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
342 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |l, v|
344 method[:parameters][l] = v
346 method[:parameters][l] = {}
348 if !method[:parameters][l][:default].nil?
349 # The JAVA SDK is sensitive to all values being strings
350 method[:parameters][l][:default] = method[:parameters][l][:default].to_s
352 method[:parameters][l][:type] ||= 'string'
353 method[:parameters][l][:description] ||= ''
354 method[:parameters][l][:location] = (route.segment_keys.include?(l) ? 'path' : 'query')
355 if method[:parameters][l][:required].nil?
356 method[:parameters][l][:required] = v != false
360 d_methods[action.to_sym] = method
363 list_method = method.dup
364 list_method[:id].sub!('index', 'list')
365 list_method[:description].sub!('Index', 'List')
366 list_method[:description].sub!('index', 'list')
367 d_methods[:list] = list_method
372 Rails.configuration.disable_api_methods.each do |method|
373 ctrl, action = method.split('.', 2)
374 discovery[:resources][ctrl][:methods].delete(action.to_sym)