camaleon_cms 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of camaleon_cms might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/app/apps/plugins/contact_form/admin_forms_controller.rb +0 -9
- data/app/apps/plugins/contact_form/contact_form_helper.rb +94 -3
- data/app/apps/plugins/contact_form/front_controller.rb +2 -68
- data/app/apps/plugins/front_cache/front_cache_helper.rb +6 -2
- data/app/controllers/admin/appearances/widgets/assign_controller.rb +3 -3
- data/app/controllers/admin/appearances/widgets/sidebar_controller.rb +5 -5
- data/app/controllers/admin/sessions_controller.rb +1 -1
- data/app/controllers/api/api_controller.rb +13 -7
- data/app/controllers/api/v1/category_controller.rb +9 -1
- data/app/controllers/api/v1/contact_form_controller.rb +55 -0
- data/app/controllers/camaleon_controller.rb +10 -3
- data/app/helpers/session_helper.rb +2 -2
- data/app/helpers/theme_helper.rb +12 -0
- data/app/serializers/api/base_serializer.rb +9 -0
- data/app/serializers/api/v1/category_serializer.rb +8 -0
- data/app/views/admin/settings/custom_fields/get_items.html.erb +4 -2
- data/app/views/default_theme/layouts/index.html.erb +1 -1
- data/config/initializers/swagger.rb +18 -0
- data/config/locales/admin/en.yml +12 -2
- data/config/locales/languages.yml +14 -0
- data/config/locales/ru.yml +207 -0
- data/config/routes.rb +5 -0
- data/config/routes/admin.rb +2 -0
- data/lib/camaleon_cms/engine.rb +5 -0
- data/lib/camaleon_cms/version.rb +1 -1
- data/lib/generators/camaleon_cms/gem_plugin_generator.rb +23 -23
- data/lib/generators/ctheme_template/app/apps/themes/my_theme/views/layouts/index.html.erb +1 -1
- data/lib/tasks/precompile_overrides.rake +6 -0
- data/public/docs/index.html +70 -0
- data/public/docs/swagger-ui/css/highlight.default.css +135 -0
- data/public/docs/swagger-ui/css/screen.css +1070 -0
- data/public/docs/swagger-ui/images/logo_small.png +0 -0
- data/public/docs/swagger-ui/images/throbber.gif +0 -0
- data/public/docs/swagger-ui/lib/backbone-min.js +38 -0
- data/public/docs/swagger-ui/lib/handlebars-1.0.0.js +2278 -0
- data/public/docs/swagger-ui/lib/highlight.7.3.pack.js +1 -0
- data/public/docs/swagger-ui/lib/jquery-1.8.0.min.js +2 -0
- data/public/docs/swagger-ui/lib/jquery.ba-bbq.min.js +18 -0
- data/public/docs/swagger-ui/lib/jquery.slideto.min.js +1 -0
- data/public/docs/swagger-ui/lib/jquery.wiggle.min.js +8 -0
- data/public/docs/swagger-ui/lib/shred.bundle.js +2765 -0
- data/public/docs/swagger-ui/lib/shred/content.js +193 -0
- data/public/docs/swagger-ui/lib/swagger.js +1253 -0
- data/public/docs/swagger-ui/lib/underscore-min.js +32 -0
- data/public/docs/swagger-ui/swagger-ui.js +2039 -0
- data/public/docs/swagger-ui/swagger-ui.min.js +1 -0
- metadata +56 -11
- data/app/views/admin/settings/shortcodes.html.erb +0 -37
- data/lib/generators/camaleon_cms/gem_theme_generator.rb +0 -122
- data/test/camaleon_cms_test.rb +0 -7
- data/test/integration/navigation_test.rb +0 -10
- data/test/test_helper.rb +0 -19
@@ -0,0 +1,193 @@
|
|
1
|
+
|
2
|
+
// The purpose of the `Content` object is to abstract away the data conversions
|
3
|
+
// to and from raw content entities as strings. For example, you want to be able
|
4
|
+
// to pass in a Javascript object and have it be automatically converted into a
|
5
|
+
// JSON string if the `content-type` is set to a JSON-based media type.
|
6
|
+
// Conversely, you want to be able to transparently get back a Javascript object
|
7
|
+
// in the response if the `content-type` is a JSON-based media-type.
|
8
|
+
|
9
|
+
// One limitation of the current implementation is that it [assumes the `charset` is UTF-8](https://github.com/spire-io/shred/issues/5).
|
10
|
+
|
11
|
+
// The `Content` constructor takes an options object, which *must* have either a
|
12
|
+
// `body` or `data` property and *may* have a `type` property indicating the
|
13
|
+
// media type. If there is no `type` attribute, a default will be inferred.
|
14
|
+
var Content = function(options) {
|
15
|
+
this.body = options.body;
|
16
|
+
this.data = options.data;
|
17
|
+
this.type = options.type;
|
18
|
+
};
|
19
|
+
|
20
|
+
Content.prototype = {
|
21
|
+
// Treat `toString()` as asking for the `content.body`. That is, the raw content entity.
|
22
|
+
//
|
23
|
+
// toString: function() { return this.body; }
|
24
|
+
//
|
25
|
+
// Commented out, but I've forgotten why. :/
|
26
|
+
};
|
27
|
+
|
28
|
+
|
29
|
+
// `Content` objects have the following attributes:
|
30
|
+
Object.defineProperties(Content.prototype,{
|
31
|
+
|
32
|
+
// - **type**. Typically accessed as `content.type`, reflects the `content-type`
|
33
|
+
// header associated with the request or response. If not passed as an options
|
34
|
+
// to the constructor or set explicitly, it will infer the type the `data`
|
35
|
+
// attribute, if possible, and, failing that, will default to `text/plain`.
|
36
|
+
type: {
|
37
|
+
get: function() {
|
38
|
+
if (this._type) {
|
39
|
+
return this._type;
|
40
|
+
} else {
|
41
|
+
if (this._data) {
|
42
|
+
switch(typeof this._data) {
|
43
|
+
case "string": return "text/plain";
|
44
|
+
case "object": return "application/json";
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
return "text/plain";
|
49
|
+
},
|
50
|
+
set: function(value) {
|
51
|
+
this._type = value;
|
52
|
+
return this;
|
53
|
+
},
|
54
|
+
enumerable: true
|
55
|
+
},
|
56
|
+
|
57
|
+
// - **data**. Typically accessed as `content.data`, reflects the content entity
|
58
|
+
// converted into Javascript data. This can be a string, if the `type` is, say,
|
59
|
+
// `text/plain`, but can also be a Javascript object. The conversion applied is
|
60
|
+
// based on the `processor` attribute. The `data` attribute can also be set
|
61
|
+
// directly, in which case the conversion will be done the other way, to infer
|
62
|
+
// the `body` attribute.
|
63
|
+
data: {
|
64
|
+
get: function() {
|
65
|
+
if (this._body) {
|
66
|
+
return this.processor.parser(this._body);
|
67
|
+
} else {
|
68
|
+
return this._data;
|
69
|
+
}
|
70
|
+
},
|
71
|
+
set: function(data) {
|
72
|
+
if (this._body&&data) Errors.setDataWithBody(this);
|
73
|
+
this._data = data;
|
74
|
+
return this;
|
75
|
+
},
|
76
|
+
enumerable: true
|
77
|
+
},
|
78
|
+
|
79
|
+
// - **body**. Typically accessed as `content.body`, reflects the content entity
|
80
|
+
// as a UTF-8 string. It is the mirror of the `data` attribute. If you set the
|
81
|
+
// `data` attribute, the `body` attribute will be inferred and vice-versa. If
|
82
|
+
// you attempt to set both, an exception is raised.
|
83
|
+
body: {
|
84
|
+
get: function() {
|
85
|
+
if (this._data) {
|
86
|
+
return this.processor.stringify(this._data);
|
87
|
+
} else {
|
88
|
+
return this._body.toString();
|
89
|
+
}
|
90
|
+
},
|
91
|
+
set: function(body) {
|
92
|
+
if (this._data&&body) Errors.setBodyWithData(this);
|
93
|
+
this._body = body;
|
94
|
+
return this;
|
95
|
+
},
|
96
|
+
enumerable: true
|
97
|
+
},
|
98
|
+
|
99
|
+
// - **processor**. The functions that will be used to convert to/from `data` and
|
100
|
+
// `body` attributes. You can add processors. The two that are built-in are for
|
101
|
+
// `text/plain`, which is basically an identity transformation and
|
102
|
+
// `application/json` and other JSON-based media types (including custom media
|
103
|
+
// types with `+json`). You can add your own processors. See below.
|
104
|
+
processor: {
|
105
|
+
get: function() {
|
106
|
+
var processor = Content.processors[this.type];
|
107
|
+
if (processor) {
|
108
|
+
return processor;
|
109
|
+
} else {
|
110
|
+
// Return the first processor that matches any part of the
|
111
|
+
// content type. ex: application/vnd.foobar.baz+json will match json.
|
112
|
+
var main = this.type.split(";")[0];
|
113
|
+
var parts = main.split(/\+|\//);
|
114
|
+
for (var i=0, l=parts.length; i < l; i++) {
|
115
|
+
processor = Content.processors[parts[i]]
|
116
|
+
}
|
117
|
+
return processor || {parser:identity,stringify:toString};
|
118
|
+
}
|
119
|
+
},
|
120
|
+
enumerable: true
|
121
|
+
},
|
122
|
+
|
123
|
+
// - **length**. Typically accessed as `content.length`, returns the length in
|
124
|
+
// bytes of the raw content entity.
|
125
|
+
length: {
|
126
|
+
get: function() {
|
127
|
+
if (typeof Buffer !== 'undefined') {
|
128
|
+
return Buffer.byteLength(this.body);
|
129
|
+
}
|
130
|
+
return this.body.length;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
});
|
134
|
+
|
135
|
+
Content.processors = {};
|
136
|
+
|
137
|
+
// The `registerProcessor` function allows you to add your own processors to
|
138
|
+
// convert content entities. Each processor consists of a Javascript object with
|
139
|
+
// two properties:
|
140
|
+
// - **parser**. The function used to parse a raw content entity and convert it
|
141
|
+
// into a Javascript data type.
|
142
|
+
// - **stringify**. The function used to convert a Javascript data type into a
|
143
|
+
// raw content entity.
|
144
|
+
Content.registerProcessor = function(types,processor) {
|
145
|
+
|
146
|
+
// You can pass an array of types that will trigger this processor, or just one.
|
147
|
+
// We determine the array via duck-typing here.
|
148
|
+
if (types.forEach) {
|
149
|
+
types.forEach(function(type) {
|
150
|
+
Content.processors[type] = processor;
|
151
|
+
});
|
152
|
+
} else {
|
153
|
+
// If you didn't pass an array, we just use what you pass in.
|
154
|
+
Content.processors[types] = processor;
|
155
|
+
}
|
156
|
+
};
|
157
|
+
|
158
|
+
// Register the identity processor, which is used for text-based media types.
|
159
|
+
var identity = function(x) { return x; }
|
160
|
+
, toString = function(x) { return x.toString(); }
|
161
|
+
Content.registerProcessor(
|
162
|
+
["text/html","text/plain","text"],
|
163
|
+
{ parser: identity, stringify: toString });
|
164
|
+
|
165
|
+
// Register the JSON processor, which is used for JSON-based media types.
|
166
|
+
Content.registerProcessor(
|
167
|
+
["application/json; charset=utf-8","application/json","json"],
|
168
|
+
{
|
169
|
+
parser: function(string) {
|
170
|
+
return JSON.parse(string);
|
171
|
+
},
|
172
|
+
stringify: function(data) {
|
173
|
+
return JSON.stringify(data); }});
|
174
|
+
|
175
|
+
var qs = require('querystring');
|
176
|
+
// Register the post processor, which is used for JSON-based media types.
|
177
|
+
Content.registerProcessor(
|
178
|
+
["application/x-www-form-urlencoded"],
|
179
|
+
{ parser : qs.parse, stringify : qs.stringify });
|
180
|
+
|
181
|
+
// Error functions are defined separately here in an attempt to make the code
|
182
|
+
// easier to read.
|
183
|
+
var Errors = {
|
184
|
+
setDataWithBody: function(object) {
|
185
|
+
throw new Error("Attempt to set data attribute of a content object " +
|
186
|
+
"when the body attributes was already set.");
|
187
|
+
},
|
188
|
+
setBodyWithData: function(object) {
|
189
|
+
throw new Error("Attempt to set body attribute of a content object " +
|
190
|
+
"when the data attributes was already set.");
|
191
|
+
}
|
192
|
+
}
|
193
|
+
module.exports = Content;
|
@@ -0,0 +1,1253 @@
|
|
1
|
+
// Generated by CoffeeScript 1.6.3
|
2
|
+
(function() {
|
3
|
+
var ApiKeyAuthorization, PasswordAuthorization, SwaggerApi, SwaggerAuthorizations, SwaggerHttp, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource,
|
4
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
5
|
+
|
6
|
+
SwaggerApi = (function() {
|
7
|
+
SwaggerApi.prototype.url = "http://api.wordnik.com/v4/resources.json";
|
8
|
+
|
9
|
+
SwaggerApi.prototype.debug = false;
|
10
|
+
|
11
|
+
SwaggerApi.prototype.basePath = null;
|
12
|
+
|
13
|
+
SwaggerApi.prototype.authorizations = null;
|
14
|
+
|
15
|
+
SwaggerApi.prototype.authorizationScheme = null;
|
16
|
+
|
17
|
+
SwaggerApi.prototype.info = null;
|
18
|
+
|
19
|
+
function SwaggerApi(url, options) {
|
20
|
+
if (options == null) {
|
21
|
+
options = {};
|
22
|
+
}
|
23
|
+
if (url) {
|
24
|
+
if (url.url) {
|
25
|
+
options = url;
|
26
|
+
} else {
|
27
|
+
this.url = url;
|
28
|
+
}
|
29
|
+
} else {
|
30
|
+
options = url;
|
31
|
+
}
|
32
|
+
if (options.url != null) {
|
33
|
+
this.url = options.url;
|
34
|
+
}
|
35
|
+
if (options.success != null) {
|
36
|
+
this.success = options.success;
|
37
|
+
}
|
38
|
+
this.failure = options.failure != null ? options.failure : function() {};
|
39
|
+
this.progress = options.progress != null ? options.progress : function() {};
|
40
|
+
if (options.success != null) {
|
41
|
+
this.build();
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
SwaggerApi.prototype.build = function() {
|
46
|
+
var e, obj,
|
47
|
+
_this = this;
|
48
|
+
this.progress('fetching resource list: ' + this.url);
|
49
|
+
obj = {
|
50
|
+
url: this.url,
|
51
|
+
method: "get",
|
52
|
+
headers: {},
|
53
|
+
on: {
|
54
|
+
error: function(response) {
|
55
|
+
if (_this.url.substring(0, 4) !== 'http') {
|
56
|
+
return _this.fail('Please specify the protocol for ' + _this.url);
|
57
|
+
} else if (response.status === 0) {
|
58
|
+
return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
|
59
|
+
} else if (response.status === 404) {
|
60
|
+
return _this.fail('Can\'t read swagger JSON from ' + _this.url);
|
61
|
+
} else {
|
62
|
+
return _this.fail(response.status + ' : ' + response.statusText + ' ' + _this.url);
|
63
|
+
}
|
64
|
+
},
|
65
|
+
response: function(rawResponse) {
|
66
|
+
var response;
|
67
|
+
response = JSON.parse(rawResponse.content.data);
|
68
|
+
_this.swaggerVersion = response.swaggerVersion;
|
69
|
+
if (_this.swaggerVersion === "1.2") {
|
70
|
+
return _this.buildFromSpec(response);
|
71
|
+
} else {
|
72
|
+
return _this.buildFrom1_1Spec(response);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
};
|
77
|
+
e = {};
|
78
|
+
if (typeof window !== 'undefined') {
|
79
|
+
e = window;
|
80
|
+
} else {
|
81
|
+
e = exports;
|
82
|
+
}
|
83
|
+
e.authorizations.apply(obj);
|
84
|
+
new SwaggerHttp().execute(obj);
|
85
|
+
return this;
|
86
|
+
};
|
87
|
+
|
88
|
+
SwaggerApi.prototype.buildFromSpec = function(response) {
|
89
|
+
var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
|
90
|
+
if (response.apiVersion != null) {
|
91
|
+
this.apiVersion = response.apiVersion;
|
92
|
+
}
|
93
|
+
this.apis = {};
|
94
|
+
this.apisArray = [];
|
95
|
+
this.produces = response.produces;
|
96
|
+
this.authSchemes = response.authorizations;
|
97
|
+
if (response.info != null) {
|
98
|
+
this.info = response.info;
|
99
|
+
}
|
100
|
+
isApi = false;
|
101
|
+
_ref = response.apis;
|
102
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
103
|
+
api = _ref[_i];
|
104
|
+
if (api.operations) {
|
105
|
+
_ref1 = api.operations;
|
106
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
107
|
+
operation = _ref1[_j];
|
108
|
+
isApi = true;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
if (response.basePath) {
|
113
|
+
this.basePath = response.basePath;
|
114
|
+
} else if (this.url.indexOf('?') > 0) {
|
115
|
+
this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
|
116
|
+
} else {
|
117
|
+
this.basePath = this.url;
|
118
|
+
}
|
119
|
+
if (isApi) {
|
120
|
+
newName = response.resourcePath.replace(/\//g, '');
|
121
|
+
this.resourcePath = response.resourcePath;
|
122
|
+
res = new SwaggerResource(response, this);
|
123
|
+
this.apis[newName] = res;
|
124
|
+
this.apisArray.push(res);
|
125
|
+
} else {
|
126
|
+
_ref2 = response.apis;
|
127
|
+
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
|
128
|
+
resource = _ref2[_k];
|
129
|
+
res = new SwaggerResource(resource, this);
|
130
|
+
this.apis[res.name] = res;
|
131
|
+
this.apisArray.push(res);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
if (this.success) {
|
135
|
+
this.success();
|
136
|
+
}
|
137
|
+
return this;
|
138
|
+
};
|
139
|
+
|
140
|
+
SwaggerApi.prototype.buildFrom1_1Spec = function(response) {
|
141
|
+
var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
|
142
|
+
console.log("This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info");
|
143
|
+
if (response.apiVersion != null) {
|
144
|
+
this.apiVersion = response.apiVersion;
|
145
|
+
}
|
146
|
+
this.apis = {};
|
147
|
+
this.apisArray = [];
|
148
|
+
this.produces = response.produces;
|
149
|
+
if (response.info != null) {
|
150
|
+
this.info = response.info;
|
151
|
+
}
|
152
|
+
isApi = false;
|
153
|
+
_ref = response.apis;
|
154
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
155
|
+
api = _ref[_i];
|
156
|
+
if (api.operations) {
|
157
|
+
_ref1 = api.operations;
|
158
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
159
|
+
operation = _ref1[_j];
|
160
|
+
isApi = true;
|
161
|
+
}
|
162
|
+
}
|
163
|
+
}
|
164
|
+
if (response.basePath) {
|
165
|
+
this.basePath = response.basePath;
|
166
|
+
} else if (this.url.indexOf('?') > 0) {
|
167
|
+
this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
|
168
|
+
} else {
|
169
|
+
this.basePath = this.url;
|
170
|
+
}
|
171
|
+
if (isApi) {
|
172
|
+
newName = response.resourcePath.replace(/\//g, '');
|
173
|
+
this.resourcePath = response.resourcePath;
|
174
|
+
res = new SwaggerResource(response, this);
|
175
|
+
this.apis[newName] = res;
|
176
|
+
this.apisArray.push(res);
|
177
|
+
} else {
|
178
|
+
_ref2 = response.apis;
|
179
|
+
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
|
180
|
+
resource = _ref2[_k];
|
181
|
+
res = new SwaggerResource(resource, this);
|
182
|
+
this.apis[res.name] = res;
|
183
|
+
this.apisArray.push(res);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
if (this.success) {
|
187
|
+
this.success();
|
188
|
+
}
|
189
|
+
return this;
|
190
|
+
};
|
191
|
+
|
192
|
+
SwaggerApi.prototype.selfReflect = function() {
|
193
|
+
var resource, resource_name, _ref;
|
194
|
+
if (this.apis == null) {
|
195
|
+
return false;
|
196
|
+
}
|
197
|
+
_ref = this.apis;
|
198
|
+
for (resource_name in _ref) {
|
199
|
+
resource = _ref[resource_name];
|
200
|
+
if (resource.ready == null) {
|
201
|
+
return false;
|
202
|
+
}
|
203
|
+
}
|
204
|
+
this.setConsolidatedModels();
|
205
|
+
this.ready = true;
|
206
|
+
if (this.success != null) {
|
207
|
+
return this.success();
|
208
|
+
}
|
209
|
+
};
|
210
|
+
|
211
|
+
SwaggerApi.prototype.fail = function(message) {
|
212
|
+
this.failure(message);
|
213
|
+
throw message;
|
214
|
+
};
|
215
|
+
|
216
|
+
SwaggerApi.prototype.setConsolidatedModels = function() {
|
217
|
+
var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results;
|
218
|
+
this.modelsArray = [];
|
219
|
+
this.models = {};
|
220
|
+
_ref = this.apis;
|
221
|
+
for (resource_name in _ref) {
|
222
|
+
resource = _ref[resource_name];
|
223
|
+
for (modelName in resource.models) {
|
224
|
+
if (this.models[modelName] == null) {
|
225
|
+
this.models[modelName] = resource.models[modelName];
|
226
|
+
this.modelsArray.push(resource.models[modelName]);
|
227
|
+
}
|
228
|
+
}
|
229
|
+
}
|
230
|
+
_ref1 = this.modelsArray;
|
231
|
+
_results = [];
|
232
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
233
|
+
model = _ref1[_i];
|
234
|
+
_results.push(model.setReferencedModels(this.models));
|
235
|
+
}
|
236
|
+
return _results;
|
237
|
+
};
|
238
|
+
|
239
|
+
SwaggerApi.prototype.help = function() {
|
240
|
+
var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2;
|
241
|
+
_ref = this.apis;
|
242
|
+
for (resource_name in _ref) {
|
243
|
+
resource = _ref[resource_name];
|
244
|
+
console.log(resource_name);
|
245
|
+
_ref1 = resource.operations;
|
246
|
+
for (operation_name in _ref1) {
|
247
|
+
operation = _ref1[operation_name];
|
248
|
+
console.log(" " + operation.nickname);
|
249
|
+
_ref2 = operation.parameters;
|
250
|
+
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
251
|
+
parameter = _ref2[_i];
|
252
|
+
console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
|
253
|
+
}
|
254
|
+
}
|
255
|
+
}
|
256
|
+
return this;
|
257
|
+
};
|
258
|
+
|
259
|
+
return SwaggerApi;
|
260
|
+
|
261
|
+
})();
|
262
|
+
|
263
|
+
SwaggerResource = (function() {
|
264
|
+
SwaggerResource.prototype.api = null;
|
265
|
+
|
266
|
+
SwaggerResource.prototype.produces = null;
|
267
|
+
|
268
|
+
SwaggerResource.prototype.consumes = null;
|
269
|
+
|
270
|
+
function SwaggerResource(resourceObj, api) {
|
271
|
+
var consumes, e, obj, parts, produces,
|
272
|
+
_this = this;
|
273
|
+
this.api = api;
|
274
|
+
this.api = this.api;
|
275
|
+
produces = [];
|
276
|
+
consumes = [];
|
277
|
+
this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
|
278
|
+
this.description = resourceObj.description;
|
279
|
+
parts = this.path.split("/");
|
280
|
+
this.name = parts[parts.length - 1].replace('.{format}', '');
|
281
|
+
this.basePath = this.api.basePath;
|
282
|
+
this.operations = {};
|
283
|
+
this.operationsArray = [];
|
284
|
+
this.modelsArray = [];
|
285
|
+
this.models = {};
|
286
|
+
if ((resourceObj.apis != null) && (this.api.resourcePath != null)) {
|
287
|
+
this.addApiDeclaration(resourceObj);
|
288
|
+
} else {
|
289
|
+
if (this.path == null) {
|
290
|
+
this.api.fail("SwaggerResources must have a path.");
|
291
|
+
}
|
292
|
+
if (this.path.substring(0, 4) === 'http') {
|
293
|
+
this.url = this.path.replace('{format}', 'json');
|
294
|
+
} else {
|
295
|
+
this.url = this.api.basePath + this.path.replace('{format}', 'json');
|
296
|
+
}
|
297
|
+
this.api.progress('fetching resource ' + this.name + ': ' + this.url);
|
298
|
+
// start patch
|
299
|
+
if(this.url.indexOf("/")==0) {
|
300
|
+
var origin = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');
|
301
|
+
this.url = origin + this.url;
|
302
|
+
//console.log("this.url remapped", this.url)
|
303
|
+
}
|
304
|
+
// end patch
|
305
|
+
obj = {
|
306
|
+
url: this.url,
|
307
|
+
method: "get",
|
308
|
+
headers: {},
|
309
|
+
on: {
|
310
|
+
error: function(response) {
|
311
|
+
return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + response.statusText + ")");
|
312
|
+
},
|
313
|
+
response: function(rawResponse) {
|
314
|
+
var response;
|
315
|
+
response = JSON.parse(rawResponse.content.data);
|
316
|
+
return _this.addApiDeclaration(response);
|
317
|
+
}
|
318
|
+
}
|
319
|
+
};
|
320
|
+
e = {};
|
321
|
+
if (typeof window !== 'undefined') {
|
322
|
+
e = window;
|
323
|
+
} else {
|
324
|
+
e = exports;
|
325
|
+
}
|
326
|
+
e.authorizations.apply(obj);
|
327
|
+
new SwaggerHttp().execute(obj);
|
328
|
+
}
|
329
|
+
}
|
330
|
+
|
331
|
+
SwaggerResource.prototype.addApiDeclaration = function(response) {
|
332
|
+
var endpoint, _i, _len, _ref;
|
333
|
+
if (response.produces != null) {
|
334
|
+
this.produces = response.produces;
|
335
|
+
}
|
336
|
+
if (response.consumes != null) {
|
337
|
+
this.consumes = response.consumes;
|
338
|
+
}
|
339
|
+
if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0) {
|
340
|
+
this.basePath = response.basePath;
|
341
|
+
// start patch
|
342
|
+
if(this.basePath.indexOf("/")==0) {
|
343
|
+
var origin = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');
|
344
|
+
this.basePath = origin + this.basePath;
|
345
|
+
//console.log("this.basePath remapped", this.basePath)
|
346
|
+
}
|
347
|
+
// end patch
|
348
|
+
}
|
349
|
+
this.addModels(response.models);
|
350
|
+
if (response.apis) {
|
351
|
+
_ref = response.apis;
|
352
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
353
|
+
endpoint = _ref[_i];
|
354
|
+
this.addOperations(endpoint.path, endpoint.operations, response.consumes, response.produces);
|
355
|
+
}
|
356
|
+
}
|
357
|
+
this.api[this.name] = this;
|
358
|
+
this.ready = true;
|
359
|
+
return this.api.selfReflect();
|
360
|
+
};
|
361
|
+
|
362
|
+
SwaggerResource.prototype.addModels = function(models) {
|
363
|
+
var model, modelName, swaggerModel, _i, _len, _ref, _results;
|
364
|
+
if (models != null) {
|
365
|
+
for (modelName in models) {
|
366
|
+
if (this.models[modelName] == null) {
|
367
|
+
swaggerModel = new SwaggerModel(modelName, models[modelName]);
|
368
|
+
this.modelsArray.push(swaggerModel);
|
369
|
+
this.models[modelName] = swaggerModel;
|
370
|
+
}
|
371
|
+
}
|
372
|
+
_ref = this.modelsArray;
|
373
|
+
_results = [];
|
374
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
375
|
+
model = _ref[_i];
|
376
|
+
_results.push(model.setReferencedModels(this.models));
|
377
|
+
}
|
378
|
+
return _results;
|
379
|
+
}
|
380
|
+
};
|
381
|
+
|
382
|
+
SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes, produces) {
|
383
|
+
var method, o, op, ref, responseMessages, type, _i, _len, _results;
|
384
|
+
if (ops) {
|
385
|
+
_results = [];
|
386
|
+
for (_i = 0, _len = ops.length; _i < _len; _i++) {
|
387
|
+
o = ops[_i];
|
388
|
+
consumes = this.consumes;
|
389
|
+
produces = this.produces;
|
390
|
+
if (o.consumes != null) {
|
391
|
+
consumes = o.consumes;
|
392
|
+
} else {
|
393
|
+
consumes = this.consumes;
|
394
|
+
}
|
395
|
+
if (o.produces != null) {
|
396
|
+
produces = o.produces;
|
397
|
+
} else {
|
398
|
+
produces = this.produces;
|
399
|
+
}
|
400
|
+
type = o.type || o.responseClass;
|
401
|
+
if (type === "array") {
|
402
|
+
ref = null;
|
403
|
+
if (o.items) {
|
404
|
+
ref = o.items["type"] || o.items["$ref"];
|
405
|
+
}
|
406
|
+
type = "array[" + ref + "]";
|
407
|
+
}
|
408
|
+
responseMessages = o.responseMessages;
|
409
|
+
method = o.method;
|
410
|
+
if (o.httpMethod) {
|
411
|
+
method = o.httpMethod;
|
412
|
+
}
|
413
|
+
if (o.supportedContentTypes) {
|
414
|
+
consumes = o.supportedContentTypes;
|
415
|
+
}
|
416
|
+
if (o.errorResponses) {
|
417
|
+
responseMessages = o.errorResponses;
|
418
|
+
}
|
419
|
+
o.nickname = this.sanitize(o.nickname);
|
420
|
+
op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, type, responseMessages, this, consumes, produces);
|
421
|
+
this.operations[op.nickname] = op;
|
422
|
+
_results.push(this.operationsArray.push(op));
|
423
|
+
}
|
424
|
+
return _results;
|
425
|
+
}
|
426
|
+
};
|
427
|
+
|
428
|
+
SwaggerResource.prototype.sanitize = function(nickname) {
|
429
|
+
var op;
|
430
|
+
op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|./?,\\'""-]/g, '_');
|
431
|
+
op = op.replace(/((_){2,})/g, '_');
|
432
|
+
op = op.replace(/^(_)*/g, '');
|
433
|
+
op = op.replace(/([_])*$/g, '');
|
434
|
+
return op;
|
435
|
+
};
|
436
|
+
|
437
|
+
SwaggerResource.prototype.help = function() {
|
438
|
+
var msg, operation, operation_name, parameter, _i, _len, _ref, _ref1, _results;
|
439
|
+
_ref = this.operations;
|
440
|
+
_results = [];
|
441
|
+
for (operation_name in _ref) {
|
442
|
+
operation = _ref[operation_name];
|
443
|
+
msg = " " + operation.nickname;
|
444
|
+
_ref1 = operation.parameters;
|
445
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
446
|
+
parameter = _ref1[_i];
|
447
|
+
msg.concat(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
|
448
|
+
}
|
449
|
+
_results.push(msg);
|
450
|
+
}
|
451
|
+
return _results;
|
452
|
+
};
|
453
|
+
|
454
|
+
return SwaggerResource;
|
455
|
+
|
456
|
+
})();
|
457
|
+
|
458
|
+
SwaggerModel = (function() {
|
459
|
+
function SwaggerModel(modelName, obj) {
|
460
|
+
var prop, propertyName, value;
|
461
|
+
this.name = obj.id != null ? obj.id : modelName;
|
462
|
+
this.properties = [];
|
463
|
+
for (propertyName in obj.properties) {
|
464
|
+
if (obj.required != null) {
|
465
|
+
for (value in obj.required) {
|
466
|
+
if (propertyName === obj.required[value]) {
|
467
|
+
obj.properties[propertyName].required = true;
|
468
|
+
}
|
469
|
+
}
|
470
|
+
}
|
471
|
+
prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]);
|
472
|
+
this.properties.push(prop);
|
473
|
+
}
|
474
|
+
}
|
475
|
+
|
476
|
+
SwaggerModel.prototype.setReferencedModels = function(allModels) {
|
477
|
+
var prop, type, _i, _len, _ref, _results;
|
478
|
+
_ref = this.properties;
|
479
|
+
_results = [];
|
480
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
481
|
+
prop = _ref[_i];
|
482
|
+
type = prop.type || prop.dataType;
|
483
|
+
if (allModels[type] != null) {
|
484
|
+
_results.push(prop.refModel = allModels[type]);
|
485
|
+
} else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) {
|
486
|
+
_results.push(prop.refModel = allModels[prop.refDataType]);
|
487
|
+
} else {
|
488
|
+
_results.push(void 0);
|
489
|
+
}
|
490
|
+
}
|
491
|
+
return _results;
|
492
|
+
};
|
493
|
+
|
494
|
+
SwaggerModel.prototype.getMockSignature = function(modelsToIgnore) {
|
495
|
+
var classClose, classOpen, prop, propertiesStr, returnVal, strong, strongClose, stronger, _i, _j, _len, _len1, _ref, _ref1;
|
496
|
+
propertiesStr = [];
|
497
|
+
_ref = this.properties;
|
498
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
499
|
+
prop = _ref[_i];
|
500
|
+
propertiesStr.push(prop.toString());
|
501
|
+
}
|
502
|
+
strong = '<span class="strong">';
|
503
|
+
stronger = '<span class="stronger">';
|
504
|
+
strongClose = '</span>';
|
505
|
+
classOpen = strong + this.name + ' {' + strongClose;
|
506
|
+
classClose = strong + '}' + strongClose;
|
507
|
+
returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;
|
508
|
+
if (!modelsToIgnore) {
|
509
|
+
modelsToIgnore = [];
|
510
|
+
}
|
511
|
+
modelsToIgnore.push(this);
|
512
|
+
_ref1 = this.properties;
|
513
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
514
|
+
prop = _ref1[_j];
|
515
|
+
if ((prop.refModel != null) && (modelsToIgnore.indexOf(prop.refModel)) === -1) {
|
516
|
+
returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
|
517
|
+
}
|
518
|
+
}
|
519
|
+
return returnVal;
|
520
|
+
};
|
521
|
+
|
522
|
+
SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) {
|
523
|
+
var prop, result, _i, _len, _ref;
|
524
|
+
result = {};
|
525
|
+
modelsToIgnore = modelsToIgnore || [];
|
526
|
+
modelsToIgnore.push(this.name);
|
527
|
+
_ref = this.properties;
|
528
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
529
|
+
prop = _ref[_i];
|
530
|
+
result[prop.name] = prop.getSampleValue(modelsToIgnore);
|
531
|
+
}
|
532
|
+
modelsToIgnore.pop(this.name);
|
533
|
+
return result;
|
534
|
+
};
|
535
|
+
|
536
|
+
return SwaggerModel;
|
537
|
+
|
538
|
+
})();
|
539
|
+
|
540
|
+
SwaggerModelProperty = (function() {
|
541
|
+
function SwaggerModelProperty(name, obj) {
|
542
|
+
this.name = name;
|
543
|
+
this.dataType = obj.type || obj.dataType || obj["$ref"];
|
544
|
+
this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
|
545
|
+
this.descr = obj.description;
|
546
|
+
this.required = obj.required;
|
547
|
+
if (obj.items != null) {
|
548
|
+
if (obj.items.type != null) {
|
549
|
+
this.refDataType = obj.items.type;
|
550
|
+
}
|
551
|
+
if (obj.items.$ref != null) {
|
552
|
+
this.refDataType = obj.items.$ref;
|
553
|
+
}
|
554
|
+
}
|
555
|
+
this.dataTypeWithRef = this.refDataType != null ? this.dataType + '[' + this.refDataType + ']' : this.dataType;
|
556
|
+
if (obj.allowableValues != null) {
|
557
|
+
this.valueType = obj.allowableValues.valueType;
|
558
|
+
this.values = obj.allowableValues.values;
|
559
|
+
if (this.values != null) {
|
560
|
+
this.valuesString = "'" + this.values.join("' or '") + "'";
|
561
|
+
}
|
562
|
+
}
|
563
|
+
if (obj["enum"] != null) {
|
564
|
+
this.valueType = "string";
|
565
|
+
this.values = obj["enum"];
|
566
|
+
if (this.values != null) {
|
567
|
+
this.valueString = "'" + this.values.join("' or '") + "'";
|
568
|
+
}
|
569
|
+
}
|
570
|
+
}
|
571
|
+
|
572
|
+
SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
|
573
|
+
var result;
|
574
|
+
if ((this.refModel != null) && (modelsToIgnore.indexOf(this.refModel.name) === -1)) {
|
575
|
+
result = this.refModel.createJSONSample(modelsToIgnore);
|
576
|
+
} else {
|
577
|
+
if (this.isCollection) {
|
578
|
+
result = this.refDataType;
|
579
|
+
} else {
|
580
|
+
result = this.dataType;
|
581
|
+
}
|
582
|
+
}
|
583
|
+
if (this.isCollection) {
|
584
|
+
return [result];
|
585
|
+
} else {
|
586
|
+
return result;
|
587
|
+
}
|
588
|
+
};
|
589
|
+
|
590
|
+
SwaggerModelProperty.prototype.toString = function() {
|
591
|
+
var req, str;
|
592
|
+
req = this.required ? 'propReq' : 'propOpt';
|
593
|
+
str = '<span class="propName ' + req + '">' + this.name + '</span> (<span class="propType">' + this.dataTypeWithRef + '</span>';
|
594
|
+
if (!this.required) {
|
595
|
+
str += ', <span class="propOptKey">optional</span>';
|
596
|
+
}
|
597
|
+
str += ')';
|
598
|
+
if (this.values != null) {
|
599
|
+
str += " = <span class='propVals'>['" + this.values.join("' or '") + "']</span>";
|
600
|
+
}
|
601
|
+
if (this.descr != null) {
|
602
|
+
str += ': <span class="propDesc">' + this.descr + '</span>';
|
603
|
+
}
|
604
|
+
return str;
|
605
|
+
};
|
606
|
+
|
607
|
+
return SwaggerModelProperty;
|
608
|
+
|
609
|
+
})();
|
610
|
+
|
611
|
+
SwaggerOperation = (function() {
|
612
|
+
function SwaggerOperation(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces) {
|
613
|
+
var parameter, v, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3,
|
614
|
+
_this = this;
|
615
|
+
this.nickname = nickname;
|
616
|
+
this.path = path;
|
617
|
+
this.method = method;
|
618
|
+
this.parameters = parameters != null ? parameters : [];
|
619
|
+
this.summary = summary;
|
620
|
+
this.notes = notes;
|
621
|
+
this.type = type;
|
622
|
+
this.responseMessages = responseMessages;
|
623
|
+
this.resource = resource;
|
624
|
+
this.consumes = consumes;
|
625
|
+
this.produces = produces;
|
626
|
+
this["do"] = __bind(this["do"], this);
|
627
|
+
if (this.nickname == null) {
|
628
|
+
this.resource.api.fail("SwaggerOperations must have a nickname.");
|
629
|
+
}
|
630
|
+
if (this.path == null) {
|
631
|
+
this.resource.api.fail("SwaggerOperation " + nickname + " is missing path.");
|
632
|
+
}
|
633
|
+
if (this.method == null) {
|
634
|
+
this.resource.api.fail("SwaggerOperation " + nickname + " is missing method.");
|
635
|
+
}
|
636
|
+
this.path = this.path.replace('{format}', 'json');
|
637
|
+
this.method = this.method.toLowerCase();
|
638
|
+
this.isGetMethod = this.method === "get";
|
639
|
+
this.resourceName = this.resource.name;
|
640
|
+
if (((_ref = this.type) != null ? _ref.toLowerCase() : void 0) === 'void') {
|
641
|
+
this.type = void 0;
|
642
|
+
}
|
643
|
+
if (this.type != null) {
|
644
|
+
this.responseClassSignature = this.getSignature(this.type, this.resource.models);
|
645
|
+
this.responseSampleJSON = this.getSampleJSON(this.type, this.resource.models);
|
646
|
+
}
|
647
|
+
this.responseMessages = this.responseMessages || [];
|
648
|
+
_ref1 = this.parameters;
|
649
|
+
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
650
|
+
parameter = _ref1[_i];
|
651
|
+
parameter.name = parameter.name || parameter.type || parameter.dataType;
|
652
|
+
type = parameter.type || parameter.dataType;
|
653
|
+
if (type.toLowerCase() === 'boolean') {
|
654
|
+
parameter.allowableValues = {};
|
655
|
+
parameter.allowableValues.values = ["true", "false"];
|
656
|
+
}
|
657
|
+
parameter.signature = this.getSignature(type, this.resource.models);
|
658
|
+
parameter.sampleJSON = this.getSampleJSON(type, this.resource.models);
|
659
|
+
if (parameter["enum"] != null) {
|
660
|
+
parameter.isList = true;
|
661
|
+
parameter.allowableValues = {};
|
662
|
+
parameter.allowableValues.descriptiveValues = [];
|
663
|
+
_ref2 = parameter["enum"];
|
664
|
+
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
665
|
+
v = _ref2[_j];
|
666
|
+
if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
|
667
|
+
parameter.allowableValues.descriptiveValues.push({
|
668
|
+
value: v,
|
669
|
+
isDefault: true
|
670
|
+
});
|
671
|
+
} else {
|
672
|
+
parameter.allowableValues.descriptiveValues.push({
|
673
|
+
value: v,
|
674
|
+
isDefault: false
|
675
|
+
});
|
676
|
+
}
|
677
|
+
}
|
678
|
+
}
|
679
|
+
if (parameter.allowableValues != null) {
|
680
|
+
if (parameter.allowableValues.valueType === "RANGE") {
|
681
|
+
parameter.isRange = true;
|
682
|
+
} else {
|
683
|
+
parameter.isList = true;
|
684
|
+
}
|
685
|
+
if (parameter.allowableValues.values != null) {
|
686
|
+
parameter.allowableValues.descriptiveValues = [];
|
687
|
+
_ref3 = parameter.allowableValues.values;
|
688
|
+
for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
|
689
|
+
v = _ref3[_k];
|
690
|
+
if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
|
691
|
+
parameter.allowableValues.descriptiveValues.push({
|
692
|
+
value: v,
|
693
|
+
isDefault: true
|
694
|
+
});
|
695
|
+
} else {
|
696
|
+
parameter.allowableValues.descriptiveValues.push({
|
697
|
+
value: v,
|
698
|
+
isDefault: false
|
699
|
+
});
|
700
|
+
}
|
701
|
+
}
|
702
|
+
}
|
703
|
+
}
|
704
|
+
}
|
705
|
+
this.resource[this.nickname] = function(args, callback, error) {
|
706
|
+
return _this["do"](args, callback, error);
|
707
|
+
};
|
708
|
+
this.resource[this.nickname].help = function() {
|
709
|
+
return _this.help();
|
710
|
+
};
|
711
|
+
}
|
712
|
+
|
713
|
+
SwaggerOperation.prototype.isListType = function(type) {
|
714
|
+
if (type.indexOf('[') >= 0) {
|
715
|
+
return type.substring(type.indexOf('[') + 1, type.indexOf(']'));
|
716
|
+
} else {
|
717
|
+
return void 0;
|
718
|
+
}
|
719
|
+
};
|
720
|
+
|
721
|
+
SwaggerOperation.prototype.getSignature = function(type, models) {
|
722
|
+
var isPrimitive, listType;
|
723
|
+
listType = this.isListType(type);
|
724
|
+
isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
|
725
|
+
if (isPrimitive) {
|
726
|
+
return type;
|
727
|
+
} else {
|
728
|
+
if (listType != null) {
|
729
|
+
return models[listType].getMockSignature();
|
730
|
+
} else {
|
731
|
+
return models[type].getMockSignature();
|
732
|
+
}
|
733
|
+
}
|
734
|
+
};
|
735
|
+
|
736
|
+
SwaggerOperation.prototype.getSampleJSON = function(type, models) {
|
737
|
+
var isPrimitive, listType, val;
|
738
|
+
listType = this.isListType(type);
|
739
|
+
isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
|
740
|
+
val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample());
|
741
|
+
if (val) {
|
742
|
+
val = listType ? [val] : val;
|
743
|
+
return JSON.stringify(val, null, 2);
|
744
|
+
}
|
745
|
+
};
|
746
|
+
|
747
|
+
SwaggerOperation.prototype["do"] = function(args, opts, callback, error) {
|
748
|
+
var key, param, params, possibleParams, req, requestContentType, responseContentType, value, _i, _len, _ref;
|
749
|
+
if (args == null) {
|
750
|
+
args = {};
|
751
|
+
}
|
752
|
+
if (opts == null) {
|
753
|
+
opts = {};
|
754
|
+
}
|
755
|
+
requestContentType = null;
|
756
|
+
responseContentType = null;
|
757
|
+
if ((typeof args) === "function") {
|
758
|
+
error = opts;
|
759
|
+
callback = args;
|
760
|
+
args = {};
|
761
|
+
}
|
762
|
+
if ((typeof opts) === "function") {
|
763
|
+
error = callback;
|
764
|
+
callback = opts;
|
765
|
+
}
|
766
|
+
if (error == null) {
|
767
|
+
error = function(xhr, textStatus, error) {
|
768
|
+
return console.log(xhr, textStatus, error);
|
769
|
+
};
|
770
|
+
}
|
771
|
+
if (callback == null) {
|
772
|
+
callback = function(data) {
|
773
|
+
var content;
|
774
|
+
content = null;
|
775
|
+
if (data.content != null) {
|
776
|
+
content = data.content.data;
|
777
|
+
} else {
|
778
|
+
content = "no data";
|
779
|
+
}
|
780
|
+
return console.log("default callback: " + content);
|
781
|
+
};
|
782
|
+
}
|
783
|
+
params = {};
|
784
|
+
params.headers = [];
|
785
|
+
if (args.headers != null) {
|
786
|
+
params.headers = args.headers;
|
787
|
+
delete args.headers;
|
788
|
+
}
|
789
|
+
_ref = this.parameters;
|
790
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
791
|
+
param = _ref[_i];
|
792
|
+
if (param.paramType === "header") {
|
793
|
+
if (args[param.name]) {
|
794
|
+
params.headers[param.name] = args[param.name];
|
795
|
+
}
|
796
|
+
}
|
797
|
+
}
|
798
|
+
if (args.body != null) {
|
799
|
+
params.body = args.body;
|
800
|
+
delete args.body;
|
801
|
+
}
|
802
|
+
possibleParams = (function() {
|
803
|
+
var _j, _len1, _ref1, _results;
|
804
|
+
_ref1 = this.parameters;
|
805
|
+
_results = [];
|
806
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
807
|
+
param = _ref1[_j];
|
808
|
+
if (param.paramType === "form" || param.paramType.toLowerCase() === "file") {
|
809
|
+
_results.push(param);
|
810
|
+
}
|
811
|
+
}
|
812
|
+
return _results;
|
813
|
+
}).call(this);
|
814
|
+
if (possibleParams) {
|
815
|
+
for (key in possibleParams) {
|
816
|
+
value = possibleParams[key];
|
817
|
+
if (args[value.name]) {
|
818
|
+
params[value.name] = args[value.name];
|
819
|
+
}
|
820
|
+
}
|
821
|
+
}
|
822
|
+
req = new SwaggerRequest(this.method, this.urlify(args), params, opts, callback, error, this);
|
823
|
+
if (opts.mock != null) {
|
824
|
+
return req;
|
825
|
+
} else {
|
826
|
+
return true;
|
827
|
+
}
|
828
|
+
};
|
829
|
+
|
830
|
+
SwaggerOperation.prototype.pathJson = function() {
|
831
|
+
return this.path.replace("{format}", "json");
|
832
|
+
};
|
833
|
+
|
834
|
+
SwaggerOperation.prototype.pathXml = function() {
|
835
|
+
return this.path.replace("{format}", "xml");
|
836
|
+
};
|
837
|
+
|
838
|
+
SwaggerOperation.prototype.urlify = function(args) {
|
839
|
+
var param, queryParams, reg, url, _i, _j, _len, _len1, _ref, _ref1;
|
840
|
+
url = this.resource.basePath + this.pathJson();
|
841
|
+
_ref = this.parameters;
|
842
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
843
|
+
param = _ref[_i];
|
844
|
+
if (param.paramType === 'path') {
|
845
|
+
if (args[param.name]) {
|
846
|
+
reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
|
847
|
+
url = url.replace(reg, encodeURIComponent(args[param.name]));
|
848
|
+
delete args[param.name];
|
849
|
+
} else {
|
850
|
+
throw "" + param.name + " is a required path param.";
|
851
|
+
}
|
852
|
+
}
|
853
|
+
}
|
854
|
+
queryParams = "";
|
855
|
+
_ref1 = this.parameters;
|
856
|
+
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
857
|
+
param = _ref1[_j];
|
858
|
+
if (param.paramType === 'query') {
|
859
|
+
if (args[param.name]) {
|
860
|
+
if (queryParams !== "") {
|
861
|
+
queryParams += "&";
|
862
|
+
}
|
863
|
+
queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]);
|
864
|
+
}
|
865
|
+
}
|
866
|
+
}
|
867
|
+
if ((queryParams != null) && queryParams.length > 0) {
|
868
|
+
url += "?" + queryParams;
|
869
|
+
}
|
870
|
+
return url;
|
871
|
+
};
|
872
|
+
|
873
|
+
SwaggerOperation.prototype.supportHeaderParams = function() {
|
874
|
+
return this.resource.api.supportHeaderParams;
|
875
|
+
};
|
876
|
+
|
877
|
+
SwaggerOperation.prototype.supportedSubmitMethods = function() {
|
878
|
+
return this.resource.api.supportedSubmitMethods;
|
879
|
+
};
|
880
|
+
|
881
|
+
SwaggerOperation.prototype.getQueryParams = function(args) {
|
882
|
+
return this.getMatchingParams(['query'], args);
|
883
|
+
};
|
884
|
+
|
885
|
+
SwaggerOperation.prototype.getHeaderParams = function(args) {
|
886
|
+
return this.getMatchingParams(['header'], args);
|
887
|
+
};
|
888
|
+
|
889
|
+
SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args) {
|
890
|
+
var matchingParams, name, param, value, _i, _len, _ref, _ref1;
|
891
|
+
matchingParams = {};
|
892
|
+
_ref = this.parameters;
|
893
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
894
|
+
param = _ref[_i];
|
895
|
+
if (args && args[param.name]) {
|
896
|
+
matchingParams[param.name] = args[param.name];
|
897
|
+
}
|
898
|
+
}
|
899
|
+
_ref1 = this.resource.api.headers;
|
900
|
+
for (name in _ref1) {
|
901
|
+
value = _ref1[name];
|
902
|
+
matchingParams[name] = value;
|
903
|
+
}
|
904
|
+
return matchingParams;
|
905
|
+
};
|
906
|
+
|
907
|
+
SwaggerOperation.prototype.help = function() {
|
908
|
+
var msg, parameter, _i, _len, _ref;
|
909
|
+
msg = "";
|
910
|
+
_ref = this.parameters;
|
911
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
912
|
+
parameter = _ref[_i];
|
913
|
+
if (msg !== "") {
|
914
|
+
msg += "\n";
|
915
|
+
}
|
916
|
+
msg += "* " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description;
|
917
|
+
}
|
918
|
+
return msg;
|
919
|
+
};
|
920
|
+
|
921
|
+
return SwaggerOperation;
|
922
|
+
|
923
|
+
})();
|
924
|
+
|
925
|
+
SwaggerRequest = (function() {
|
926
|
+
function SwaggerRequest(type, url, params, opts, successCallback, errorCallback, operation, execution) {
|
927
|
+
var body, e, fields, headers, key, myHeaders, name, obj, param, parent, possibleParams, requestContentType, responseContentType, urlEncoded, value, values,
|
928
|
+
_this = this;
|
929
|
+
this.type = type;
|
930
|
+
this.url = url;
|
931
|
+
this.params = params;
|
932
|
+
this.opts = opts;
|
933
|
+
this.successCallback = successCallback;
|
934
|
+
this.errorCallback = errorCallback;
|
935
|
+
this.operation = operation;
|
936
|
+
this.execution = execution;
|
937
|
+
if (this.type == null) {
|
938
|
+
throw "SwaggerRequest type is required (get/post/put/delete).";
|
939
|
+
}
|
940
|
+
if (this.url == null) {
|
941
|
+
throw "SwaggerRequest url is required.";
|
942
|
+
}
|
943
|
+
if (this.successCallback == null) {
|
944
|
+
throw "SwaggerRequest successCallback is required.";
|
945
|
+
}
|
946
|
+
if (this.errorCallback == null) {
|
947
|
+
throw "SwaggerRequest error callback is required.";
|
948
|
+
}
|
949
|
+
if (this.operation == null) {
|
950
|
+
throw "SwaggerRequest operation is required.";
|
951
|
+
}
|
952
|
+
this.type = this.type.toUpperCase();
|
953
|
+
headers = params.headers;
|
954
|
+
myHeaders = {};
|
955
|
+
body = params.body;
|
956
|
+
parent = params["parent"];
|
957
|
+
requestContentType = "application/json";
|
958
|
+
if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) {
|
959
|
+
if (this.opts.requestContentType) {
|
960
|
+
requestContentType = this.opts.requestContentType;
|
961
|
+
}
|
962
|
+
} else {
|
963
|
+
if (((function() {
|
964
|
+
var _i, _len, _ref, _results;
|
965
|
+
_ref = this.operation.parameters;
|
966
|
+
_results = [];
|
967
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
968
|
+
param = _ref[_i];
|
969
|
+
if (param.paramType === "form") {
|
970
|
+
_results.push(param);
|
971
|
+
}
|
972
|
+
}
|
973
|
+
return _results;
|
974
|
+
}).call(this)).length > 0) {
|
975
|
+
type = param.type || param.dataType;
|
976
|
+
if (((function() {
|
977
|
+
var _i, _len, _ref, _results;
|
978
|
+
_ref = this.operation.parameters;
|
979
|
+
_results = [];
|
980
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
981
|
+
param = _ref[_i];
|
982
|
+
if (type.toLowerCase() === "file") {
|
983
|
+
_results.push(param);
|
984
|
+
}
|
985
|
+
}
|
986
|
+
return _results;
|
987
|
+
}).call(this)).length > 0) {
|
988
|
+
requestContentType = "multipart/form-data";
|
989
|
+
} else {
|
990
|
+
requestContentType = "application/x-www-form-urlencoded";
|
991
|
+
}
|
992
|
+
} else if (this.type !== "DELETE") {
|
993
|
+
requestContentType = null;
|
994
|
+
}
|
995
|
+
}
|
996
|
+
if (requestContentType && this.operation.consumes) {
|
997
|
+
if (this.operation.consumes.indexOf(requestContentType) === -1) {
|
998
|
+
console.log("server doesn't consume " + requestContentType + ", try " + JSON.stringify(this.operation.consumes));
|
999
|
+
if (this.requestContentType === null) {
|
1000
|
+
requestContentType = this.operation.consumes[0];
|
1001
|
+
}
|
1002
|
+
}
|
1003
|
+
}
|
1004
|
+
responseContentType = null;
|
1005
|
+
if (this.type === "POST" || this.type === "GET" || this.type === "PATCH") {
|
1006
|
+
if (this.opts.responseContentType) {
|
1007
|
+
responseContentType = this.opts.responseContentType;
|
1008
|
+
} else {
|
1009
|
+
responseContentType = "application/json";
|
1010
|
+
}
|
1011
|
+
} else {
|
1012
|
+
responseContentType = null;
|
1013
|
+
}
|
1014
|
+
if (responseContentType && this.operation.produces) {
|
1015
|
+
if (this.operation.produces.indexOf(responseContentType) === -1) {
|
1016
|
+
console.log("server can't produce " + responseContentType);
|
1017
|
+
}
|
1018
|
+
}
|
1019
|
+
if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) {
|
1020
|
+
fields = {};
|
1021
|
+
possibleParams = (function() {
|
1022
|
+
var _i, _len, _ref, _results;
|
1023
|
+
_ref = this.operation.parameters;
|
1024
|
+
_results = [];
|
1025
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
1026
|
+
param = _ref[_i];
|
1027
|
+
if (param.paramType === "form") {
|
1028
|
+
_results.push(param);
|
1029
|
+
}
|
1030
|
+
}
|
1031
|
+
return _results;
|
1032
|
+
}).call(this);
|
1033
|
+
values = {};
|
1034
|
+
for (key in possibleParams) {
|
1035
|
+
value = possibleParams[key];
|
1036
|
+
if (this.params[value.name]) {
|
1037
|
+
values[value.name] = this.params[value.name];
|
1038
|
+
}
|
1039
|
+
}
|
1040
|
+
urlEncoded = "";
|
1041
|
+
for (key in values) {
|
1042
|
+
value = values[key];
|
1043
|
+
if (urlEncoded !== "") {
|
1044
|
+
urlEncoded += "&";
|
1045
|
+
}
|
1046
|
+
urlEncoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
1047
|
+
}
|
1048
|
+
body = urlEncoded;
|
1049
|
+
}
|
1050
|
+
for (name in headers) {
|
1051
|
+
myHeaders[name] = headers[name];
|
1052
|
+
}
|
1053
|
+
if (requestContentType) {
|
1054
|
+
myHeaders["Content-Type"] = requestContentType;
|
1055
|
+
}
|
1056
|
+
if (responseContentType) {
|
1057
|
+
myHeaders["Accept"] = responseContentType;
|
1058
|
+
}
|
1059
|
+
if (!((headers != null) && (headers.mock != null))) {
|
1060
|
+
obj = {
|
1061
|
+
url: this.url,
|
1062
|
+
method: this.type,
|
1063
|
+
headers: myHeaders,
|
1064
|
+
body: body,
|
1065
|
+
on: {
|
1066
|
+
error: function(response) {
|
1067
|
+
return _this.errorCallback(response, _this.opts.parent);
|
1068
|
+
},
|
1069
|
+
redirect: function(response) {
|
1070
|
+
return _this.successCallback(response, _this.opts.parent);
|
1071
|
+
},
|
1072
|
+
307: function(response) {
|
1073
|
+
return _this.successCallback(response, _this.opts.parent);
|
1074
|
+
},
|
1075
|
+
response: function(response) {
|
1076
|
+
return _this.successCallback(response, _this.opts.parent);
|
1077
|
+
}
|
1078
|
+
}
|
1079
|
+
};
|
1080
|
+
e = {};
|
1081
|
+
if (typeof window !== 'undefined') {
|
1082
|
+
e = window;
|
1083
|
+
} else {
|
1084
|
+
e = exports;
|
1085
|
+
}
|
1086
|
+
e.authorizations.apply(obj);
|
1087
|
+
if (opts.mock == null) {
|
1088
|
+
new SwaggerHttp().execute(obj);
|
1089
|
+
} else {
|
1090
|
+
console.log(obj);
|
1091
|
+
return obj;
|
1092
|
+
}
|
1093
|
+
}
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
SwaggerRequest.prototype.asCurl = function() {
|
1097
|
+
var header_args, k, v;
|
1098
|
+
header_args = (function() {
|
1099
|
+
var _ref, _results;
|
1100
|
+
_ref = this.headers;
|
1101
|
+
_results = [];
|
1102
|
+
for (k in _ref) {
|
1103
|
+
v = _ref[k];
|
1104
|
+
_results.push("--header \"" + k + ": " + v + "\"");
|
1105
|
+
}
|
1106
|
+
return _results;
|
1107
|
+
}).call(this);
|
1108
|
+
return "curl " + (header_args.join(" ")) + " " + this.url;
|
1109
|
+
};
|
1110
|
+
|
1111
|
+
return SwaggerRequest;
|
1112
|
+
|
1113
|
+
})();
|
1114
|
+
|
1115
|
+
SwaggerHttp = (function() {
|
1116
|
+
SwaggerHttp.prototype.Shred = null;
|
1117
|
+
|
1118
|
+
SwaggerHttp.prototype.shred = null;
|
1119
|
+
|
1120
|
+
SwaggerHttp.prototype.content = null;
|
1121
|
+
|
1122
|
+
function SwaggerHttp() {
|
1123
|
+
var identity, toString,
|
1124
|
+
_this = this;
|
1125
|
+
if (typeof window !== 'undefined') {
|
1126
|
+
this.Shred = require("./shred");
|
1127
|
+
} else {
|
1128
|
+
this.Shred = require("shred");
|
1129
|
+
}
|
1130
|
+
this.shred = new this.Shred();
|
1131
|
+
identity = function(x) {
|
1132
|
+
return x;
|
1133
|
+
};
|
1134
|
+
toString = function(x) {
|
1135
|
+
return x.toString();
|
1136
|
+
};
|
1137
|
+
if (typeof window !== 'undefined') {
|
1138
|
+
this.content = require("./shred/content");
|
1139
|
+
this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
|
1140
|
+
parser: identity,
|
1141
|
+
stringify: toString
|
1142
|
+
});
|
1143
|
+
} else {
|
1144
|
+
this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
|
1145
|
+
parser: identity,
|
1146
|
+
stringify: toString
|
1147
|
+
});
|
1148
|
+
}
|
1149
|
+
}
|
1150
|
+
|
1151
|
+
SwaggerHttp.prototype.execute = function(obj) {
|
1152
|
+
return this.shred.request(obj);
|
1153
|
+
};
|
1154
|
+
|
1155
|
+
return SwaggerHttp;
|
1156
|
+
|
1157
|
+
})();
|
1158
|
+
|
1159
|
+
SwaggerAuthorizations = (function() {
|
1160
|
+
SwaggerAuthorizations.prototype.authz = null;
|
1161
|
+
|
1162
|
+
function SwaggerAuthorizations() {
|
1163
|
+
this.authz = {};
|
1164
|
+
}
|
1165
|
+
|
1166
|
+
SwaggerAuthorizations.prototype.add = function(name, auth) {
|
1167
|
+
this.authz[name] = auth;
|
1168
|
+
return auth;
|
1169
|
+
};
|
1170
|
+
|
1171
|
+
SwaggerAuthorizations.prototype.apply = function(obj) {
|
1172
|
+
var key, value, _ref, _results;
|
1173
|
+
_ref = this.authz;
|
1174
|
+
_results = [];
|
1175
|
+
for (key in _ref) {
|
1176
|
+
value = _ref[key];
|
1177
|
+
_results.push(value.apply(obj));
|
1178
|
+
}
|
1179
|
+
return _results;
|
1180
|
+
};
|
1181
|
+
|
1182
|
+
return SwaggerAuthorizations;
|
1183
|
+
|
1184
|
+
})();
|
1185
|
+
|
1186
|
+
ApiKeyAuthorization = (function() {
|
1187
|
+
ApiKeyAuthorization.prototype.type = null;
|
1188
|
+
|
1189
|
+
ApiKeyAuthorization.prototype.name = null;
|
1190
|
+
|
1191
|
+
ApiKeyAuthorization.prototype.value = null;
|
1192
|
+
|
1193
|
+
function ApiKeyAuthorization(name, value, type) {
|
1194
|
+
this.name = name;
|
1195
|
+
this.value = value;
|
1196
|
+
this.type = type;
|
1197
|
+
}
|
1198
|
+
|
1199
|
+
ApiKeyAuthorization.prototype.apply = function(obj) {
|
1200
|
+
if (this.type === "query") {
|
1201
|
+
if (obj.url.indexOf('?') > 0) {
|
1202
|
+
obj.url = obj.url + "&" + this.name + "=" + this.value;
|
1203
|
+
} else {
|
1204
|
+
obj.url = obj.url + "?" + this.name + "=" + this.value;
|
1205
|
+
}
|
1206
|
+
return true;
|
1207
|
+
} else if (this.type === "header") {
|
1208
|
+
return obj.headers[this.name] = this.value;
|
1209
|
+
}
|
1210
|
+
};
|
1211
|
+
|
1212
|
+
return ApiKeyAuthorization;
|
1213
|
+
|
1214
|
+
})();
|
1215
|
+
|
1216
|
+
PasswordAuthorization = (function() {
|
1217
|
+
PasswordAuthorization.prototype.name = null;
|
1218
|
+
|
1219
|
+
PasswordAuthorization.prototype.username = null;
|
1220
|
+
|
1221
|
+
PasswordAuthorization.prototype.password = null;
|
1222
|
+
|
1223
|
+
function PasswordAuthorization(name, username, password) {
|
1224
|
+
this.name = name;
|
1225
|
+
this.username = username;
|
1226
|
+
this.password = password;
|
1227
|
+
}
|
1228
|
+
|
1229
|
+
PasswordAuthorization.prototype.apply = function(obj) {
|
1230
|
+
return obj.headers["Authorization"] = "Basic " + btoa(this.username + ":" + this.password);
|
1231
|
+
};
|
1232
|
+
|
1233
|
+
return PasswordAuthorization;
|
1234
|
+
|
1235
|
+
})();
|
1236
|
+
|
1237
|
+
this.SwaggerApi = SwaggerApi;
|
1238
|
+
|
1239
|
+
this.SwaggerResource = SwaggerResource;
|
1240
|
+
|
1241
|
+
this.SwaggerOperation = SwaggerOperation;
|
1242
|
+
|
1243
|
+
this.SwaggerRequest = SwaggerRequest;
|
1244
|
+
|
1245
|
+
this.SwaggerModelProperty = SwaggerModelProperty;
|
1246
|
+
|
1247
|
+
this.ApiKeyAuthorization = ApiKeyAuthorization;
|
1248
|
+
|
1249
|
+
this.PasswordAuthorization = PasswordAuthorization;
|
1250
|
+
|
1251
|
+
this.authorizations = new SwaggerAuthorizations();
|
1252
|
+
|
1253
|
+
}).call(this);
|