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/",
32 description: "Data format for the response.",
38 "Responses with Content-Type of application/json"
44 description: "Selector specifying which fields to include in a partial response.",
49 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.",
54 description: "OAuth 2.0 token for the current user.",
61 "https://api.curoverse.com/auth/arvados" => {
62 description: "View and manage objects"
64 "https://api.curoverse.com/auth/arvados.readonly" => {
65 description: "View objects"
74 if Rails.application.config.websocket_address
75 discovery[:websocketUrl] = Rails.application.config.websocket_address
76 elsif ENV['ARVADOS_WEBSOCKETS']
77 discovery[:websocketUrl] = (root_url.sub /^http/, 'ws') + "websocket"
80 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
82 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
84 # No controller -> no discovery.
87 object_properties = {}
89 select { |col| col.name != 'id' }.
91 if k.serialized_attributes.has_key? col.name
92 object_properties[col.name] = {
93 type: k.serialized_attributes[col.name].object_class.to_s
96 object_properties[col.name] = {
101 discovery[:schemas][k.to_s + 'List'] = {
103 description: k.to_s + ' list',
108 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
109 default: "arvados##{k.to_s.camelcase(:lower)}List"
113 description: "List version."
117 description: "The list of #{k.to_s.pluralize}.",
124 description: "A link to the next page of #{k.to_s.pluralize}."
128 description: "The page token for the next page of #{k.to_s.pluralize}."
132 description: "A link back to this list."
136 discovery[:schemas][k.to_s] = {
140 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
144 description: "Object ID."
148 description: "Object version."
150 }.merge(object_properties)
152 discovery[:resources][k.to_s.underscore.pluralize] = {
155 id: "arvados.#{k.to_s.underscore.pluralize}.get",
156 path: "#{k.to_s.underscore.pluralize}/{uuid}",
158 description: "Gets a #{k.to_s}'s metadata by UUID.",
162 description: "The UUID of the #{k.to_s} in question.",
174 "https://api.curoverse.com/auth/arvados",
175 "https://api.curoverse.com/auth/arvados.readonly"
179 id: "arvados.#{k.to_s.underscore.pluralize}.list",
180 path: k.to_s.underscore.pluralize,
183 %|List #{k.to_s.pluralize}.
185 The <code>list</code> method returns a
186 <a href="/api/resources.html">resource list</a> of
187 matching #{k.to_s.pluralize}. For example:
191 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
194 "next_page_token":"",
199 "items_available":745,
201 "request_time":0.157236317
207 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
215 description: "Number of #{k.to_s.underscore.pluralize} to skip before first returned record.",
223 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
228 description: "Conditions for filtering #{k.to_s.underscore.pluralize}. (Deprecated. Use filters instead.)",
233 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
238 description: "Select which fields to return",
243 description: "Return each distinct object",
248 "$ref" => "#{k.to_s}List"
251 "https://api.curoverse.com/auth/arvados",
252 "https://api.curoverse.com/auth/arvados.readonly"
256 id: "arvados.#{k.to_s.underscore.pluralize}.create",
257 path: "#{k.to_s.underscore.pluralize}",
259 description: "Create a new #{k.to_s}.",
261 ensure_unique_name: {
263 description: "Adjust name to ensure uniqueness instead of returning an error on (owner_uuid, name) collision.",
270 k.to_s.underscore => {
279 "https://api.curoverse.com/auth/arvados"
283 id: "arvados.#{k.to_s.underscore.pluralize}.update",
284 path: "#{k.to_s.underscore.pluralize}/{uuid}",
286 description: "Update attributes of an existing #{k.to_s}.",
290 description: "The UUID of the #{k.to_s} in question.",
298 k.to_s.underscore => {
307 "https://api.curoverse.com/auth/arvados"
311 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
312 path: "#{k.to_s.underscore.pluralize}/{uuid}",
313 httpMethod: "DELETE",
314 description: "Delete an existing #{k.to_s}.",
318 description: "The UUID of the #{k.to_s} in question.",
327 "https://api.curoverse.com/auth/arvados"
332 # Check for Rails routes that don't match the usual actions
334 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
335 Rails.application.routes.routes.each do |route|
336 action = route.defaults[:action]
337 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
338 method if route.verb.match(method)
341 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
342 ctl_class.action_methods.include? action
343 if !d_methods[action.to_sym]
345 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
346 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
347 httpMethod: httpMethod,
348 description: "#{action} #{k.to_s.underscore.pluralize}",
351 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
354 "https://api.curoverse.com/auth/arvados"
357 route.segment_keys.each do |key|
359 key = :uuid if key == :id
360 method[:parameters][key] = {
369 # We already built a generic method description, but we
370 # might find some more required parameters through
372 method = d_methods[action.to_sym]
374 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
375 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
377 method[:parameters][k] = v
379 method[:parameters][k] = {}
381 if !method[:parameters][k][:default].nil?
382 # The JAVA SDK is sensitive to all values being strings
383 method[:parameters][k][:default] = method[:parameters][k][:default].to_s
385 method[:parameters][k][:type] ||= 'string'
386 method[:parameters][k][:description] ||= ''
387 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
388 if method[:parameters][k][:required].nil?
389 method[:parameters][k][:required] = v != false
393 d_methods[action.to_sym] = method
399 render json: discovery