1 class Arvados::V1::SchemaController < ApplicationController
2 skip_before_filter :find_objects_for_index
3 skip_before_filter :find_object_by_uuid
4 skip_before_filter :render_404_if_no_object
5 skip_before_filter :require_auth_scope
8 expires_in 24.hours, public: true
9 discovery = Rails.cache.fetch 'arvados_v1_rest_discovery' do
10 Rails.application.eager_load!
12 kind: "discovery#restDescription",
13 discoveryVersion: "v1",
18 source_version: (Rails.application.config.source_version ? Rails.application.config.source_version : "No version information available") + (Rails.application.config.local_modified ? Rails.application.config.local_modified.to_s : ''),
19 generatedAt: Time.now.iso8601,
21 description: "The API to interact with Arvados.",
22 documentationLink: "http://doc.arvados.org/api/index.html",
24 baseUrl: root_url + "arvados/v1/",
25 basePath: "/arvados/v1/",
27 servicePath: "arvados/v1/",
29 defaultTrashLifetime: Rails.application.config.default_trash_lifetime,
33 description: "Data format for the response.",
39 "Responses with Content-Type of application/json"
45 description: "Selector specifying which fields to include in a partial response.",
50 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.",
55 description: "OAuth 2.0 token for the current user.",
62 "https://api.curoverse.com/auth/arvados" => {
63 description: "View and manage objects"
65 "https://api.curoverse.com/auth/arvados.readonly" => {
66 description: "View objects"
75 if Rails.application.config.websocket_address
76 discovery[:websocketUrl] = Rails.application.config.websocket_address
77 elsif ENV['ARVADOS_WEBSOCKETS']
78 discovery[:websocketUrl] = (root_url.sub /^http/, 'ws') + "websocket"
81 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
83 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
85 # No controller -> no discovery.
88 object_properties = {}
90 select { |col| col.name != 'id' }.
92 if k.serialized_attributes.has_key? col.name
93 object_properties[col.name] = {
94 type: k.serialized_attributes[col.name].object_class.to_s
97 object_properties[col.name] = {
102 discovery[:schemas][k.to_s + 'List'] = {
104 description: k.to_s + ' list',
109 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
110 default: "arvados##{k.to_s.camelcase(:lower)}List"
114 description: "List version."
118 description: "The list of #{k.to_s.pluralize}.",
125 description: "A link to the next page of #{k.to_s.pluralize}."
129 description: "The page token for the next page of #{k.to_s.pluralize}."
133 description: "A link back to this list."
137 discovery[:schemas][k.to_s] = {
141 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
145 description: "Object ID."
149 description: "Object version."
151 }.merge(object_properties)
153 discovery[:resources][k.to_s.underscore.pluralize] = {
156 id: "arvados.#{k.to_s.underscore.pluralize}.get",
157 path: "#{k.to_s.underscore.pluralize}/{uuid}",
159 description: "Gets a #{k.to_s}'s metadata by UUID.",
163 description: "The UUID of the #{k.to_s} in question.",
175 "https://api.curoverse.com/auth/arvados",
176 "https://api.curoverse.com/auth/arvados.readonly"
180 id: "arvados.#{k.to_s.underscore.pluralize}.list",
181 path: k.to_s.underscore.pluralize,
184 %|List #{k.to_s.pluralize}.
186 The <code>list</code> method returns a
187 <a href="/api/resources.html">resource list</a> of
188 matching #{k.to_s.pluralize}. For example:
192 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
195 "next_page_token":"",
200 "items_available":745,
202 "request_time":0.157236317
208 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
216 description: "Number of #{k.to_s.underscore.pluralize} to skip before first returned record.",
224 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
229 description: "Conditions for filtering #{k.to_s.underscore.pluralize}. (Deprecated. Use filters instead.)",
234 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
239 description: "Select which fields to return",
244 description: "Return each distinct object",
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}.",
262 ensure_unique_name: {
264 description: "Adjust name to ensure uniqueness instead of returning an error on (owner_uuid, name) collision.",
271 k.to_s.underscore => {
280 "https://api.curoverse.com/auth/arvados"
284 id: "arvados.#{k.to_s.underscore.pluralize}.update",
285 path: "#{k.to_s.underscore.pluralize}/{uuid}",
287 description: "Update attributes of an existing #{k.to_s}.",
291 description: "The UUID of the #{k.to_s} in question.",
299 k.to_s.underscore => {
308 "https://api.curoverse.com/auth/arvados"
312 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
313 path: "#{k.to_s.underscore.pluralize}/{uuid}",
314 httpMethod: "DELETE",
315 description: "Delete an existing #{k.to_s}.",
319 description: "The UUID of the #{k.to_s} in question.",
328 "https://api.curoverse.com/auth/arvados"
333 # Check for Rails routes that don't match the usual actions
335 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
336 Rails.application.routes.routes.each do |route|
337 action = route.defaults[:action]
338 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
339 method if route.verb.match(method)
342 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
343 ctl_class.action_methods.include? action
344 if !d_methods[action.to_sym]
346 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
347 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
348 httpMethod: httpMethod,
349 description: "#{action} #{k.to_s.underscore.pluralize}",
352 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
355 "https://api.curoverse.com/auth/arvados"
358 route.segment_keys.each do |key|
360 key = :uuid if key == :id
361 method[:parameters][key] = {
370 # We already built a generic method description, but we
371 # might find some more required parameters through
373 method = d_methods[action.to_sym]
375 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
376 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
378 method[:parameters][k] = v
380 method[:parameters][k] = {}
382 if !method[:parameters][k][:default].nil?
383 # The JAVA SDK is sensitive to all values being strings
384 method[:parameters][k][:default] = method[:parameters][k][:default].to_s
386 method[:parameters][k][:type] ||= 'string'
387 method[:parameters][k][:description] ||= ''
388 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
389 if method[:parameters][k][:required].nil?
390 method[:parameters][k][:required] = v != false
394 d_methods[action.to_sym] = method
400 render json: discovery