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 websocketUrl: Rails.application.config.websocket_address,
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.clinicalfuture.com/auth/arvados" => {
62 description: "View and manage objects"
64 "https://api.clinicalfuture.com/auth/arvados.readonly" => {
65 description: "View objects"
74 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
76 ctl_class = "Arvados::V1::#{k.to_s.pluralize}Controller".constantize
78 # No controller -> no discovery.
81 object_properties = {}
83 select { |col| col.name != 'id' }.
85 if k.serialized_attributes.has_key? col.name
86 object_properties[col.name] = {
87 type: k.serialized_attributes[col.name].object_class.to_s
90 object_properties[col.name] = {
95 discovery[:schemas][k.to_s + 'List'] = {
97 description: k.to_s + ' list',
102 description: "Object type. Always arvados##{k.to_s.camelcase(:lower)}List.",
103 default: "arvados##{k.to_s.camelcase(:lower)}List"
107 description: "List version."
111 description: "The list of #{k.to_s.pluralize}.",
118 description: "A link to the next page of #{k.to_s.pluralize}."
122 description: "The page token for the next page of #{k.to_s.pluralize}."
126 description: "A link back to this list."
130 discovery[:schemas][k.to_s] = {
134 uuidPrefix: (k.respond_to?(:uuid_prefix) ? k.uuid_prefix : nil),
138 description: "Object ID."
142 description: "Object version."
144 }.merge(object_properties)
146 discovery[:resources][k.to_s.underscore.pluralize] = {
149 id: "arvados.#{k.to_s.underscore.pluralize}.get",
150 path: "#{k.to_s.underscore.pluralize}/{uuid}",
152 description: "Gets a #{k.to_s}'s metadata by UUID.",
156 description: "The UUID of the #{k.to_s} in question.",
168 "https://api.clinicalfuture.com/auth/arvados",
169 "https://api.clinicalfuture.com/auth/arvados.readonly"
173 id: "arvados.#{k.to_s.underscore.pluralize}.list",
174 path: k.to_s.underscore.pluralize,
177 %|List #{k.to_s.pluralize}.
179 The <code>list</code> method returns a
180 <a href="/api/resources.html">resource list</a> of
181 matching #{k.to_s.pluralize}. For example:
185 "kind":"arvados##{k.to_s.camelcase(:lower)}List",
188 "next_page_token":"",
193 "items_available":745,
195 "request_time":0.157236317
201 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
209 description: "Number of #{k.to_s.underscore.pluralize} to skip before first returned record.",
217 description: "Conditions for filtering #{k.to_s.underscore.pluralize}.",
222 description: "Conditions for filtering #{k.to_s.underscore.pluralize}. (Deprecated. Use filters instead.)",
227 description: "Order in which to return matching #{k.to_s.underscore.pluralize}.",
232 "$ref" => "#{k.to_s}List"
235 "https://api.clinicalfuture.com/auth/arvados",
236 "https://api.clinicalfuture.com/auth/arvados.readonly"
240 id: "arvados.#{k.to_s.underscore.pluralize}.create",
241 path: "#{k.to_s.underscore.pluralize}",
243 description: "Create a new #{k.to_s}.",
248 k.to_s.underscore => {
257 "https://api.clinicalfuture.com/auth/arvados"
261 id: "arvados.#{k.to_s.underscore.pluralize}.update",
262 path: "#{k.to_s.underscore.pluralize}/{uuid}",
264 description: "Update attributes of an existing #{k.to_s}.",
268 description: "The UUID of the #{k.to_s} in question.",
276 k.to_s.underscore => {
285 "https://api.clinicalfuture.com/auth/arvados"
289 id: "arvados.#{k.to_s.underscore.pluralize}.delete",
290 path: "#{k.to_s.underscore.pluralize}/{uuid}",
291 httpMethod: "DELETE",
292 description: "Delete an existing #{k.to_s}.",
296 description: "The UUID of the #{k.to_s} in question.",
305 "https://api.clinicalfuture.com/auth/arvados"
310 # Check for Rails routes that don't match the usual actions
312 d_methods = discovery[:resources][k.to_s.underscore.pluralize][:methods]
313 Rails.application.routes.routes.each do |route|
314 action = route.defaults[:action]
315 httpMethod = ['GET', 'POST', 'PUT', 'DELETE'].map { |method|
316 method if route.verb.match(method)
319 route.defaults[:controller] == 'arvados/v1/' + k.to_s.underscore.pluralize and
320 !d_methods[action.to_sym] and
321 ctl_class.action_methods.include? action and
322 ![:show, :index, :destroy].include?(action.to_sym)
324 id: "arvados.#{k.to_s.underscore.pluralize}.#{action}",
325 path: route.path.spec.to_s.sub('/arvados/v1/','').sub('(.:format)','').sub(/:(uu)?id/,'{uuid}'),
326 httpMethod: httpMethod,
327 description: "#{route.defaults[:action]} #{k.to_s.underscore.pluralize}",
330 "$ref" => (action == 'index' ? "#{k.to_s}List" : k.to_s)
333 "https://api.clinicalfuture.com/auth/arvados"
336 route.segment_keys.each do |key|
338 key = :uuid if key == :id
339 method[:parameters][key] = {
347 if ctl_class.respond_to? "_#{action}_requires_parameters".to_sym
348 ctl_class.send("_#{action}_requires_parameters".to_sym).each do |k, v|
350 method[:parameters][k] = v
352 method[:parameters][k] = {}
354 method[:parameters][k][:type] ||= 'string'
355 method[:parameters][k][:description] ||= ''
356 method[:parameters][k][:location] = (route.segment_keys.include?(k) ? 'path' : 'query')
357 if method[:parameters][k][:required].nil?
358 method[:parameters][k][:required] = v != false
362 d_methods[route.defaults[:action].to_sym] = method
368 render json: discovery