swagger-ui_rails 0.0.3 → 0.1.0

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.
@@ -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;
@@ -1,116 +1,196 @@
1
- // Generated by CoffeeScript 1.4.0
1
+ // Generated by CoffeeScript 1.6.3
2
2
  (function() {
3
- var SwaggerApi, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource,
4
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
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
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
5
6
 
6
7
  SwaggerApi = (function() {
7
-
8
- SwaggerApi.prototype.discoveryUrl = "http://api.wordnik.com/v4/resources.json";
8
+ SwaggerApi.prototype.url = "http://api.wordnik.com/v4/resources.json";
9
9
 
10
10
  SwaggerApi.prototype.debug = false;
11
11
 
12
- SwaggerApi.prototype.api_key = null;
13
-
14
12
  SwaggerApi.prototype.basePath = null;
15
13
 
16
- function SwaggerApi(options) {
14
+ SwaggerApi.prototype.authorizations = null;
15
+
16
+ SwaggerApi.prototype.authorizationScheme = null;
17
+
18
+ SwaggerApi.prototype.info = null;
19
+
20
+ SwaggerApi.prototype.useJQuery = null;
21
+
22
+ function SwaggerApi(url, options) {
17
23
  if (options == null) {
18
24
  options = {};
19
25
  }
20
- if (options.discoveryUrl != null) {
21
- this.discoveryUrl = options.discoveryUrl;
22
- }
23
- if (options.debug != null) {
24
- this.debug = options.debug;
25
- }
26
- this.apiKeyName = options.apiKeyName != null ? options.apiKeyName : 'api_key';
27
- if (options.apiKey != null) {
28
- this.api_key = options.apiKey;
29
- }
30
- if (options.api_key != null) {
31
- this.api_key = options.api_key;
26
+ if (url) {
27
+ if (url.url) {
28
+ options = url;
29
+ } else {
30
+ this.url = url;
31
+ }
32
+ } else {
33
+ options = url;
32
34
  }
33
- if (options.verbose != null) {
34
- this.verbose = options.verbose;
35
+ if (options.url != null) {
36
+ this.url = options.url;
35
37
  }
36
- this.supportHeaderParams = options.supportHeaderParams != null ? options.supportHeaderParams : false;
37
- this.supportedSubmitMethods = options.supportedSubmitMethods != null ? options.supportedSubmitMethods : ['get'];
38
38
  if (options.success != null) {
39
39
  this.success = options.success;
40
40
  }
41
41
  this.failure = options.failure != null ? options.failure : function() {};
42
42
  this.progress = options.progress != null ? options.progress : function() {};
43
- this.headers = options.headers != null ? options.headers : {};
44
- this.booleanValues = options.booleanValues != null ? options.booleanValues : new Array('true', 'false');
45
- this.discoveryUrl = this.suffixApiKey(this.discoveryUrl);
46
43
  if (options.success != null) {
47
44
  this.build();
48
45
  }
49
46
  }
50
47
 
51
48
  SwaggerApi.prototype.build = function() {
52
- var _this = this;
53
- this.progress('fetching resource list: ' + this.discoveryUrl);
54
- return jQuery.getJSON(this.discoveryUrl, function(response) {
55
- var res, resource, _i, _j, _len, _len1, _ref, _ref1;
56
- if (response.apiVersion != null) {
57
- _this.apiVersion = response.apiVersion;
58
- }
59
- if ((response.basePath != null) && jQuery.trim(response.basePath).length > 0) {
60
- _this.basePath = response.basePath;
61
- if (_this.basePath.match(/^HTTP/i) == null) {
62
- _this.fail("discoveryUrl basePath must be a URL.");
63
- }
64
- _this.basePath = _this.basePath.replace(/\/$/, '');
65
- } else {
66
- if (_this.discoveryUrl.indexOf('?') > 0) {
67
- _this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('?'));
68
- } else {
69
- _this.basePath = _this.discoveryUrl;
70
- }
71
- log('derived basepath from discoveryUrl as ' + _this.basePath);
72
- }
73
- _this.apis = {};
74
- _this.apisArray = [];
75
- if (response.resourcePath != null) {
76
- _this.resourcePath = response.resourcePath;
77
- res = null;
78
- _ref = response.apis;
79
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
80
- resource = _ref[_i];
81
- if (res === null) {
82
- res = new SwaggerResource(resource, _this);
49
+ var e, obj,
50
+ _this = this;
51
+ this.progress('fetching resource list: ' + this.url);
52
+ obj = {
53
+ useJQuery: this.useJQuery,
54
+ url: this.url,
55
+ method: "get",
56
+ headers: {},
57
+ on: {
58
+ error: function(response) {
59
+ if (_this.url.substring(0, 4) !== 'http') {
60
+ return _this.fail('Please specify the protocol for ' + _this.url);
61
+ } else if (response.status === 0) {
62
+ return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
63
+ } else if (response.status === 404) {
64
+ return _this.fail('Can\'t read swagger JSON from ' + _this.url);
65
+ } else {
66
+ return _this.fail(response.status + ' : ' + response.statusText + ' ' + _this.url);
67
+ }
68
+ },
69
+ response: function(response) {
70
+ var responseObj;
71
+ responseObj = JSON.parse(response.data);
72
+ _this.swaggerVersion = responseObj.swaggerVersion;
73
+ if (_this.swaggerVersion === "1.2") {
74
+ return _this.buildFromSpec(responseObj);
83
75
  } else {
84
- res.addOperations(resource.path, resource.operations);
76
+ return _this.buildFrom1_1Spec(responseObj);
85
77
  }
86
78
  }
87
- if (res != null) {
88
- _this.apis[res.name] = res;
89
- _this.apisArray.push(res);
90
- res.ready = true;
91
- _this.selfReflect();
79
+ }
80
+ };
81
+ e = {};
82
+ if (typeof window !== 'undefined') {
83
+ e = window;
84
+ } else {
85
+ e = exports;
86
+ }
87
+ e.authorizations.apply(obj);
88
+ new SwaggerHttp().execute(obj);
89
+ return this;
90
+ };
91
+
92
+ SwaggerApi.prototype.buildFromSpec = function(response) {
93
+ var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
94
+ if (response.apiVersion != null) {
95
+ this.apiVersion = response.apiVersion;
96
+ }
97
+ this.apis = {};
98
+ this.apisArray = [];
99
+ this.produces = response.produces;
100
+ this.authSchemes = response.authorizations;
101
+ if (response.info != null) {
102
+ this.info = response.info;
103
+ }
104
+ isApi = false;
105
+ _ref = response.apis;
106
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
107
+ api = _ref[_i];
108
+ if (api.operations) {
109
+ _ref1 = api.operations;
110
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
111
+ operation = _ref1[_j];
112
+ isApi = true;
92
113
  }
93
- } else {
94
- _ref1 = response.apis;
114
+ }
115
+ }
116
+ if (response.basePath) {
117
+ this.basePath = response.basePath;
118
+ } else if (this.url.indexOf('?') > 0) {
119
+ this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
120
+ } else {
121
+ this.basePath = this.url;
122
+ }
123
+ if (isApi) {
124
+ newName = response.resourcePath.replace(/\//g, '');
125
+ this.resourcePath = response.resourcePath;
126
+ res = new SwaggerResource(response, this);
127
+ this.apis[newName] = res;
128
+ this.apisArray.push(res);
129
+ } else {
130
+ _ref2 = response.apis;
131
+ for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
132
+ resource = _ref2[_k];
133
+ res = new SwaggerResource(resource, this);
134
+ this.apis[res.name] = res;
135
+ this.apisArray.push(res);
136
+ }
137
+ }
138
+ if (this.success) {
139
+ this.success();
140
+ }
141
+ return this;
142
+ };
143
+
144
+ SwaggerApi.prototype.buildFrom1_1Spec = function(response) {
145
+ var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
146
+ log("This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info");
147
+ if (response.apiVersion != null) {
148
+ this.apiVersion = response.apiVersion;
149
+ }
150
+ this.apis = {};
151
+ this.apisArray = [];
152
+ this.produces = response.produces;
153
+ if (response.info != null) {
154
+ this.info = response.info;
155
+ }
156
+ isApi = false;
157
+ _ref = response.apis;
158
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
159
+ api = _ref[_i];
160
+ if (api.operations) {
161
+ _ref1 = api.operations;
95
162
  for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
96
- resource = _ref1[_j];
97
- res = new SwaggerResource(resource, _this);
98
- _this.apis[res.name] = res;
99
- _this.apisArray.push(res);
100
- }
101
- }
102
- return _this;
103
- }).error(function(error) {
104
- if (_this.discoveryUrl.substring(0, 4) !== 'http') {
105
- return _this.fail('Please specify the protocol for ' + _this.discoveryUrl);
106
- } else if (error.status === 0) {
107
- return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
108
- } else if (error.status === 404) {
109
- return _this.fail('Can\'t read swagger JSON from ' + _this.discoveryUrl);
110
- } else {
111
- return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.discoveryUrl);
163
+ operation = _ref1[_j];
164
+ isApi = true;
165
+ }
112
166
  }
113
- });
167
+ }
168
+ if (response.basePath) {
169
+ this.basePath = response.basePath;
170
+ } else if (this.url.indexOf('?') > 0) {
171
+ this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
172
+ } else {
173
+ this.basePath = this.url;
174
+ }
175
+ if (isApi) {
176
+ newName = response.resourcePath.replace(/\//g, '');
177
+ this.resourcePath = response.resourcePath;
178
+ res = new SwaggerResource(response, this);
179
+ this.apis[newName] = res;
180
+ this.apisArray.push(res);
181
+ } else {
182
+ _ref2 = response.apis;
183
+ for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
184
+ resource = _ref2[_k];
185
+ res = new SwaggerResource(resource, this);
186
+ this.apis[res.name] = res;
187
+ this.apisArray.push(res);
188
+ }
189
+ }
190
+ if (this.success) {
191
+ this.success();
192
+ }
193
+ return this;
114
194
  };
115
195
 
116
196
  SwaggerApi.prototype.selfReflect = function() {
@@ -145,7 +225,7 @@
145
225
  for (resource_name in _ref) {
146
226
  resource = _ref[resource_name];
147
227
  for (modelName in resource.models) {
148
- if (!(this.models[modelName] != null)) {
228
+ if (this.models[modelName] == null) {
149
229
  this.models[modelName] = resource.models[modelName];
150
230
  this.modelsArray.push(resource.models[modelName]);
151
231
  }
@@ -160,30 +240,20 @@
160
240
  return _results;
161
241
  };
162
242
 
163
- SwaggerApi.prototype.suffixApiKey = function(url) {
164
- var sep;
165
- if ((this.api_key != null) && jQuery.trim(this.api_key).length > 0 && (url != null)) {
166
- sep = url.indexOf('?') > 0 ? '&' : '?';
167
- return url + sep + this.apiKeyName + '=' + this.api_key;
168
- } else {
169
- return url;
170
- }
171
- };
172
-
173
243
  SwaggerApi.prototype.help = function() {
174
244
  var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2;
175
245
  _ref = this.apis;
176
246
  for (resource_name in _ref) {
177
247
  resource = _ref[resource_name];
178
- console.log(resource_name);
248
+ log(resource_name);
179
249
  _ref1 = resource.operations;
180
250
  for (operation_name in _ref1) {
181
251
  operation = _ref1[operation_name];
182
- console.log(" " + operation.nickname);
252
+ log(" " + operation.nickname);
183
253
  _ref2 = operation.parameters;
184
254
  for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
185
255
  parameter = _ref2[_i];
186
- console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
256
+ log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
187
257
  }
188
258
  }
189
259
  }
@@ -195,65 +265,120 @@
195
265
  })();
196
266
 
197
267
  SwaggerResource = (function() {
268
+ SwaggerResource.prototype.api = null;
269
+
270
+ SwaggerResource.prototype.produces = null;
271
+
272
+ SwaggerResource.prototype.consumes = null;
198
273
 
199
274
  function SwaggerResource(resourceObj, api) {
200
- var parts,
275
+ var consumes, e, obj, parts, produces,
201
276
  _this = this;
202
277
  this.api = api;
278
+ this.api = this.api;
279
+ produces = [];
280
+ consumes = [];
203
281
  this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
204
282
  this.description = resourceObj.description;
205
283
  parts = this.path.split("/");
206
284
  this.name = parts[parts.length - 1].replace('.{format}', '');
207
285
  this.basePath = this.api.basePath;
208
- console.log('bp: ' + this.basePath);
209
286
  this.operations = {};
210
287
  this.operationsArray = [];
211
288
  this.modelsArray = [];
212
289
  this.models = {};
213
- if ((resourceObj.operations != null) && (this.api.resourcePath != null)) {
214
- this.api.progress('reading resource ' + this.name + ' models and operations');
215
- this.addModels(resourceObj.models);
216
- this.addOperations(resourceObj.path, resourceObj.operations);
217
- this.api[this.name] = this;
290
+ this.rawModels = {};
291
+ if ((resourceObj.apis != null) && (this.api.resourcePath != null)) {
292
+ this.addApiDeclaration(resourceObj);
218
293
  } else {
219
294
  if (this.path == null) {
220
295
  this.api.fail("SwaggerResources must have a path.");
221
296
  }
222
- this.url = this.api.suffixApiKey(this.api.basePath + this.path.replace('{format}', 'json'));
223
- console.log('basePath: ' + this.api.basePath);
224
- console.log('url: ' + this.url);
297
+ if (this.path.substring(0, 4) === 'http') {
298
+ this.url = this.path.replace('{format}', 'json');
299
+ } else {
300
+ this.url = this.api.basePath + this.path.replace('{format}', 'json');
301
+ }
225
302
  this.api.progress('fetching resource ' + this.name + ': ' + this.url);
226
- jQuery.getJSON(this.url, function(response) {
227
- var endpoint, _i, _len, _ref;
228
- if ((response.basePath != null) && jQuery.trim(response.basePath).length > 0) {
229
- _this.basePath = response.basePath;
230
- _this.basePath = _this.basePath.replace(/\/$/, '');
231
- }
232
- _this.addModels(response.models);
233
- if (response.apis) {
234
- _ref = response.apis;
235
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
236
- endpoint = _ref[_i];
237
- _this.addOperations(endpoint.path, endpoint.operations);
303
+ obj = {
304
+ url: this.url,
305
+ method: "get",
306
+ useJQuery: this.useJQuery,
307
+ headers: {},
308
+ on: {
309
+ error: function(response) {
310
+ return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + response.statusText + ")");
311
+ },
312
+ response: function(response) {
313
+ var responseObj;
314
+ responseObj = JSON.parse(response.data);
315
+ return _this.addApiDeclaration(responseObj);
238
316
  }
239
317
  }
240
- _this.api[_this.name] = _this;
241
- _this.ready = true;
242
- return _this.api.selfReflect();
243
- }).error(function(error) {
244
- return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + error.statusText + ")");
245
- });
318
+ };
319
+ e = {};
320
+ if (typeof window !== 'undefined') {
321
+ e = window;
322
+ } else {
323
+ e = exports;
324
+ }
325
+ e.authorizations.apply(obj);
326
+ new SwaggerHttp().execute(obj);
246
327
  }
247
328
  }
248
329
 
330
+ SwaggerResource.prototype.getAbsoluteBasePath = function(relativeBasePath) {
331
+ var parts, pos, url;
332
+ url = this.api.basePath;
333
+ pos = url.lastIndexOf(relativeBasePath);
334
+ if (pos === -1) {
335
+ parts = url.split("/");
336
+ url = parts[0] + "//" + parts[2];
337
+ if (relativeBasePath.indexOf("/") === 0) {
338
+ return url + relativeBasePath;
339
+ } else {
340
+ return url + "/" + relativeBasePath;
341
+ }
342
+ } else if (relativeBasePath === "/") {
343
+ return url.substring(0, pos);
344
+ } else {
345
+ return url.substring(0, pos) + relativeBasePath;
346
+ }
347
+ };
348
+
349
+ SwaggerResource.prototype.addApiDeclaration = function(response) {
350
+ var endpoint, _i, _len, _ref;
351
+ if (response.produces != null) {
352
+ this.produces = response.produces;
353
+ }
354
+ if (response.consumes != null) {
355
+ this.consumes = response.consumes;
356
+ }
357
+ if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0) {
358
+ this.basePath = response.basePath.indexOf("http") === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath;
359
+ }
360
+ this.addModels(response.models);
361
+ if (response.apis) {
362
+ _ref = response.apis;
363
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
364
+ endpoint = _ref[_i];
365
+ this.addOperations(endpoint.path, endpoint.operations, response.consumes, response.produces);
366
+ }
367
+ }
368
+ this.api[this.name] = this;
369
+ this.ready = true;
370
+ return this.api.selfReflect();
371
+ };
372
+
249
373
  SwaggerResource.prototype.addModels = function(models) {
250
374
  var model, modelName, swaggerModel, _i, _len, _ref, _results;
251
375
  if (models != null) {
252
376
  for (modelName in models) {
253
- if (!(this.models[modelName] != null)) {
377
+ if (this.models[modelName] == null) {
254
378
  swaggerModel = new SwaggerModel(modelName, models[modelName]);
255
379
  this.modelsArray.push(swaggerModel);
256
380
  this.models[modelName] = swaggerModel;
381
+ this.rawModels[modelName] = models[modelName];
257
382
  }
258
383
  }
259
384
  _ref = this.modelsArray;
@@ -266,30 +391,50 @@
266
391
  }
267
392
  };
268
393
 
269
- SwaggerResource.prototype.addOperations = function(resource_path, ops) {
270
- var consumes, err, errorResponses, o, op, _i, _j, _len, _len1, _results;
394
+ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes, produces) {
395
+ var method, o, op, r, ref, responseMessages, type, _i, _j, _len, _len1, _results;
271
396
  if (ops) {
272
397
  _results = [];
273
398
  for (_i = 0, _len = ops.length; _i < _len; _i++) {
274
399
  o = ops[_i];
275
- consumes = o.consumes;
276
- if (o.supportedContentTypes) {
277
- consumes = o.supportedContentTypes;
400
+ consumes = this.consumes;
401
+ produces = this.produces;
402
+ if (o.consumes != null) {
403
+ consumes = o.consumes;
404
+ } else {
405
+ consumes = this.consumes;
278
406
  }
279
- errorResponses = o.responseMessages;
280
- if (errorResponses) {
281
- for (_j = 0, _len1 = errorResponses.length; _j < _len1; _j++) {
282
- err = errorResponses[_j];
283
- err.reason = err.message;
407
+ if (o.produces != null) {
408
+ produces = o.produces;
409
+ } else {
410
+ produces = this.produces;
411
+ }
412
+ type = o.type || o.responseClass;
413
+ if (type === "array") {
414
+ ref = null;
415
+ if (o.items) {
416
+ ref = o.items["type"] || o.items["$ref"];
284
417
  }
418
+ type = "array[" + ref + "]";
285
419
  }
286
- if (o.errorResponses) {
287
- errorResponses = o.errorResponses;
420
+ responseMessages = o.responseMessages;
421
+ method = o.method;
422
+ if (o.httpMethod) {
423
+ method = o.httpMethod;
424
+ }
425
+ if (o.supportedContentTypes) {
426
+ consumes = o.supportedContentTypes;
288
427
  }
289
- if (o.method) {
290
- o.httpMethod = o.method;
428
+ if (o.errorResponses) {
429
+ responseMessages = o.errorResponses;
430
+ for (_j = 0, _len1 = responseMessages.length; _j < _len1; _j++) {
431
+ r = responseMessages[_j];
432
+ r.message = r.reason;
433
+ r.reason = null;
434
+ }
291
435
  }
292
- op = new SwaggerOperation(o.nickname, resource_path, o.httpMethod, o.parameters, o.summary, o.notes, o.responseClass, errorResponses, this, o.consumes, o.produces);
436
+ o.nickname = this.sanitize(o.nickname);
437
+ op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, type, responseMessages, this, consumes, produces, o.authorizations);
293
438
  this.operations[op.nickname] = op;
294
439
  _results.push(this.operationsArray.push(op));
295
440
  }
@@ -297,19 +442,30 @@
297
442
  }
298
443
  };
299
444
 
445
+ SwaggerResource.prototype.sanitize = function(nickname) {
446
+ var op;
447
+ op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|./?,\\'""-]/g, '_');
448
+ op = op.replace(/((_){2,})/g, '_');
449
+ op = op.replace(/^(_)*/g, '');
450
+ op = op.replace(/([_])*$/g, '');
451
+ return op;
452
+ };
453
+
300
454
  SwaggerResource.prototype.help = function() {
301
- var operation, operation_name, parameter, _i, _len, _ref, _ref1;
455
+ var msg, operation, operation_name, parameter, _i, _len, _ref, _ref1, _results;
302
456
  _ref = this.operations;
457
+ _results = [];
303
458
  for (operation_name in _ref) {
304
459
  operation = _ref[operation_name];
305
- console.log(" " + operation.nickname);
460
+ msg = " " + operation.nickname;
306
461
  _ref1 = operation.parameters;
307
462
  for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
308
463
  parameter = _ref1[_i];
309
- console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
464
+ msg.concat(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
310
465
  }
466
+ _results.push(msg);
311
467
  }
312
- return this;
468
+ return _results;
313
469
  };
314
470
 
315
471
  return SwaggerResource;
@@ -317,24 +473,32 @@
317
473
  })();
318
474
 
319
475
  SwaggerModel = (function() {
320
-
321
476
  function SwaggerModel(modelName, obj) {
322
- var propertyName;
477
+ var prop, propertyName, value;
323
478
  this.name = obj.id != null ? obj.id : modelName;
324
479
  this.properties = [];
325
480
  for (propertyName in obj.properties) {
326
- this.properties.push(new SwaggerModelProperty(propertyName, obj.properties[propertyName]));
481
+ if (obj.required != null) {
482
+ for (value in obj.required) {
483
+ if (propertyName === obj.required[value]) {
484
+ obj.properties[propertyName].required = true;
485
+ }
486
+ }
487
+ }
488
+ prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]);
489
+ this.properties.push(prop);
327
490
  }
328
491
  }
329
492
 
330
493
  SwaggerModel.prototype.setReferencedModels = function(allModels) {
331
- var prop, _i, _len, _ref, _results;
494
+ var prop, type, _i, _len, _ref, _results;
332
495
  _ref = this.properties;
333
496
  _results = [];
334
497
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
335
498
  prop = _ref[_i];
336
- if (allModels[prop.dataType] != null) {
337
- _results.push(prop.refModel = allModels[prop.dataType]);
499
+ type = prop.type || prop.dataType;
500
+ if (allModels[type] != null) {
501
+ _results.push(prop.refModel = allModels[type]);
338
502
  } else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) {
339
503
  _results.push(prop.refModel = allModels[prop.refDataType]);
340
504
  } else {
@@ -365,7 +529,7 @@
365
529
  _ref1 = this.properties;
366
530
  for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
367
531
  prop = _ref1[_j];
368
- if ((prop.refModel != null) && (modelsToIgnore.indexOf(prop.refModel)) === -1) {
532
+ if ((prop.refModel != null) && (modelsToIgnore[prop.refModel] !== 'undefined') === -1) {
369
533
  returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
370
534
  }
371
535
  }
@@ -382,6 +546,7 @@
382
546
  prop = _ref[_i];
383
547
  result[prop.name] = prop.getSampleValue(modelsToIgnore);
384
548
  }
549
+ modelsToIgnore.pop(this.name);
385
550
  return result;
386
551
  };
387
552
 
@@ -390,10 +555,9 @@
390
555
  })();
391
556
 
392
557
  SwaggerModelProperty = (function() {
393
-
394
558
  function SwaggerModelProperty(name, obj) {
395
559
  this.name = name;
396
- this.dataType = obj.type;
560
+ this.dataType = obj.type || obj.dataType || obj["$ref"];
397
561
  this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
398
562
  this.descr = obj.description;
399
563
  this.required = obj.required;
@@ -413,11 +577,18 @@
413
577
  this.valuesString = "'" + this.values.join("' or '") + "'";
414
578
  }
415
579
  }
580
+ if (obj["enum"] != null) {
581
+ this.valueType = "string";
582
+ this.values = obj["enum"];
583
+ if (this.values != null) {
584
+ this.valueString = "'" + this.values.join("' or '") + "'";
585
+ }
586
+ }
416
587
  }
417
588
 
418
589
  SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
419
590
  var result;
420
- if ((this.refModel != null) && (modelsToIgnore.indexOf(this.refModel.name) === -1)) {
591
+ if ((this.refModel != null) && (modelsToIgnore[this.refModel.name] === 'undefined')) {
421
592
  result = this.refModel.createJSONSample(modelsToIgnore);
422
593
  } else {
423
594
  if (this.isCollection) {
@@ -455,54 +626,74 @@
455
626
  })();
456
627
 
457
628
  SwaggerOperation = (function() {
458
-
459
- function SwaggerOperation(nickname, path, httpMethod, parameters, summary, notes, responseClass, errorResponses, resource, consumes, produces) {
460
- var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2,
629
+ function SwaggerOperation(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces, authorizations) {
630
+ var parameter, v, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3,
461
631
  _this = this;
462
632
  this.nickname = nickname;
463
633
  this.path = path;
464
- this.httpMethod = httpMethod;
634
+ this.method = method;
465
635
  this.parameters = parameters != null ? parameters : [];
466
636
  this.summary = summary;
467
637
  this.notes = notes;
468
- this.responseClass = responseClass;
469
- this.errorResponses = errorResponses;
638
+ this.type = type;
639
+ this.responseMessages = responseMessages;
470
640
  this.resource = resource;
471
641
  this.consumes = consumes;
472
642
  this.produces = produces;
643
+ this.authorizations = authorizations;
473
644
  this["do"] = __bind(this["do"], this);
474
-
475
645
  if (this.nickname == null) {
476
646
  this.resource.api.fail("SwaggerOperations must have a nickname.");
477
647
  }
478
648
  if (this.path == null) {
479
649
  this.resource.api.fail("SwaggerOperation " + nickname + " is missing path.");
480
650
  }
481
- if (this.httpMethod == null) {
482
- this.resource.api.fail("SwaggerOperation " + nickname + " is missing httpMethod.");
651
+ if (this.method == null) {
652
+ this.resource.api.fail("SwaggerOperation " + nickname + " is missing method.");
483
653
  }
484
654
  this.path = this.path.replace('{format}', 'json');
485
- this.httpMethod = this.httpMethod.toLowerCase();
486
- this.isGetMethod = this.httpMethod === "get";
655
+ this.method = this.method.toLowerCase();
656
+ this.isGetMethod = this.method === "get";
487
657
  this.resourceName = this.resource.name;
488
- if (((_ref = this.responseClass) != null ? _ref.toLowerCase() : void 0) === 'void') {
489
- this.responseClass = void 0;
658
+ if (((_ref = this.type) != null ? _ref.toLowerCase() : void 0) === 'void') {
659
+ this.type = void 0;
490
660
  }
491
- if (this.responseClass != null) {
492
- this.responseClassSignature = this.getSignature(this.responseClass, this.resource.models);
493
- this.responseSampleJSON = this.getSampleJSON(this.responseClass, this.resource.models);
661
+ if (this.type != null) {
662
+ this.responseClassSignature = this.getSignature(this.type, this.resource.models);
663
+ this.responseSampleJSON = this.getSampleJSON(this.type, this.resource.models);
494
664
  }
495
- this.errorResponses = this.errorResponses || [];
665
+ this.responseMessages = this.responseMessages || [];
496
666
  _ref1 = this.parameters;
497
667
  for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
498
668
  parameter = _ref1[_i];
499
- parameter.name = parameter.name || parameter.dataType;
500
- if (parameter.dataType.toLowerCase() === 'boolean') {
669
+ parameter.name = parameter.name || parameter.type || parameter.dataType;
670
+ type = parameter.type || parameter.dataType;
671
+ if (type.toLowerCase() === 'boolean') {
501
672
  parameter.allowableValues = {};
502
- parameter.allowableValues.values = this.resource.api.booleanValues;
673
+ parameter.allowableValues.values = ["true", "false"];
674
+ }
675
+ parameter.signature = this.getSignature(type, this.resource.models);
676
+ parameter.sampleJSON = this.getSampleJSON(type, this.resource.models);
677
+ if (parameter["enum"] != null) {
678
+ parameter.isList = true;
679
+ parameter.allowableValues = {};
680
+ parameter.allowableValues.descriptiveValues = [];
681
+ _ref2 = parameter["enum"];
682
+ for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
683
+ v = _ref2[_j];
684
+ if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
685
+ parameter.allowableValues.descriptiveValues.push({
686
+ value: String(v),
687
+ isDefault: true
688
+ });
689
+ } else {
690
+ parameter.allowableValues.descriptiveValues.push({
691
+ value: String(v),
692
+ isDefault: false
693
+ });
694
+ }
695
+ }
503
696
  }
504
- parameter.signature = this.getSignature(parameter.dataType, this.resource.models);
505
- parameter.sampleJSON = this.getSampleJSON(parameter.dataType, this.resource.models);
506
697
  if (parameter.allowableValues != null) {
507
698
  if (parameter.allowableValues.valueType === "RANGE") {
508
699
  parameter.isRange = true;
@@ -511,9 +702,9 @@
511
702
  }
512
703
  if (parameter.allowableValues.values != null) {
513
704
  parameter.allowableValues.descriptiveValues = [];
514
- _ref2 = parameter.allowableValues.values;
515
- for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
516
- v = _ref2[_j];
705
+ _ref3 = parameter.allowableValues.values;
706
+ for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
707
+ v = _ref3[_k];
517
708
  if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
518
709
  parameter.allowableValues.descriptiveValues.push({
519
710
  value: v,
@@ -532,71 +723,126 @@
532
723
  this.resource[this.nickname] = function(args, callback, error) {
533
724
  return _this["do"](args, callback, error);
534
725
  };
726
+ this.resource[this.nickname].help = function() {
727
+ return _this.help();
728
+ };
535
729
  }
536
730
 
537
- SwaggerOperation.prototype.isListType = function(dataType) {
538
- if (dataType.indexOf('[') >= 0) {
539
- return dataType.substring(dataType.indexOf('[') + 1, dataType.indexOf(']'));
731
+ SwaggerOperation.prototype.isListType = function(type) {
732
+ if (type.indexOf('[') >= 0) {
733
+ return type.substring(type.indexOf('[') + 1, type.indexOf(']'));
540
734
  } else {
541
735
  return void 0;
542
736
  }
543
737
  };
544
738
 
545
- SwaggerOperation.prototype.getSignature = function(dataType, models) {
739
+ SwaggerOperation.prototype.getSignature = function(type, models) {
546
740
  var isPrimitive, listType;
547
- listType = this.isListType(dataType);
548
- isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true;
741
+ listType = this.isListType(type);
742
+ isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
549
743
  if (isPrimitive) {
550
- return dataType;
744
+ return type;
551
745
  } else {
552
746
  if (listType != null) {
553
747
  return models[listType].getMockSignature();
554
748
  } else {
555
- return models[dataType].getMockSignature();
749
+ return models[type].getMockSignature();
556
750
  }
557
751
  }
558
752
  };
559
753
 
560
- SwaggerOperation.prototype.getSampleJSON = function(dataType, models) {
754
+ SwaggerOperation.prototype.getSampleJSON = function(type, models) {
561
755
  var isPrimitive, listType, val;
562
- listType = this.isListType(dataType);
563
- isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true;
564
- val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[dataType].createJSONSample());
756
+ listType = this.isListType(type);
757
+ isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
758
+ val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample());
565
759
  if (val) {
566
760
  val = listType ? [val] : val;
567
761
  return JSON.stringify(val, null, 2);
568
762
  }
569
763
  };
570
764
 
571
- SwaggerOperation.prototype["do"] = function(args, callback, error) {
572
- var body, headers;
765
+ SwaggerOperation.prototype["do"] = function(args, opts, callback, error) {
766
+ var key, param, params, possibleParams, req, requestContentType, responseContentType, value, _i, _len, _ref;
573
767
  if (args == null) {
574
768
  args = {};
575
769
  }
770
+ if (opts == null) {
771
+ opts = {};
772
+ }
773
+ requestContentType = null;
774
+ responseContentType = null;
576
775
  if ((typeof args) === "function") {
577
- error = callback;
776
+ error = opts;
578
777
  callback = args;
579
778
  args = {};
580
779
  }
780
+ if ((typeof opts) === "function") {
781
+ error = callback;
782
+ callback = opts;
783
+ }
581
784
  if (error == null) {
582
785
  error = function(xhr, textStatus, error) {
583
- return console.log(xhr, textStatus, error);
786
+ return log(xhr, textStatus, error);
584
787
  };
585
788
  }
586
789
  if (callback == null) {
587
- callback = function(data) {
588
- return console.log(data);
790
+ callback = function(response) {
791
+ var content;
792
+ content = null;
793
+ if (response != null) {
794
+ content = response.data;
795
+ } else {
796
+ content = "no data";
797
+ }
798
+ return log("default callback: " + content);
589
799
  };
590
800
  }
801
+ params = {};
802
+ params.headers = [];
591
803
  if (args.headers != null) {
592
- headers = args.headers;
804
+ params.headers = args.headers;
593
805
  delete args.headers;
594
806
  }
807
+ _ref = this.parameters;
808
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
809
+ param = _ref[_i];
810
+ if (param.paramType === "header") {
811
+ if (args[param.name]) {
812
+ params.headers[param.name] = args[param.name];
813
+ }
814
+ }
815
+ }
595
816
  if (args.body != null) {
596
- body = args.body;
817
+ params.body = args.body;
597
818
  delete args.body;
598
819
  }
599
- return new SwaggerRequest(this.httpMethod, this.urlify(args), headers, body, callback, error, this);
820
+ possibleParams = (function() {
821
+ var _j, _len1, _ref1, _results;
822
+ _ref1 = this.parameters;
823
+ _results = [];
824
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
825
+ param = _ref1[_j];
826
+ if (param.paramType === "form" || param.paramType.toLowerCase() === "file") {
827
+ _results.push(param);
828
+ }
829
+ }
830
+ return _results;
831
+ }).call(this);
832
+ if (possibleParams) {
833
+ for (key in possibleParams) {
834
+ value = possibleParams[key];
835
+ if (args[value.name]) {
836
+ params[value.name] = args[value.name];
837
+ }
838
+ }
839
+ }
840
+ req = new SwaggerRequest(this.method, this.urlify(args), params, opts, callback, error, this);
841
+ if (opts.mock != null) {
842
+ return req;
843
+ } else {
844
+ return true;
845
+ }
600
846
  };
601
847
 
602
848
  SwaggerOperation.prototype.pathJson = function() {
@@ -607,11 +853,8 @@
607
853
  return this.path.replace("{format}", "xml");
608
854
  };
609
855
 
610
- SwaggerOperation.prototype.urlify = function(args, includeApiKey) {
611
- var param, queryParams, reg, url, _i, _len, _ref;
612
- if (includeApiKey == null) {
613
- includeApiKey = true;
614
- }
856
+ SwaggerOperation.prototype.urlify = function(args) {
857
+ var param, queryParams, reg, url, _i, _j, _len, _len1, _ref, _ref1;
615
858
  url = this.resource.basePath + this.pathJson();
616
859
  _ref = this.parameters;
617
860
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -626,13 +869,18 @@
626
869
  }
627
870
  }
628
871
  }
629
- if (includeApiKey && (this.resource.api.api_key != null) && this.resource.api.api_key.length > 0) {
630
- args[this.apiKeyName] = this.resource.api.api_key;
631
- }
632
- if (this.supportHeaderParams()) {
633
- queryParams = jQuery.param(this.getQueryParams(args, includeApiKey));
634
- } else {
635
- queryParams = jQuery.param(this.getQueryAndHeaderParams(args, includeApiKey));
872
+ queryParams = "";
873
+ _ref1 = this.parameters;
874
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
875
+ param = _ref1[_j];
876
+ if (param.paramType === 'query') {
877
+ if (args[param.name]) {
878
+ if (queryParams !== "") {
879
+ queryParams += "&";
880
+ }
881
+ queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]);
882
+ }
883
+ }
636
884
  }
637
885
  if ((queryParams != null) && queryParams.length > 0) {
638
886
  url += "?" + queryParams;
@@ -648,58 +896,44 @@
648
896
  return this.resource.api.supportedSubmitMethods;
649
897
  };
650
898
 
651
- SwaggerOperation.prototype.getQueryAndHeaderParams = function(args, includeApiKey) {
652
- if (includeApiKey == null) {
653
- includeApiKey = true;
654
- }
655
- return this.getMatchingParams(['query', 'header'], args, includeApiKey);
656
- };
657
-
658
- SwaggerOperation.prototype.getQueryParams = function(args, includeApiKey) {
659
- if (includeApiKey == null) {
660
- includeApiKey = true;
661
- }
662
- return this.getMatchingParams(['query'], args, includeApiKey);
899
+ SwaggerOperation.prototype.getQueryParams = function(args) {
900
+ return this.getMatchingParams(['query'], args);
663
901
  };
664
902
 
665
- SwaggerOperation.prototype.getHeaderParams = function(args, includeApiKey) {
666
- if (includeApiKey == null) {
667
- includeApiKey = true;
668
- }
669
- return this.getMatchingParams(['header'], args, includeApiKey);
903
+ SwaggerOperation.prototype.getHeaderParams = function(args) {
904
+ return this.getMatchingParams(['header'], args);
670
905
  };
671
906
 
672
- SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args, includeApiKey) {
907
+ SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args) {
673
908
  var matchingParams, name, param, value, _i, _len, _ref, _ref1;
674
909
  matchingParams = {};
675
910
  _ref = this.parameters;
676
911
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
677
912
  param = _ref[_i];
678
- if ((jQuery.inArray(param.paramType, paramTypes) >= 0) && args[param.name]) {
913
+ if (args && args[param.name]) {
679
914
  matchingParams[param.name] = args[param.name];
680
915
  }
681
916
  }
682
- if (includeApiKey && (this.resource.api.api_key != null) && this.resource.api.api_key.length > 0) {
683
- matchingParams[this.resource.api.apiKeyName] = this.resource.api.api_key;
684
- }
685
- if (jQuery.inArray('header', paramTypes) >= 0) {
686
- _ref1 = this.resource.api.headers;
687
- for (name in _ref1) {
688
- value = _ref1[name];
689
- matchingParams[name] = value;
690
- }
917
+ _ref1 = this.resource.api.headers;
918
+ for (name in _ref1) {
919
+ value = _ref1[name];
920
+ matchingParams[name] = value;
691
921
  }
692
922
  return matchingParams;
693
923
  };
694
924
 
695
925
  SwaggerOperation.prototype.help = function() {
696
- var parameter, _i, _len, _ref;
926
+ var msg, parameter, _i, _len, _ref;
927
+ msg = "";
697
928
  _ref = this.parameters;
698
929
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
699
930
  parameter = _ref[_i];
700
- console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
931
+ if (msg !== "") {
932
+ msg += "\n";
933
+ }
934
+ msg += "* " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description;
701
935
  }
702
- return this;
936
+ return msg;
703
937
  };
704
938
 
705
939
  return SwaggerOperation;
@@ -707,17 +941,17 @@
707
941
  })();
708
942
 
709
943
  SwaggerRequest = (function() {
710
-
711
- function SwaggerRequest(type, url, headers, body, successCallback, errorCallback, operation) {
712
- var obj,
944
+ function SwaggerRequest(type, url, params, opts, successCallback, errorCallback, operation, execution) {
945
+ var body, e, fields, headers, key, myHeaders, name, obj, param, parent, possibleParams, requestContentType, responseContentType, status, urlEncoded, value, values,
713
946
  _this = this;
714
947
  this.type = type;
715
948
  this.url = url;
716
- this.headers = headers;
717
- this.body = body;
949
+ this.params = params;
950
+ this.opts = opts;
718
951
  this.successCallback = successCallback;
719
952
  this.errorCallback = errorCallback;
720
953
  this.operation = operation;
954
+ this.execution = execution;
721
955
  if (this.type == null) {
722
956
  throw "SwaggerRequest type is required (get/post/put/delete).";
723
957
  }
@@ -733,30 +967,151 @@
733
967
  if (this.operation == null) {
734
968
  throw "SwaggerRequest operation is required.";
735
969
  }
736
- if (this.operation.resource.api.verbose) {
737
- console.log(this.asCurl());
970
+ this.type = this.type.toUpperCase();
971
+ headers = params.headers;
972
+ myHeaders = {};
973
+ body = params.body;
974
+ parent = params["parent"];
975
+ requestContentType = "application/json";
976
+ if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) {
977
+ if (this.opts.requestContentType) {
978
+ requestContentType = this.opts.requestContentType;
979
+ }
980
+ } else {
981
+ if (((function() {
982
+ var _i, _len, _ref, _results;
983
+ _ref = this.operation.parameters;
984
+ _results = [];
985
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
986
+ param = _ref[_i];
987
+ if (param.paramType === "form") {
988
+ _results.push(param);
989
+ }
990
+ }
991
+ return _results;
992
+ }).call(this)).length > 0) {
993
+ type = param.type || param.dataType;
994
+ if (((function() {
995
+ var _i, _len, _ref, _results;
996
+ _ref = this.operation.parameters;
997
+ _results = [];
998
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
999
+ param = _ref[_i];
1000
+ if (type.toLowerCase() === "file") {
1001
+ _results.push(param);
1002
+ }
1003
+ }
1004
+ return _results;
1005
+ }).call(this)).length > 0) {
1006
+ requestContentType = "multipart/form-data";
1007
+ } else {
1008
+ requestContentType = "application/x-www-form-urlencoded";
1009
+ }
1010
+ } else if (this.type !== "DELETE") {
1011
+ requestContentType = null;
1012
+ }
1013
+ }
1014
+ if (requestContentType && this.operation.consumes) {
1015
+ if (this.operation.consumes[requestContentType] === 'undefined') {
1016
+ log("server doesn't consume " + requestContentType + ", try " + JSON.stringify(this.operation.consumes));
1017
+ if (this.requestContentType === null) {
1018
+ requestContentType = this.operation.consumes[0];
1019
+ }
1020
+ }
1021
+ }
1022
+ responseContentType = null;
1023
+ if (this.type === "POST" || this.type === "GET" || this.type === "PATCH") {
1024
+ if (this.opts.responseContentType) {
1025
+ responseContentType = this.opts.responseContentType;
1026
+ } else {
1027
+ responseContentType = "application/json";
1028
+ }
1029
+ } else {
1030
+ responseContentType = null;
738
1031
  }
739
- this.headers || (this.headers = {});
740
- if (this.operation.resource.api.api_key != null) {
741
- this.headers[this.apiKeyName] = this.operation.resource.api.api_key;
1032
+ if (responseContentType && this.operation.produces) {
1033
+ if (this.operation.produces[responseContentType] === 'undefined') {
1034
+ log("server can't produce " + responseContentType);
1035
+ }
1036
+ }
1037
+ if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) {
1038
+ fields = {};
1039
+ possibleParams = (function() {
1040
+ var _i, _len, _ref, _results;
1041
+ _ref = this.operation.parameters;
1042
+ _results = [];
1043
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1044
+ param = _ref[_i];
1045
+ if (param.paramType === "form") {
1046
+ _results.push(param);
1047
+ }
1048
+ }
1049
+ return _results;
1050
+ }).call(this);
1051
+ values = {};
1052
+ for (key in possibleParams) {
1053
+ value = possibleParams[key];
1054
+ if (this.params[value.name]) {
1055
+ values[value.name] = this.params[value.name];
1056
+ }
1057
+ }
1058
+ urlEncoded = "";
1059
+ for (key in values) {
1060
+ value = values[key];
1061
+ if (urlEncoded !== "") {
1062
+ urlEncoded += "&";
1063
+ }
1064
+ urlEncoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
1065
+ }
1066
+ body = urlEncoded;
742
1067
  }
743
- if (this.headers.mock == null) {
1068
+ for (name in headers) {
1069
+ myHeaders[name] = headers[name];
1070
+ }
1071
+ if (requestContentType) {
1072
+ myHeaders["Content-Type"] = requestContentType;
1073
+ }
1074
+ if (responseContentType) {
1075
+ myHeaders["Accept"] = responseContentType;
1076
+ }
1077
+ if (!((headers != null) && (headers.mock != null))) {
744
1078
  obj = {
745
- type: this.type,
746
1079
  url: this.url,
747
- data: JSON.stringify(this.body),
748
- dataType: 'json',
749
- error: function(xhr, textStatus, error) {
750
- return _this.errorCallback(xhr, textStatus, error);
751
- },
752
- success: function(data) {
753
- return _this.successCallback(data);
1080
+ method: this.type,
1081
+ headers: myHeaders,
1082
+ body: body,
1083
+ useJQuery: this.useJQuery,
1084
+ on: {
1085
+ error: function(response) {
1086
+ return _this.errorCallback(response, _this.opts.parent);
1087
+ },
1088
+ redirect: function(response) {
1089
+ return _this.successCallback(response, _this.opts.parent);
1090
+ },
1091
+ 307: function(response) {
1092
+ return _this.successCallback(response, _this.opts.parent);
1093
+ },
1094
+ response: function(response) {
1095
+ return _this.successCallback(response, _this.opts.parent);
1096
+ }
754
1097
  }
755
1098
  };
756
- if (obj.type.toLowerCase() === "post" || obj.type.toLowerCase() === "put") {
757
- obj.contentType = "application/json";
1099
+ e = {};
1100
+ if (typeof window !== 'undefined') {
1101
+ e = window;
1102
+ } else {
1103
+ e = exports;
1104
+ }
1105
+ status = e.authorizations.apply(obj, this.operation.authorizations);
1106
+ if (opts.mock == null) {
1107
+ if (status !== false) {
1108
+ new SwaggerHttp().execute(obj);
1109
+ } else {
1110
+ obj.canceled = true;
1111
+ }
1112
+ } else {
1113
+ return obj;
758
1114
  }
759
- jQuery.ajax(obj);
760
1115
  }
761
1116
  }
762
1117
 
@@ -779,14 +1134,294 @@
779
1134
 
780
1135
  })();
781
1136
 
782
- window.SwaggerApi = SwaggerApi;
1137
+ SwaggerHttp = (function() {
1138
+ function SwaggerHttp() {}
1139
+
1140
+ SwaggerHttp.prototype.Shred = null;
1141
+
1142
+ SwaggerHttp.prototype.shred = null;
1143
+
1144
+ SwaggerHttp.prototype.content = null;
1145
+
1146
+ SwaggerHttp.prototype.initShred = function() {
1147
+ var identity, toString,
1148
+ _this = this;
1149
+ if (typeof window !== 'undefined') {
1150
+ this.Shred = require("./shred");
1151
+ } else {
1152
+ this.Shred = require("shred");
1153
+ }
1154
+ this.shred = new this.Shred();
1155
+ identity = function(x) {
1156
+ return x;
1157
+ };
1158
+ toString = function(x) {
1159
+ return x.toString();
1160
+ };
1161
+ if (typeof window !== 'undefined') {
1162
+ this.content = require("./shred/content");
1163
+ return this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
1164
+ parser: identity,
1165
+ stringify: toString
1166
+ });
1167
+ } else {
1168
+ return this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
1169
+ parser: identity,
1170
+ stringify: toString
1171
+ });
1172
+ }
1173
+ };
1174
+
1175
+ SwaggerHttp.prototype.execute = function(obj) {
1176
+ if (this.isIE() || obj.useJQuery) {
1177
+ return this.executeWithJQuery(obj);
1178
+ } else {
1179
+ return this.executeWithShred(obj);
1180
+ }
1181
+ };
1182
+
1183
+ SwaggerHttp.prototype.executeWithShred = function(obj) {
1184
+ var cb, res,
1185
+ _this = this;
1186
+ if (!this.Shred) {
1187
+ this.initShred();
1188
+ }
1189
+ cb = obj.on;
1190
+ res = {
1191
+ error: function(response) {
1192
+ if (obj) {
1193
+ return cb.error(response);
1194
+ }
1195
+ },
1196
+ redirect: function(response) {
1197
+ if (obj) {
1198
+ return cb.redirect(response);
1199
+ }
1200
+ },
1201
+ 307: function(response) {
1202
+ if (obj) {
1203
+ return cb.redirect(response);
1204
+ }
1205
+ },
1206
+ response: function(raw) {
1207
+ var headers, out;
1208
+ if (obj) {
1209
+ headers = raw._headers;
1210
+ out = {
1211
+ headers: headers,
1212
+ url: raw.request.url,
1213
+ method: raw.request.method,
1214
+ status: raw.status,
1215
+ data: raw.content.data
1216
+ };
1217
+ return cb.response(out);
1218
+ }
1219
+ }
1220
+ };
1221
+ if (obj) {
1222
+ obj.on = res;
1223
+ }
1224
+ return this.shred.request(obj);
1225
+ };
1226
+
1227
+ SwaggerHttp.prototype.executeWithJQuery = function(obj) {
1228
+ var beforeSend, cb, request,
1229
+ _this = this;
1230
+ cb = obj.on;
1231
+ request = obj;
1232
+ obj.type = obj.method;
1233
+ obj.cache = false;
1234
+ beforeSend = function(xhr) {
1235
+ var key, _results;
1236
+ if (obj.headers) {
1237
+ _results = [];
1238
+ for (key in obj.headers) {
1239
+ if (key.toLowerCase() === "content-type") {
1240
+ _results.push(obj.contentType = obj.headers[key]);
1241
+ } else if (key.toLowerCase() === "accept") {
1242
+ _results.push(obj.accepts = obj.headers[key]);
1243
+ } else {
1244
+ _results.push(xhr.setRequestHeader(key, obj.headers[key]));
1245
+ }
1246
+ }
1247
+ return _results;
1248
+ }
1249
+ };
1250
+ obj.beforeSend = beforeSend;
1251
+ obj.data = obj.body;
1252
+ obj.complete = function(response, textStatus, opts) {
1253
+ var headerArray, headers, i, out, _i, _j, _k, _ref, _ref1, _ref2, _ref3, _results, _results1;
1254
+ headers = {};
1255
+ headerArray = response.getAllResponseHeaders().split(":");
1256
+ for (i = _i = 0, _ref = headerArray.length / 2, _ref1 = 2.; _ref1 > 0 ? _i <= _ref : _i >= _ref; i = _i += _ref1) {
1257
+ headers[headerArray[i]] = headerArray[i + 1];
1258
+ }
1259
+ out = {
1260
+ headers: headers,
1261
+ url: request.url,
1262
+ method: request.method,
1263
+ status: response.status,
1264
+ data: response.responseText,
1265
+ headers: headers
1266
+ };
1267
+ if (_ref2 = response.status, __indexOf.call((function() {
1268
+ _results = [];
1269
+ for (_j = 200; _j <= 299; _j++){ _results.push(_j); }
1270
+ return _results;
1271
+ }).apply(this), _ref2) >= 0) {
1272
+ cb.response(out);
1273
+ }
1274
+ if ((_ref3 = response.status, __indexOf.call((function() {
1275
+ _results1 = [];
1276
+ for (_k = 400; _k <= 599; _k++){ _results1.push(_k); }
1277
+ return _results1;
1278
+ }).apply(this), _ref3) >= 0) || response.status === 0) {
1279
+ cb.error(out);
1280
+ }
1281
+ return cb.response(out);
1282
+ };
1283
+ $.support.cors = true;
1284
+ return $.ajax(obj);
1285
+ };
1286
+
1287
+ SwaggerHttp.prototype.isIE = function() {
1288
+ var isIE, nav, version;
1289
+ ({
1290
+ isIE: false
1291
+ });
1292
+ if (typeof navigator !== 'undefined' && navigator.userAgent) {
1293
+ nav = navigator.userAgent.toLowerCase();
1294
+ if (nav.indexOf('msie') !== -1) {
1295
+ version = parseInt(nav.split('msie')[1]);
1296
+ if (version <= 8) {
1297
+ isIE = true;
1298
+ }
1299
+ }
1300
+ }
1301
+ return isIE;
1302
+ };
1303
+
1304
+ return SwaggerHttp;
1305
+
1306
+ })();
1307
+
1308
+ SwaggerAuthorizations = (function() {
1309
+ SwaggerAuthorizations.prototype.authz = null;
1310
+
1311
+ function SwaggerAuthorizations() {
1312
+ this.authz = {};
1313
+ }
1314
+
1315
+ SwaggerAuthorizations.prototype.add = function(name, auth) {
1316
+ this.authz[name] = auth;
1317
+ return auth;
1318
+ };
1319
+
1320
+ SwaggerAuthorizations.prototype.remove = function(name) {
1321
+ return delete this.authz[name];
1322
+ };
1323
+
1324
+ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
1325
+ var key, result, status, value, _ref;
1326
+ status = null;
1327
+ _ref = this.authz;
1328
+ for (key in _ref) {
1329
+ value = _ref[key];
1330
+ result = value.apply(obj, authorizations);
1331
+ if (result === false) {
1332
+ status = false;
1333
+ }
1334
+ if (result === true) {
1335
+ status = true;
1336
+ }
1337
+ }
1338
+ return status;
1339
+ };
1340
+
1341
+ return SwaggerAuthorizations;
1342
+
1343
+ })();
1344
+
1345
+ ApiKeyAuthorization = (function() {
1346
+ ApiKeyAuthorization.prototype.type = null;
1347
+
1348
+ ApiKeyAuthorization.prototype.name = null;
1349
+
1350
+ ApiKeyAuthorization.prototype.value = null;
1351
+
1352
+ function ApiKeyAuthorization(name, value, type) {
1353
+ this.name = name;
1354
+ this.value = value;
1355
+ this.type = type;
1356
+ }
1357
+
1358
+ ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
1359
+ if (this.type === "query") {
1360
+ if (obj.url.indexOf('?') > 0) {
1361
+ obj.url = obj.url + "&" + this.name + "=" + this.value;
1362
+ } else {
1363
+ obj.url = obj.url + "?" + this.name + "=" + this.value;
1364
+ }
1365
+ return true;
1366
+ } else if (this.type === "header") {
1367
+ obj.headers[this.name] = this.value;
1368
+ return true;
1369
+ }
1370
+ };
1371
+
1372
+ return ApiKeyAuthorization;
1373
+
1374
+ })();
1375
+
1376
+ PasswordAuthorization = (function() {
1377
+ PasswordAuthorization._btoa = null;
1378
+
1379
+ PasswordAuthorization.prototype.name = null;
1380
+
1381
+ PasswordAuthorization.prototype.username = null;
1382
+
1383
+ PasswordAuthorization.prototype.password = null;
1384
+
1385
+ function PasswordAuthorization(name, username, password) {
1386
+ this.name = name;
1387
+ this.username = username;
1388
+ this.password = password;
1389
+ PasswordAuthorization._ensureBtoa();
1390
+ }
1391
+
1392
+ PasswordAuthorization.prototype.apply = function(obj, authorizations) {
1393
+ obj.headers["Authorization"] = "Basic " + PasswordAuthorization._btoa(this.username + ":" + this.password);
1394
+ return true;
1395
+ };
1396
+
1397
+ PasswordAuthorization._ensureBtoa = function() {
1398
+ if (typeof window !== 'undefined') {
1399
+ return this._btoa = btoa;
1400
+ } else {
1401
+ return this._btoa = require("btoa");
1402
+ }
1403
+ };
1404
+
1405
+ return PasswordAuthorization;
1406
+
1407
+ })();
1408
+
1409
+ this.SwaggerApi = SwaggerApi;
1410
+
1411
+ this.SwaggerResource = SwaggerResource;
1412
+
1413
+ this.SwaggerOperation = SwaggerOperation;
1414
+
1415
+ this.SwaggerRequest = SwaggerRequest;
1416
+
1417
+ this.SwaggerModelProperty = SwaggerModelProperty;
783
1418
 
784
- window.SwaggerResource = SwaggerResource;
1419
+ this.ApiKeyAuthorization = ApiKeyAuthorization;
785
1420
 
786
- window.SwaggerOperation = SwaggerOperation;
1421
+ this.PasswordAuthorization = PasswordAuthorization;
787
1422
 
788
- window.SwaggerRequest = SwaggerRequest;
1423
+ this.SwaggerHttp = SwaggerHttp;
789
1424
 
790
- window.SwaggerModelProperty = SwaggerModelProperty;
1425
+ this.authorizations = new SwaggerAuthorizations();
791
1426
 
792
- }).call(this);
1427
+ }).call(this);