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_all
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 generatedAt: Time.now.iso8601,
20 description: "The API to interact with Arvados.",
21 documentationLink: "http://doc.arvados.org/api/index.html",
23 baseUrl: root_url + "/arvados/v1/",
24 basePath: "/arvados/v1/",
26 servicePath: "arvados/v1/",
31 description: "Data format for the response.",
37 "Responses with Content-Type of application/json"
43 description: "Selector specifying which fields to include in a partial response.",
48 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.",
53 description: "OAuth 2.0 token for the current user.",
60 "https://api.clinicalfuture.com/auth/arvados" => {
61 description: "View and manage objects"
63 "https://api.clinicalfuture.com/auth/arvados.readonly" => {
64 description: "View objects"
73 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
75 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
77 # No controller -> no discovery.
80 object_properties = {}
82 select { |col| col.name != 'id' }.
84 if k.serialized_attributes.has_key? col.name
85 object_properties[col.name] = {
86 type: k.serialized_attributes[col.name].object_class.to_s
89 object_properties[col.name] = {
94 discovery[:schemas][k.to_s + 'List'] = {
96 description: k.to_s + ' list',
101 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
102 default: "arvados##{k.to_s.camelcase(:lower)}List"
106 description: "List version."
110 description: "The list of #{k.to_s.pluralize}.",
117 description: "A link to the next page of #{k.to_s.pluralize}."
121 description: "The page token for the next page of #{k.to_s.pluralize}."
125 description: "A link back to this list."
129 discovery[:schemas][k.to_s] = {
133 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
137 description: "Object ID."
141 description: "Object version."
143 }.merge(object_properties)
145 discovery[:resources][k.to_s.underscore.pluralize] = {
148 id: "arvados.#{k.to_s.underscore.pluralize}.get",
149 path: "#{k.to_s.underscore.pluralize}/{uuid}",
151 description: "Gets a #{k.to_s}'s metadata by UUID.",
155 description: "The UUID of the #{k.to_s} in question.",
167 "https://api.clinicalfuture.com/auth/arvados",
168 "https://api.clinicalfuture.com/auth/arvados.readonly"
172 id: "arvados.#{k.to_s.underscore.pluralize}.list",
173 path: k.to_s.underscore.pluralize,
176 %|List #{k.to_s.pluralize}.
178 The <code>list</code> method returns a
179 <a href="/api/resources.html">resource list</a> of
180 matching #{k.to_s.pluralize}. For example:
184 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
187 "next_page_token":"",
192 "items_available":745,
194 "request_time":0.157236317
200 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
208 description: "Number of #{k.to_s.underscore.pluralize} to skip before first returned record.",
216 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
221 description: "Conditions for filtering #{k.to_s.underscore.pluralize}. (Deprecated. Use filters instead.)",
226 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
231 "$ref" => "#{k.to_s}List"
234 "https://api.clinicalfuture.com/auth/arvados",
235 "https://api.clinicalfuture.com/auth/arvados.readonly"
239 id: "arvados.#{k.to_s.underscore.pluralize}.create",
240 path: "#{k.to_s.underscore.pluralize}",
242 description: "Create a new #{k.to_s}.",
247 k.to_s.underscore => {
256 "https://api.clinicalfuture.com/auth/arvados"
260 id: "arvados.#{k.to_s.underscore.pluralize}.update",
261 path: "#{k.to_s.underscore.pluralize}/{uuid}",
263 description: "Update attributes of an existing #{k.to_s}.",
267 description: "The UUID of the #{k.to_s} in question.",
275 k.to_s.underscore => {
284 "https://api.clinicalfuture.com/auth/arvados"
288 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
289 path: "#{k.to_s.underscore.pluralize}/{uuid}",
290 httpMethod: "DELETE",
291 description: "Delete an existing #{k.to_s}.",
295 description: "The UUID of the #{k.to_s} in question.",
304 "https://api.clinicalfuture.com/auth/arvados"
309 # Check for Rails routes that don't match the usual actions
311 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
312 Rails.application.routes.routes.each do |route|
313 action = route.defaults[:action]
314 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
315 method if route.verb.match(method)
318 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
319 !d_methods[action.to_sym] and
320 ctl_class.action_methods.include? action and
321 ![:show, :index, :destroy].include?(action.to_sym)
323 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
324 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
325 httpMethod: httpMethod,
326 description: "#{route.defaults[:action]} #{k.to_s.underscore.pluralize}",
329 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
332 "https://api.clinicalfuture.com/auth/arvados"
335 route.segment_keys.each do |key|
337 key = :uuid if key == :id
338 method[:parameters][key] = {
346 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
347 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
349 method[:parameters][k] = v
351 method[:parameters][k] = {}
353 method[:parameters][k][:type] ||= 'string'
354 method[:parameters][k][:description] ||= ''
355 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
356 if method[:parameters][k][:required].nil?
357 method[:parameters][k][:required] = v != false
361 d_methods[route.defaults[:action].to_sym] = method
367 render json: discovery