1 class Orvos::V1::SchemaController < ApplicationController
2 skip_before_filter :find_object_by_uuid
3 skip_before_filter :login_required
6 classes = Rails.cache.fetch 'orvos_v1_schema' do
7 Rails.application.eager_load!
9 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
10 classes[k] = k.columns.collect do |col|
11 if k.serialized_attributes.has_key? col.name
13 type: k.serialized_attributes[col.name].object_class.to_s }
25 def discovery_rest_description
26 discovery = Rails.cache.fetch 'orvos_v1_rest_discovery' do
27 Rails.application.eager_load!
29 kind: "discovery#restDescription",
30 discoveryVersion: "v1",
36 description: "The API to interact with Orvos.",
37 documentationLink: "https://redmine.clinicalfuture.com/projects/orvos/",
39 baseUrl: root_url + "/orvos/v1/",
40 basePath: "/orvos/v1/",
42 servicePath: "orvos/v1/",
47 description: "Data format for the response.",
53 "Responses with Content-Type of application/json"
59 description: "Selector specifying which fields to include in a partial response.",
64 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.",
69 description: "OAuth 2.0 token for the current user.",
76 "https://api.clinicalfuture.com/auth/orvos" => {
77 description: "View and manage objects"
79 "https://api.clinicalfuture.com/auth/orvos.readonly" => {
80 description: "View objects"
89 ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k|
90 next if k == ApiClientAuthorization
91 next if k == ApiClient
92 object_properties = {}
94 select { |col| col.name != 'id' }.
96 if k.serialized_attributes.has_key? col.name
97 object_properties[col.name] = {
98 type: k.serialized_attributes[col.name].object_class.to_s
101 object_properties[col.name] = {
106 discovery[:schemas][k.to_s + 'List'] = {
113 description: "Object type. Always orvos##{k.to_s.camelcase(:lower)}List.",
114 default: "orvos##{k.to_s.camelcase(:lower)}List"
118 description: "List version."
122 description: "The list of #{k.to_s.pluralize}.",
129 description: "A link to the next page of #{k.to_s.pluralize}."
133 description: "The page token for the next page of #{k.to_s.pluralize}."
137 description: "A link back to this list."
141 discovery[:schemas][k.to_s] = {
148 description: "Object ID."
152 description: "Object version."
154 }.merge(object_properties)
156 discovery[:resources][k.to_s.underscore.pluralize] = {
159 id: "orvos.#{k.to_s.underscore.pluralize}.get",
160 path: "#{k.to_s.underscore.pluralize}/{uuid}",
162 description: "Gets a #{k.to_s}'s metadata by UUID.",
166 description: "The UUID of the #{k.to_s} in question.",
178 "https://api.clinicalfuture.com/auth/orvos",
179 "https://api.clinicalfuture.com/auth/orvos.readonly"
183 id: "orvos.#{k.to_s.underscore.pluralize}.list",
184 path: k.to_s.underscore.pluralize,
186 description: "List #{k.to_s.underscore.pluralize}.",
190 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
198 description: "Page token.",
203 description: "Query string for searching #{k.to_s.underscore.pluralize}.",
208 "$ref" => "#{k.to_s}List"
211 "https://api.clinicalfuture.com/auth/orvos",
212 "https://api.clinicalfuture.com/auth/orvos.readonly"
216 id: "orvos.#{k.to_s.underscore.pluralize}.create",
217 path: "#{k.to_s.underscore.pluralize}",
219 description: "Create a new #{k.to_s}.",
221 k.to_s.underscore => {
225 properties: object_properties
235 "https://api.clinicalfuture.com/auth/orvos"
239 id: "orvos.#{k.to_s.underscore.pluralize}.update",
240 path: "#{k.to_s.underscore.pluralize}/{uuid}",
242 description: "Update attributes of an existing #{k.to_s}.",
246 description: "The UUID of the #{k.to_s} in question.",
250 k.to_s.underscore => {
254 properties: object_properties
264 "https://api.clinicalfuture.com/auth/orvos"
268 id: "orvos.#{k.to_s.underscore.pluralize}.delete",
269 path: "#{k.to_s.underscore.pluralize}/{uuid}",
270 httpMethod: "DELETE",
271 description: "Delete an existing #{k.to_s}.",
275 description: "The UUID of the #{k.to_s} in question.",
284 "https://api.clinicalfuture.com/auth/orvos"
292 render json: discovery