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 'discovery_rest_description' 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 'discovery_rest_description' 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 object_properties = {}
92 select { |col| col.name != 'id' }.
94 if k.serialized_attributes.has_key? col.name
95 object_properties[col.name] = {
96 type: k.serialized_attributes[col.name].object_class.to_s
99 object_properties[col.name] = {
104 discovery[:schemas][k.to_s + 'List'] = {
111 description: "Object type. Always orvos##{k.to_s.camelcase(:lower)}List.",
112 default: "orvos##{k.to_s.camelcase(:lower)}List"
116 description: "List version."
120 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] = {
143 description: "Object ID."
147 description: "Object version."
149 }.merge(object_properties)
151 discovery[:resources][k.to_s.underscore.pluralize] = {
154 id: "orvos.#{k.to_s.underscore.pluralize}.get",
155 path: "#{k.to_s.underscore.pluralize}/{uuid}",
157 description: "Gets a #{k.to_s}'s metadata by ID.",
161 description: "The ID for the #{k.to_s} in question.",
173 "https://api.clinicalfuture.com/auth/orvos",
174 "https://api.clinicalfuture.com/auth/orvos.readonly"
178 id: "orvos.#{k.to_s.underscore.pluralize}.list",
179 path: k.to_s.underscore.pluralize,
181 description: "List #{k.to_s.underscore.pluralize}.",
185 description: "Maximum number of #{k.to_s.underscore.pluralize} to return.",
193 description: "Page token.",
198 description: "Query string for searching #{k.to_s.underscore.pluralize}.",
203 "$ref" => "#{k.to_s.pluralize}List"
206 "https://api.clinicalfuture.com/auth/orvos",
207 "https://api.clinicalfuture.com/auth/orvos.readonly"
215 render json: discovery