swagger_ui_generator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +69 -0
  6. data/Rakefile +23 -0
  7. data/lib/generators/swagger_ui_generator/install/install_generator.rb +22 -0
  8. data/lib/generators/swagger_ui_generator/install/templates/public/api-docs.html.erb +73 -0
  9. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/css/highlight.default.css +135 -0
  10. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/css/screen.css +1070 -0
  11. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/backbone-min.js +38 -0
  12. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/handlebars-1.0.0.js +2278 -0
  13. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/highlight.7.3.pack.js +1 -0
  14. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/jquery-1.8.0.min.js +2 -0
  15. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/jquery.ba-bbq.min.js +18 -0
  16. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/jquery.slideto.min.js +1 -0
  17. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/jquery.wiggle.min.js +8 -0
  18. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/shred.bundle.js +2765 -0
  19. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/shred/content.js +193 -0
  20. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/swagger.js +1311 -0
  21. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/lib/underscore-min.js +32 -0
  22. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/swagger-ui.js +2129 -0
  23. data/lib/generators/swagger_ui_generator/install/templates/public/swagger/throbber.gif +0 -0
  24. data/lib/swagger_ui_generator.rb +5 -0
  25. data/lib/swagger_ui_generator/importer.rb +97 -0
  26. data/lib/swagger_ui_generator/version.rb +3 -0
  27. data/swagger_ui_generator.gemspec +28 -0
  28. data/test/lib/generators/swagger_ui_generator/install_generator_test.rb +73 -0
  29. data/test/test_helper.rb +19 -0
  30. data/vendor/swagger-ui/.gitignore +22 -0
  31. data/vendor/swagger-ui/.npmignore +7 -0
  32. data/vendor/swagger-ui/Cakefile +132 -0
  33. data/vendor/swagger-ui/README.md +110 -0
  34. data/vendor/swagger-ui/dist/css/highlight.default.css +135 -0
  35. data/vendor/swagger-ui/dist/css/screen.css +1070 -0
  36. data/vendor/swagger-ui/dist/images/logo_small.png +0 -0
  37. data/vendor/swagger-ui/dist/images/pet_store_api.png +0 -0
  38. data/vendor/swagger-ui/dist/images/throbber.gif +0 -0
  39. data/vendor/swagger-ui/dist/images/wordnik_api.png +0 -0
  40. data/vendor/swagger-ui/dist/index.html +78 -0
  41. data/vendor/swagger-ui/dist/lib/backbone-min.js +38 -0
  42. data/vendor/swagger-ui/dist/lib/handlebars-1.0.0.js +2278 -0
  43. data/vendor/swagger-ui/dist/lib/highlight.7.3.pack.js +1 -0
  44. data/vendor/swagger-ui/dist/lib/jquery-1.8.0.min.js +2 -0
  45. data/vendor/swagger-ui/dist/lib/jquery.ba-bbq.min.js +18 -0
  46. data/vendor/swagger-ui/dist/lib/jquery.slideto.min.js +1 -0
  47. data/vendor/swagger-ui/dist/lib/jquery.wiggle.min.js +8 -0
  48. data/vendor/swagger-ui/dist/lib/shred.bundle.js +2765 -0
  49. data/vendor/swagger-ui/dist/lib/shred/content.js +193 -0
  50. data/vendor/swagger-ui/dist/lib/swagger.js +1311 -0
  51. data/vendor/swagger-ui/dist/lib/underscore-min.js +32 -0
  52. data/vendor/swagger-ui/dist/swagger-ui.js +2129 -0
  53. data/vendor/swagger-ui/dist/swagger-ui.min.js +1 -0
  54. data/vendor/swagger-ui/lib/backbone-min.js +38 -0
  55. data/vendor/swagger-ui/lib/handlebars-1.0.0.js +2278 -0
  56. data/vendor/swagger-ui/lib/highlight.7.3.pack.js +1 -0
  57. data/vendor/swagger-ui/lib/jquery-1.8.0.min.js +2 -0
  58. data/vendor/swagger-ui/lib/jquery.ba-bbq.min.js +18 -0
  59. data/vendor/swagger-ui/lib/jquery.slideto.min.js +1 -0
  60. data/vendor/swagger-ui/lib/jquery.wiggle.min.js +8 -0
  61. data/vendor/swagger-ui/lib/shred.bundle.js +2765 -0
  62. data/vendor/swagger-ui/lib/shred/content.js +193 -0
  63. data/vendor/swagger-ui/lib/swagger.js +1311 -0
  64. data/vendor/swagger-ui/lib/underscore-min.js +32 -0
  65. data/vendor/swagger-ui/package.json +26 -0
  66. data/vendor/swagger-ui/src/main/coffeescript/SwaggerUi.coffee +101 -0
  67. data/vendor/swagger-ui/src/main/coffeescript/view/ContentTypeView.coffee +14 -0
  68. data/vendor/swagger-ui/src/main/coffeescript/view/HeaderView.coffee +37 -0
  69. data/vendor/swagger-ui/src/main/coffeescript/view/MainView.coffee +18 -0
  70. data/vendor/swagger-ui/src/main/coffeescript/view/OperationView.coffee +318 -0
  71. data/vendor/swagger-ui/src/main/coffeescript/view/ParameterContentTypeView.coffee +14 -0
  72. data/vendor/swagger-ui/src/main/coffeescript/view/ParameterView.coffee +57 -0
  73. data/vendor/swagger-ui/src/main/coffeescript/view/ResourceView.coffee +21 -0
  74. data/vendor/swagger-ui/src/main/coffeescript/view/ResponseContentTypeView.coffee +14 -0
  75. data/vendor/swagger-ui/src/main/coffeescript/view/SignatureView.coffee +51 -0
  76. data/vendor/swagger-ui/src/main/coffeescript/view/StatusCodeView.coffee +11 -0
  77. data/vendor/swagger-ui/src/main/html/css/highlight.default.css +135 -0
  78. data/vendor/swagger-ui/src/main/html/css/screen.css +1070 -0
  79. data/vendor/swagger-ui/src/main/html/images/logo_small.png +0 -0
  80. data/vendor/swagger-ui/src/main/html/images/pet_store_api.png +0 -0
  81. data/vendor/swagger-ui/src/main/html/images/throbber.gif +0 -0
  82. data/vendor/swagger-ui/src/main/html/images/wordnik_api.png +0 -0
  83. data/vendor/swagger-ui/src/main/html/index.html +78 -0
  84. data/vendor/swagger-ui/src/main/javascript/doc.js +184 -0
  85. data/vendor/swagger-ui/src/main/less/reset.less +50 -0
  86. data/vendor/swagger-ui/src/main/less/screen.less +67 -0
  87. data/vendor/swagger-ui/src/main/less/specs.less +1004 -0
  88. data/vendor/swagger-ui/src/main/template/content_type.handlebars +10 -0
  89. data/vendor/swagger-ui/src/main/template/main.handlebars +22 -0
  90. data/vendor/swagger-ui/src/main/template/operation.handlebars +85 -0
  91. data/vendor/swagger-ui/src/main/template/param.handlebars +30 -0
  92. data/vendor/swagger-ui/src/main/template/param_list.handlebars +25 -0
  93. data/vendor/swagger-ui/src/main/template/param_readonly.handlebars +15 -0
  94. data/vendor/swagger-ui/src/main/template/param_readonly_required.handlebars +15 -0
  95. data/vendor/swagger-ui/src/main/template/param_required.handlebars +31 -0
  96. data/vendor/swagger-ui/src/main/template/parameter_content_type.handlebars +10 -0
  97. data/vendor/swagger-ui/src/main/template/resource.handlebars +27 -0
  98. data/vendor/swagger-ui/src/main/template/response_content_type.handlebars +10 -0
  99. data/vendor/swagger-ui/src/main/template/signature.handlebars +18 -0
  100. data/vendor/swagger-ui/src/main/template/status_code.handlebars +2 -0
  101. data/vendor/swagger-ui/src/test/spec.html +26 -0
  102. data/vendor/swagger-ui/src/test/swagger-ui-spec.coffee +49 -0
  103. data/vendor/swagger-ui/swagger-ui.json +20 -0
  104. metadata +240 -0
@@ -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,1311 @@
1
+ // swagger.js
2
+ // version 2.0.14
3
+
4
+ var __bind = function(fn, me){
5
+ return function(){
6
+ return fn.apply(me, arguments);
7
+ };
8
+ };
9
+
10
+ log = function(){
11
+ log.history = log.history || [];
12
+ log.history.push(arguments);
13
+ if(this.console){
14
+ console.log( Array.prototype.slice.call(arguments) );
15
+ }
16
+ };
17
+
18
+ var SwaggerApi = function(url, options) {
19
+ this.url = null;
20
+ this.debug = false;
21
+ this.basePath = null;
22
+ this.authorizations = null;
23
+ this.authorizationScheme = null;
24
+ this.info = null;
25
+
26
+ options = (options||{});
27
+ if (url)
28
+ if (url.url)
29
+ options = url;
30
+ else
31
+ this.url = url;
32
+ else
33
+ options = url;
34
+
35
+ if (options.url != null)
36
+ this.url = options.url;
37
+
38
+ if (options.success != null)
39
+ this.success = options.success;
40
+
41
+ this.failure = options.failure != null ? options.failure : function() {};
42
+ this.progress = options.progress != null ? options.progress : function() {};
43
+ if (options.success != null)
44
+ this.build();
45
+ }
46
+
47
+ SwaggerApi.prototype.build = function() {
48
+ var _this = this;
49
+ this.progress('fetching resource list: ' + this.url);
50
+ var obj = {
51
+ useJQuery: this.useJQuery,
52
+ url: this.url,
53
+ method: "get",
54
+ headers: {
55
+ accept: "application/json"
56
+ },
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(resp) {
70
+ var responseObj = resp.obj;
71
+ _this.swaggerVersion = responseObj.swaggerVersion;
72
+ if (_this.swaggerVersion === "1.2") {
73
+ return _this.buildFromSpec(responseObj);
74
+ } else {
75
+ return _this.buildFrom1_1Spec(responseObj);
76
+ }
77
+ }
78
+ }
79
+ };
80
+ var e = (typeof window !== 'undefined' ? window : exports);
81
+ e.authorizations.apply(obj);
82
+ new SwaggerHttp().execute(obj);
83
+ return this;
84
+ };
85
+
86
+ SwaggerApi.prototype.buildFromSpec = function(response) {
87
+ if (response.apiVersion != null) {
88
+ this.apiVersion = response.apiVersion;
89
+ }
90
+ this.apis = {};
91
+ this.apisArray = [];
92
+ this.produces = response.produces;
93
+ this.authSchemes = response.authorizations;
94
+ if (response.info != null) {
95
+ this.info = response.info;
96
+ }
97
+ var isApi = false;
98
+ for (var i = 0; i < response.apis.length; i++) {
99
+ var api = response.apis[i];
100
+ if (api.operations) {
101
+ for (var j = 0; j < api.operations.length; j++) {
102
+ operation = api.operations[j];
103
+ isApi = true;
104
+ }
105
+ }
106
+ }
107
+ if (response.basePath) {
108
+ this.basePath = response.basePath;
109
+ } else if (this.url.indexOf('?') > 0) {
110
+ this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
111
+ } else {
112
+ this.basePath = this.url;
113
+ }
114
+ if (isApi) {
115
+ var newName = response.resourcePath.replace(/\//g, '');
116
+ this.resourcePath = response.resourcePath;
117
+ res = new SwaggerResource(response, this);
118
+ this.apis[newName] = res;
119
+ this.apisArray.push(res);
120
+ } else {
121
+ for (var k = 0; k < response.apis.length; k++) {
122
+ var resource = response.apis[k];
123
+ res = new SwaggerResource(resource, this);
124
+ this.apis[res.name] = res;
125
+ this.apisArray.push(res);
126
+ }
127
+ }
128
+ if (this.success) {
129
+ this.success();
130
+ }
131
+ return this;
132
+ };
133
+
134
+ SwaggerApi.prototype.buildFrom1_1Spec = function(response) {
135
+ log("This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info");
136
+ if (response.apiVersion != null)
137
+ this.apiVersion = response.apiVersion;
138
+ this.apis = {};
139
+ this.apisArray = [];
140
+ this.produces = response.produces;
141
+ if (response.info != null) {
142
+ this.info = response.info;
143
+ }
144
+ var isApi = false;
145
+ for (var i = 0; i < response.apis.length; i++) {
146
+ var api = response.apis[i];
147
+ if (api.operations) {
148
+ for (var j = 0; j < api.operations.length; j++) {
149
+ operation = api.operations[j];
150
+ isApi = true;
151
+ }
152
+ }
153
+ }
154
+ if (response.basePath) {
155
+ this.basePath = response.basePath;
156
+ } else if (this.url.indexOf('?') > 0) {
157
+ this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
158
+ } else {
159
+ this.basePath = this.url;
160
+ }
161
+ if (isApi) {
162
+ var newName = response.resourcePath.replace(/\//g, '');
163
+ this.resourcePath = response.resourcePath;
164
+ var res = new SwaggerResource(response, this);
165
+ this.apis[newName] = res;
166
+ this.apisArray.push(res);
167
+ } else {
168
+ for (k = 0; k < response.apis.length; k++) {
169
+ resource = response.apis[k];
170
+ res = new SwaggerResource(resource, this);
171
+ this.apis[res.name] = res;
172
+ this.apisArray.push(res);
173
+ }
174
+ }
175
+ if (this.success) {
176
+ this.success();
177
+ }
178
+ return this;
179
+ };
180
+
181
+ SwaggerApi.prototype.selfReflect = function() {
182
+ var resource, resource_name, _ref;
183
+ if (this.apis == null) {
184
+ return false;
185
+ }
186
+ _ref = this.apis;
187
+ for (resource_name in _ref) {
188
+ resource = _ref[resource_name];
189
+ if (resource.ready == null) {
190
+ return false;
191
+ }
192
+ }
193
+ this.setConsolidatedModels();
194
+ this.ready = true;
195
+ if (this.success != null) {
196
+ return this.success();
197
+ }
198
+ };
199
+
200
+ SwaggerApi.prototype.fail = function(message) {
201
+ this.failure(message);
202
+ throw message;
203
+ };
204
+
205
+ SwaggerApi.prototype.setConsolidatedModels = function() {
206
+ var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results;
207
+ this.modelsArray = [];
208
+ this.models = {};
209
+ _ref = this.apis;
210
+ for (resource_name in _ref) {
211
+ resource = _ref[resource_name];
212
+ for (modelName in resource.models) {
213
+ if (this.models[modelName] == null) {
214
+ this.models[modelName] = resource.models[modelName];
215
+ this.modelsArray.push(resource.models[modelName]);
216
+ }
217
+ }
218
+ }
219
+ _ref1 = this.modelsArray;
220
+ _results = [];
221
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
222
+ model = _ref1[_i];
223
+ _results.push(model.setReferencedModels(this.models));
224
+ }
225
+ return _results;
226
+ };
227
+
228
+ SwaggerApi.prototype.help = function() {
229
+ var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2;
230
+ _ref = this.apis;
231
+ for (resource_name in _ref) {
232
+ resource = _ref[resource_name];
233
+ log(resource_name);
234
+ _ref1 = resource.operations;
235
+ for (operation_name in _ref1) {
236
+ operation = _ref1[operation_name];
237
+ log(" " + operation.nickname);
238
+ _ref2 = operation.parameters;
239
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
240
+ parameter = _ref2[_i];
241
+ log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
242
+ }
243
+ }
244
+ }
245
+ return this;
246
+ };
247
+
248
+ var SwaggerResource = function(resourceObj, api) {
249
+ var _this = this;
250
+ this.api = api;
251
+ this.api = this.api;
252
+ produces = [];
253
+ consumes = [];
254
+ this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
255
+ this.description = resourceObj.description;
256
+
257
+ var parts = this.path.split("/");
258
+ this.name = parts[parts.length - 1].replace('.{format}', '');
259
+ this.basePath = this.api.basePath;
260
+ this.operations = {};
261
+ this.operationsArray = [];
262
+ this.modelsArray = [];
263
+ this.models = {};
264
+ this.rawModels = {};
265
+ this.useJQuery = (typeof api.useJQuery !== 'undefined' ? api.useJQuery : null);
266
+
267
+ if ((resourceObj.apis != null) && (this.api.resourcePath != null)) {
268
+ this.addApiDeclaration(resourceObj);
269
+ } else {
270
+ if (this.path == null) {
271
+ this.api.fail("SwaggerResources must have a path.");
272
+ }
273
+ if (this.path.substring(0, 4) === 'http') {
274
+ this.url = this.path.replace('{format}', 'json');
275
+ } else {
276
+ this.url = this.api.basePath + this.path.replace('{format}', 'json');
277
+ }
278
+ this.api.progress('fetching resource ' + this.name + ': ' + this.url);
279
+ obj = {
280
+ url: this.url,
281
+ method: "get",
282
+ useJQuery: this.useJQuery,
283
+ headers: {
284
+ accept: "application/json"
285
+ },
286
+ on: {
287
+ response: function(response) {
288
+ var responseObj = response.obj;
289
+ return _this.addApiDeclaration(responseObj);
290
+ },
291
+ error: function(response) {
292
+ return _this.api.fail("Unable to read api '" +
293
+ _this.name + "' from path " + _this.url + " (server returned " + response.statusText + ")");
294
+ }
295
+ }
296
+ };
297
+ var e = typeof window !== 'undefined' ? window : exports;
298
+ e.authorizations.apply(obj);
299
+ new SwaggerHttp().execute(obj);
300
+ }
301
+ }
302
+
303
+ SwaggerResource.prototype.getAbsoluteBasePath = function(relativeBasePath) {
304
+ var parts, pos, url;
305
+ url = this.api.basePath;
306
+ pos = url.lastIndexOf(relativeBasePath);
307
+ if (pos === -1) {
308
+ parts = url.split("/");
309
+ url = parts[0] + "//" + parts[2];
310
+ if (relativeBasePath.indexOf("/") === 0) {
311
+ return url + relativeBasePath;
312
+ } else {
313
+ return url + "/" + relativeBasePath;
314
+ }
315
+ } else if (relativeBasePath === "/") {
316
+ return url.substring(0, pos);
317
+ } else {
318
+ return url.substring(0, pos) + relativeBasePath;
319
+ }
320
+ };
321
+
322
+ SwaggerResource.prototype.addApiDeclaration = function(response) {
323
+ if (response.produces != null)
324
+ this.produces = response.produces;
325
+ if (response.consumes != null)
326
+ this.consumes = response.consumes;
327
+ if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0)
328
+ this.basePath = response.basePath.indexOf("http") === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath;
329
+
330
+ this.addModels(response.models);
331
+ if (response.apis) {
332
+ for (var i = 0 ; i < response.apis.length; i++) {
333
+ var endpoint = response.apis[i];
334
+ this.addOperations(endpoint.path, endpoint.operations, response.consumes, response.produces);
335
+ }
336
+ }
337
+ this.api[this.name] = this;
338
+ this.ready = true;
339
+ return this.api.selfReflect();
340
+ };
341
+
342
+ SwaggerResource.prototype.addModels = function(models) {
343
+ if (models != null) {
344
+ for (modelName in models) {
345
+ if (this.models[modelName] == null) {
346
+ var swaggerModel = new SwaggerModel(modelName, models[modelName]);
347
+ this.modelsArray.push(swaggerModel);
348
+ this.models[modelName] = swaggerModel;
349
+ this.rawModels[modelName] = models[modelName];
350
+ }
351
+ }
352
+ var output = [];
353
+ for (var i = 0; i < this.modelsArray.length; i++) {
354
+ model = this.modelsArray[i];
355
+ output.push(model.setReferencedModels(this.models));
356
+ }
357
+ return output;
358
+ }
359
+ };
360
+
361
+ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes, produces) {
362
+ if (ops) {
363
+ output = [];
364
+ for (var i = 0; i < ops.length; i++) {
365
+ o = ops[i];
366
+ consumes = this.consumes;
367
+ produces = this.produces;
368
+ if (o.consumes != null)
369
+ consumes = o.consumes;
370
+ else
371
+ consumes = this.consumes;
372
+
373
+ if (o.produces != null)
374
+ produces = o.produces;
375
+ else
376
+ produces = this.produces;
377
+ type = (o.type||o.responseClass);
378
+
379
+ if (type === "array") {
380
+ ref = null;
381
+ if (o.items)
382
+ ref = o.items["type"] || o.items["$ref"];
383
+ type = "array[" + ref + "]";
384
+ }
385
+ responseMessages = o.responseMessages;
386
+ method = o.method;
387
+ if (o.httpMethod) {
388
+ method = o.httpMethod;
389
+ }
390
+ if (o.supportedContentTypes) {
391
+ consumes = o.supportedContentTypes;
392
+ }
393
+ if (o.errorResponses) {
394
+ responseMessages = o.errorResponses;
395
+ for (j = 0; j < responseMessages.length; j++) {
396
+ r = responseMessages[j];
397
+ r.message = r.reason;
398
+ r.reason = null;
399
+ }
400
+ }
401
+ o.nickname = this.sanitize(o.nickname);
402
+ op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, type, responseMessages, this, consumes, produces, o.authorizations);
403
+ this.operations[op.nickname] = op;
404
+ output.push(this.operationsArray.push(op));
405
+ }
406
+ return output;
407
+ }
408
+ };
409
+
410
+ SwaggerResource.prototype.sanitize = function(nickname) {
411
+ var op;
412
+ op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|./?,\\'""-]/g, '_');
413
+ //'
414
+ op = op.replace(/((_){2,})/g, '_');
415
+ op = op.replace(/^(_)*/g, '');
416
+ op = op.replace(/([_])*$/g, '');
417
+ return op;
418
+ };
419
+
420
+ SwaggerResource.prototype.help = function() {
421
+ var op = this.operations;
422
+ var output = [];
423
+ for (operation_name in op) {
424
+ operation = op[operation_name];
425
+ var msg = " " + operation.nickname;
426
+ for (var i = 0; i < operation.parameters; i++) {
427
+ parameter = operation.parameters[i];
428
+ msg.concat(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
429
+ }
430
+ output.push(msg);
431
+ }
432
+ return output;
433
+ };
434
+
435
+ var SwaggerModel = function(modelName, obj) {
436
+ this.name = obj.id != null ? obj.id : modelName;
437
+ this.properties = [];
438
+ for (propertyName in obj.properties) {
439
+ if (obj.required != null) {
440
+ for (value in obj.required) {
441
+ if (propertyName === obj.required[value]) {
442
+ obj.properties[propertyName].required = true;
443
+ }
444
+ }
445
+ }
446
+ prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]);
447
+ this.properties.push(prop);
448
+ }
449
+ }
450
+
451
+ SwaggerModel.prototype.setReferencedModels = function(allModels) {
452
+ var results = [];
453
+ for (var i = 0; i < this.properties.length; i++) {
454
+ var property = this.properties[i];
455
+ var type = property.type || property.dataType;
456
+ if (allModels[type] != null)
457
+ results.push(property.refModel = allModels[type]);
458
+ else if ((property.refDataType != null) && (allModels[property.refDataType] != null))
459
+ results.push(property.refModel = allModels[property.refDataType]);
460
+ else
461
+ results.push(void 0);
462
+ }
463
+ return results;
464
+ };
465
+
466
+ SwaggerModel.prototype.getMockSignature = function(modelsToIgnore) {
467
+ var propertiesStr = [];
468
+ for (var i = 0; i < this.properties.length; i++) {
469
+ prop = this.properties[i];
470
+ propertiesStr.push(prop.toString());
471
+ }
472
+
473
+ var strong = '<span class="strong">';
474
+ var stronger = '<span class="stronger">';
475
+ var strongClose = '</span>';
476
+ var classOpen = strong + this.name + ' {' + strongClose;
477
+ var classClose = strong + '}' + strongClose;
478
+ var returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;
479
+ if (!modelsToIgnore)
480
+ modelsToIgnore = [];
481
+ modelsToIgnore.push(this);
482
+
483
+ for (var i = 0; i < this.properties.length; i++) {
484
+ prop = this.properties[i];
485
+ if ((prop.refModel != null) && modelsToIgnore.indexOf(prop.refModel) === -1) {
486
+ returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
487
+ }
488
+ }
489
+ return returnVal;
490
+ };
491
+
492
+ SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) {
493
+ var result = {};
494
+ var modelsToIgnore = (modelsToIgnore||[])
495
+ modelsToIgnore.push(this.name);
496
+ for (var i = 0; i < this.properties.length; i++) {
497
+ prop = this.properties[i];
498
+ result[prop.name] = prop.getSampleValue(modelsToIgnore);
499
+ }
500
+ modelsToIgnore.pop(this.name);
501
+ return result;
502
+ };
503
+
504
+ var SwaggerModelProperty = function(name, obj) {
505
+ this.name = name;
506
+ this.dataType = obj.type || obj.dataType || obj["$ref"];
507
+ this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
508
+ this.descr = obj.description;
509
+ this.required = obj.required;
510
+ if (obj.items != null) {
511
+ if (obj.items.type != null) {
512
+ this.refDataType = obj.items.type;
513
+ }
514
+ if (obj.items.$ref != null) {
515
+ this.refDataType = obj.items.$ref;
516
+ }
517
+ }
518
+ this.dataTypeWithRef = this.refDataType != null ? (this.dataType + '[' + this.refDataType + ']') : this.dataType;
519
+ if (obj.allowableValues != null) {
520
+ this.valueType = obj.allowableValues.valueType;
521
+ this.values = obj.allowableValues.values;
522
+ if (this.values != null) {
523
+ this.valuesString = "'" + this.values.join("' or '") + "'";
524
+ }
525
+ }
526
+ if (obj["enum"] != null) {
527
+ this.valueType = "string";
528
+ this.values = obj["enum"];
529
+ if (this.values != null) {
530
+ this.valueString = "'" + this.values.join("' or '") + "'";
531
+ }
532
+ }
533
+ }
534
+
535
+ SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
536
+ var result;
537
+ if ((this.refModel != null) && (modelsToIgnore[this.refModel.name] === undefined)) {
538
+ result = this.refModel.createJSONSample(modelsToIgnore);
539
+ } else {
540
+ if (this.isCollection) {
541
+ result = this.toSampleValue(this.refDataType);
542
+ } else {
543
+ result = this.toSampleValue(this.dataType);
544
+ }
545
+ }
546
+ if (this.isCollection) {
547
+ return [result];
548
+ } else {
549
+ return result;
550
+ }
551
+ };
552
+
553
+ SwaggerModelProperty.prototype.toSampleValue = function(value) {
554
+ var result;
555
+ if (value === "integer") {
556
+ result = 0;
557
+ } else if (value === "boolean") {
558
+ result = false;
559
+ } else if (value === "double" || value === "number") {
560
+ result = 0.0;
561
+ } else if (value === "string") {
562
+ result = "";
563
+ } else {
564
+ result = value;
565
+ }
566
+ return result;
567
+ };
568
+
569
+ SwaggerModelProperty.prototype.toString = function() {
570
+ var req = this.required ? 'propReq' : 'propOpt';
571
+ var str = '<span class="propName ' + req + '">' + this.name + '</span> (<span class="propType">' + this.dataTypeWithRef + '</span>';
572
+ if (!this.required) {
573
+ str += ', <span class="propOptKey">optional</span>';
574
+ }
575
+ str += ')';
576
+ if (this.values != null) {
577
+ str += " = <span class='propVals'>['" + this.values.join("' or '") + "']</span>";
578
+ }
579
+ if (this.descr != null) {
580
+ str += ': <span class="propDesc">' + this.descr + '</span>';
581
+ }
582
+ return str;
583
+ };
584
+
585
+ var SwaggerOperation = function(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces, authorizations) {
586
+ var _this = this;
587
+
588
+ var errors = [];
589
+ this.nickname = (nickname||errors.push("SwaggerOperations must have a nickname."));
590
+ this.path = (path||errors.push("SwaggerOperation " + nickname + " is missing path."));
591
+ this.method = (method||errors.push("SwaggerOperation " + nickname + " is missing method."));
592
+ this.parameters = parameters != null ? parameters : [];
593
+ this.summary = summary;
594
+ this.notes = notes;
595
+ this.type = type;
596
+ this.responseMessages = (responseMessages||[]);
597
+ this.resource = (resource||errors.push("Resource is required"));
598
+ this.consumes = consumes;
599
+ this.produces = produces;
600
+ this.authorizations = authorizations;
601
+ this["do"] = __bind(this["do"], this);
602
+
603
+ if (errors.length > 0)
604
+ this.resource.api.fail(errors);
605
+
606
+ this.path = this.path.replace('{format}', 'json');
607
+ this.method = this.method.toLowerCase();
608
+ this.isGetMethod = this.method === "get";
609
+
610
+ this.resourceName = this.resource.name;
611
+ if(typeof this.type !== 'undefined' && this.type === 'void')
612
+ this.type = null;
613
+ else {
614
+ this.responseClassSignature = this.getSignature(this.type, this.resource.models);
615
+ this.responseSampleJSON = this.getSampleJSON(this.type, this.resource.models);
616
+ }
617
+
618
+ for(var i = 0; i < this.parameters.length; i ++) {
619
+ var param = this.parameters[i];
620
+ // might take this away
621
+ param.name = param.name || param.type || param.dataType;
622
+
623
+ // for 1.1 compatibility
624
+ var type = param.type || param.dataType;
625
+
626
+ if(type.toLowerCase() === 'boolean') {
627
+ param.allowableValues = {};
628
+ param.allowableValues.values = ["true", "false"];
629
+ }
630
+ param.signature = this.getSignature(type, this.resource.models);
631
+ param.sampleJSON = this.getSampleJSON(type, this.resource.models);
632
+
633
+ var enumValue = param["enum"];
634
+ if(enumValue != null) {
635
+ param.isList = true;
636
+ param.allowableValues = {};
637
+ param.allowableValues.descriptiveValues = [];
638
+
639
+ for(j = 0; j < enumValue.length; j++) {
640
+ var v = enumValue[j];
641
+ if(param.defaultValue != null) {
642
+ param.allowableValues.descriptiveValues.push ({
643
+ value: String(v),
644
+ isDefault: (v === param.defaultValue)
645
+ });
646
+ }
647
+ else {
648
+ param.allowableValues.descriptiveValues.push ({
649
+ value: String(v),
650
+ isDefault: false
651
+ });
652
+ }
653
+ }
654
+ }
655
+ if(param.allowableValues != null) {
656
+ if(param.allowableValues.valueType === "RANGE")
657
+ param.isRange = true;
658
+ else
659
+ param.isList = true;
660
+ if(param.allowableValues != null) {
661
+ param.allowableValues.descriptiveValues = [];
662
+ for(j = 0; j < param.allowableValues.values; j++){
663
+ var v = param.allowableValues.values[j];
664
+ if(param.defaultValue != null) {
665
+ param.allowableValues.descriptiveValues.push ({
666
+ value: String(v),
667
+ isDefault: (v === param.defaultValue)
668
+ });
669
+ }
670
+ else {
671
+ param.allowableValues.descriptiveValues.push ({
672
+ value: String(v),
673
+ isDefault: false
674
+ });
675
+ }
676
+ }
677
+ }
678
+ }
679
+ }
680
+ this.resource[this.nickname] = function(args, callback, error) {
681
+ return _this["do"](args, callback, error);
682
+ };
683
+ this.resource[this.nickname].help = function() {
684
+ return _this.help();
685
+ };
686
+ }
687
+
688
+ SwaggerOperation.prototype.isListType = function(type) {
689
+ if (type.indexOf('[') >= 0) {
690
+ return type.substring(type.indexOf('[') + 1, type.indexOf(']'));
691
+ } else {
692
+ return void 0;
693
+ }
694
+ };
695
+
696
+ SwaggerOperation.prototype.getSignature = function(type, models) {
697
+ var isPrimitive, listType;
698
+ listType = this.isListType(type);
699
+ isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
700
+ if (isPrimitive) {
701
+ return type;
702
+ } else {
703
+ if (listType != null) {
704
+ return models[listType].getMockSignature();
705
+ } else {
706
+ return models[type].getMockSignature();
707
+ }
708
+ }
709
+ };
710
+
711
+ SwaggerOperation.prototype.getSampleJSON = function(type, models) {
712
+ var isPrimitive, listType, val;
713
+ listType = this.isListType(type);
714
+ isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
715
+ val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample());
716
+ if (val) {
717
+ val = listType ? [val] : val;
718
+ return JSON.stringify(val, null, 2);
719
+ }
720
+ };
721
+
722
+ SwaggerOperation.prototype["do"] = function(args, opts, callback, error) {
723
+ var key, param, params, possibleParams, req, requestContentType, responseContentType, value, _i, _len, _ref;
724
+ if (args == null) {
725
+ args = {};
726
+ }
727
+ if (opts == null) {
728
+ opts = {};
729
+ }
730
+ requestContentType = null;
731
+ responseContentType = null;
732
+ if ((typeof args) === "function") {
733
+ error = opts;
734
+ callback = args;
735
+ args = {};
736
+ }
737
+ if ((typeof opts) === "function") {
738
+ error = callback;
739
+ callback = opts;
740
+ }
741
+ if (error == null) {
742
+ error = function(xhr, textStatus, error) {
743
+ return log(xhr, textStatus, error);
744
+ };
745
+ }
746
+ if (callback == null) {
747
+ callback = function(response) {
748
+ var content;
749
+ content = null;
750
+ if (response != null) {
751
+ content = response.data;
752
+ } else {
753
+ content = "no data";
754
+ }
755
+ return log("default callback: " + content);
756
+ };
757
+ }
758
+ params = {};
759
+ params.headers = [];
760
+ if (args.headers != null) {
761
+ params.headers = args.headers;
762
+ delete args.headers;
763
+ }
764
+
765
+ var possibleParams = [];
766
+ for(var i = 0; i < this.parameters.length; i++) {
767
+ var param = this.parameters[i];
768
+ if(param.paramType === 'header') {
769
+ if(args[param.name])
770
+ params.headers[param.name] = args[param.name];
771
+ }
772
+ else if(param.paramType === 'form' || param.paramType.toLowerCase() === 'file')
773
+ possibleParams.push(param);
774
+ }
775
+
776
+ if (args.body != null) {
777
+ params.body = args.body;
778
+ delete args.body;
779
+ }
780
+
781
+ if (possibleParams) {
782
+ for (key in possibleParams) {
783
+ value = possibleParams[key];
784
+ if (args[value.name]) {
785
+ params[value.name] = args[value.name];
786
+ }
787
+ }
788
+ }
789
+
790
+ req = new SwaggerRequest(this.method, this.urlify(args), params, opts, callback, error, this);
791
+ if (opts.mock != null) {
792
+ return req;
793
+ } else {
794
+ return true;
795
+ }
796
+ };
797
+
798
+ SwaggerOperation.prototype.pathJson = function() {
799
+ return this.path.replace("{format}", "json");
800
+ };
801
+
802
+ SwaggerOperation.prototype.pathXml = function() {
803
+ return this.path.replace("{format}", "xml");
804
+ };
805
+
806
+ SwaggerOperation.prototype.urlify = function(args) {
807
+ var url = this.resource.basePath + this.pathJson();
808
+ var params = this.parameters;
809
+ for(var i = 0; i < params.length; i ++){
810
+ var param = params[i];
811
+ if (param.paramType === 'path') {
812
+ if(args[param.name]) {
813
+ // apply path params and remove from args
814
+ var reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
815
+ url = url.replace(reg, encodeURIComponent(args[param.name]));
816
+ delete args[param.name];
817
+ }
818
+ else
819
+ throw "" + param.name + " is a required path param.";
820
+ }
821
+ }
822
+
823
+ var queryParams = "";
824
+ for(var i = 0; i < params.length; i ++){
825
+ var param = params[i];
826
+ if(param.paramType === 'query') {
827
+ if(queryParams !== '')
828
+ queryParams += "&";
829
+ queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]);
830
+ }
831
+ }
832
+ if ((queryParams != null) && queryParams.length > 0)
833
+ url += '?' + queryParams;
834
+ return url;
835
+ };
836
+
837
+ SwaggerOperation.prototype.supportHeaderParams = function() {
838
+ return this.resource.api.supportHeaderParams;
839
+ };
840
+
841
+ SwaggerOperation.prototype.supportedSubmitMethods = function() {
842
+ return this.resource.api.supportedSubmitMethods;
843
+ };
844
+
845
+ SwaggerOperation.prototype.getQueryParams = function(args) {
846
+ return this.getMatchingParams(['query'], args);
847
+ };
848
+
849
+ SwaggerOperation.prototype.getHeaderParams = function(args) {
850
+ return this.getMatchingParams(['header'], args);
851
+ };
852
+
853
+ SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args) {
854
+ var matchingParams = {};
855
+ var params = this.parameters;
856
+ for (var i = 0; i < params.length; i++) {
857
+ param = params[i];
858
+ if (args && args[param.name])
859
+ matchingParams[param.name] = args[param.name];
860
+ }
861
+ var headers = this.resource.api.headers;
862
+ for (name in headers) {
863
+ var value = headers[name];
864
+ matchingParams[name] = value;
865
+ }
866
+ return matchingParams;
867
+ };
868
+
869
+ SwaggerOperation.prototype.help = function() {
870
+ var msg = "";
871
+ var params = this.parameters;
872
+ for (var i = 0; i < params.length; i++) {
873
+ var param = params[i];
874
+ if (msg !== "")
875
+ msg += "\n";
876
+ msg += "* " + param.name + (param.required ? ' (required)' : '') + " - " + param.description;
877
+ }
878
+ return msg;
879
+ };
880
+
881
+ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCallback, operation, execution) {
882
+ var _this = this;
883
+ var errors = [];
884
+ this.useJQuery = (typeof operation.useJQuery !== 'undefined' ? operation.useJQuery : null);
885
+ this.type = (type||errors.push("SwaggerRequest type is required (get/post/put/delete/patch/options)."));
886
+ this.url = (url||errors.push("SwaggerRequest url is required."));
887
+ this.params = params;
888
+ this.opts = opts;
889
+ this.successCallback = (successCallback||errors.push("SwaggerRequest successCallback is required."));
890
+ this.errorCallback = (errorCallback||errors.push("SwaggerRequest error callback is required."));
891
+ this.operation = (operation||errors.push("SwaggerRequest operation is required."));
892
+ this.execution = execution;
893
+ this.headers = (params.headers||{});
894
+
895
+ if(errors.length > 0) {
896
+ throw errors;
897
+ }
898
+
899
+ this.type = this.type.toUpperCase();
900
+
901
+ var myHeaders = {};
902
+ var body = params.body;
903
+ var parent = params["parent"];
904
+ var requestContentType = "application/json";
905
+
906
+ var formParams = [];
907
+ var fileParams = [];
908
+ var params = this.operation.parameters;
909
+
910
+
911
+ for(var i = 0; i < params.length; i++) {
912
+ var param = params[i];
913
+ if(param.paramType === "form")
914
+ formParams.push(param);
915
+ else if(param.paramType === "file")
916
+ fileParams.push(param);
917
+ }
918
+
919
+
920
+ if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) {
921
+ if (this.opts.requestContentType) {
922
+ requestContentType = this.opts.requestContentType;
923
+ }
924
+ } else {
925
+ // if any form params, content type must be set
926
+ if(formParams.length > 0) {
927
+ if(fileParams.length > 0)
928
+ requestContentType = "multipart/form-data";
929
+ else
930
+ requestContentType = "application/x-www-form-urlencoded";
931
+ }
932
+ else if (this.type != "DELETE")
933
+ requestContentType = null;
934
+ }
935
+
936
+ if (requestContentType && this.operation.consumes) {
937
+ if (this.operation.consumes[requestContentType] === 'undefined') {
938
+ log("server doesn't consume " + requestContentType + ", try " + JSON.stringify(this.operation.consumes));
939
+ if (this.requestContentType === null) {
940
+ requestContentType = this.operation.consumes[0];
941
+ }
942
+ }
943
+ }
944
+
945
+ responseContentType = null;
946
+ if (this.opts.responseContentType) {
947
+ responseContentType = this.opts.responseContentType;
948
+ } else {
949
+ responseContentType = "application/json";
950
+ }
951
+ if (responseContentType && this.operation.produces) {
952
+ if (this.operation.produces[responseContentType] === 'undefined') {
953
+ log("server can't produce " + responseContentType);
954
+ }
955
+ }
956
+ if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) {
957
+ var fields = {};
958
+ var possibleParams = {};
959
+ var values = {};
960
+
961
+ for(var i = 0; i < formParams.length; i++){
962
+ var param = formParams[i];
963
+ values[param.name] = param;
964
+ }
965
+
966
+ var encoded = "";
967
+ for(key in values) {
968
+ value = this.params[key];
969
+ if(encoded !== "")
970
+ encoded += "&";
971
+ encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
972
+ }
973
+ body = encoded
974
+ }
975
+ for (name in this.headers)
976
+ myHeaders[name] = this.headers[name];
977
+ if (requestContentType)
978
+ myHeaders["Content-Type"] = requestContentType;
979
+ if (responseContentType)
980
+ myHeaders["Accept"] = responseContentType;
981
+
982
+ if (!((this.headers != null) && (this.headers.mock != null))) {
983
+ obj = {
984
+ url: this.url,
985
+ method: this.type,
986
+ headers: myHeaders,
987
+ body: body,
988
+ useJQuery: this.useJQuery,
989
+ on: {
990
+ error: function(response) {
991
+ return _this.errorCallback(response, _this.opts.parent);
992
+ },
993
+ redirect: function(response) {
994
+ return _this.successCallback(response, _this.opts.parent);
995
+ },
996
+ 307: function(response) {
997
+ return _this.successCallback(response, _this.opts.parent);
998
+ },
999
+ response: function(response) {
1000
+ return _this.successCallback(response, _this.opts.parent);
1001
+ }
1002
+ }
1003
+ };
1004
+ var e;
1005
+ if (typeof window !== 'undefined') {
1006
+ e = window;
1007
+ } else {
1008
+ e = exports;
1009
+ }
1010
+ status = e.authorizations.apply(obj, this.operation.authorizations);
1011
+ if (opts.mock == null) {
1012
+ if (status !== false) {
1013
+ new SwaggerHttp().execute(obj);
1014
+ } else {
1015
+ obj.canceled = true;
1016
+ }
1017
+ } else {
1018
+ return obj;
1019
+ }
1020
+ }
1021
+ };
1022
+
1023
+ SwaggerRequest.prototype.asCurl = function() {
1024
+ var results = [];
1025
+ if(this.headers) {
1026
+ for(key in this.headers) {
1027
+ results.push("--header \"" + key + ": " + this.headers[v] + "\"");
1028
+ }
1029
+ }
1030
+ return "curl " + (results.join(" ")) + " " + this.url;
1031
+ };
1032
+
1033
+ /**
1034
+ * SwaggerHttp is a wrapper for executing requests
1035
+ */
1036
+ var SwaggerHttp = function() {};
1037
+
1038
+ SwaggerHttp.prototype.execute = function(obj) {
1039
+ if(obj && (typeof obj.useJQuery === 'boolean'))
1040
+ this.useJQuery = obj.useJQuery;
1041
+ else
1042
+ this.useJQuery = this.isIE8();
1043
+
1044
+ if(this.useJQuery)
1045
+ return new JQueryHttpClient().execute(obj);
1046
+ else
1047
+ return new ShredHttpClient().execute(obj);
1048
+ }
1049
+
1050
+ SwaggerHttp.prototype.isIE8 = function() {
1051
+ var detectedIE = false;
1052
+ if (typeof navigator !== 'undefined' && navigator.userAgent) {
1053
+ nav = navigator.userAgent.toLowerCase();
1054
+ if (nav.indexOf('msie') !== -1) {
1055
+ var version = parseInt(nav.split('msie')[1]);
1056
+ if (version <= 8) {
1057
+ detectedIE = true;
1058
+ }
1059
+ }
1060
+ }
1061
+ return detectedIE;
1062
+ };
1063
+
1064
+ /*
1065
+ * JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic
1066
+ */
1067
+ var JQueryHttpClient = function(options) {}
1068
+
1069
+ JQueryHttpClient.prototype.execute = function(obj) {
1070
+ var cb = obj.on;
1071
+ var request = obj;
1072
+
1073
+ obj.type = obj.method;
1074
+ obj.cache = false;
1075
+
1076
+ obj.beforeSend = function(xhr) {
1077
+ var key, results;
1078
+ if (obj.headers) {
1079
+ results = [];
1080
+ for (key in obj.headers) {
1081
+ if (key.toLowerCase() === "content-type") {
1082
+ results.push(obj.contentType = obj.headers[key]);
1083
+ } else if (key.toLowerCase() === "accept") {
1084
+ results.push(obj.accepts = obj.headers[key]);
1085
+ } else {
1086
+ results.push(xhr.setRequestHeader(key, obj.headers[key]));
1087
+ }
1088
+ }
1089
+ return results;
1090
+ }
1091
+ };
1092
+
1093
+ obj.data = obj.body;
1094
+ obj.complete = function(response, textStatus, opts) {
1095
+ headers = {};
1096
+ headerArray = response.getAllResponseHeaders().split(":");
1097
+
1098
+ for(var i = 0; i < headerArray.length / 2; i++)
1099
+ headers[headerArray[i] = headerArray[i+1]];
1100
+
1101
+ out = {
1102
+ headers: headers,
1103
+ url: request.url,
1104
+ method: request.method,
1105
+ status: response.status,
1106
+ data: response.responseText,
1107
+ headers: headers
1108
+ };
1109
+
1110
+ var contentType = (response._headers["content-type"]||response._headers["Content-Type"]||null)
1111
+
1112
+ if(contentType != null) {
1113
+ if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
1114
+ if(response.responseText && response.responseText !== "")
1115
+ out.obj = JSON.parse(response.responseText);
1116
+ else
1117
+ out.obj = {}
1118
+ }
1119
+ }
1120
+
1121
+ if(response.status >= 200 && response.status < 300)
1122
+ cb.response(out);
1123
+ else if(response.status === 0 || (response.status >= 400 && response.status < 599))
1124
+ cb.error(out);
1125
+ else
1126
+ return cb.response(out);
1127
+ };
1128
+
1129
+ $.support.cors = true;
1130
+ return $.ajax(obj);
1131
+ }
1132
+
1133
+ /*
1134
+ * ShredHttpClient is a light-weight, node or browser HTTP client
1135
+ */
1136
+ var ShredHttpClient = function(options) {
1137
+ this.options = (options||{});
1138
+ this.isInitialized = false;
1139
+
1140
+ var identity, toString;
1141
+
1142
+ if (typeof window !== 'undefined') {
1143
+ this.Shred = require("./shred");
1144
+ this.content = require("./shred/content");
1145
+ }
1146
+ else
1147
+ this.Shred = require("shred");
1148
+ this.shred = new this.Shred();
1149
+ }
1150
+
1151
+ ShredHttpClient.prototype.initShred = function () {
1152
+ this.isInitialized = true;
1153
+ this.registerProcessors(this.shred);
1154
+ }
1155
+
1156
+ ShredHttpClient.prototype.registerProcessors = function(shred) {
1157
+ var identity = function(x) {
1158
+ return x;
1159
+ };
1160
+ var toString = function(x) {
1161
+ return x.toString();
1162
+ };
1163
+
1164
+ if (typeof window !== 'undefined') {
1165
+ this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
1166
+ parser: identity,
1167
+ stringify: toString
1168
+ });
1169
+ } else {
1170
+ this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
1171
+ parser: identity,
1172
+ stringify: toString
1173
+ });
1174
+ }
1175
+ }
1176
+
1177
+ ShredHttpClient.prototype.execute = function(obj) {
1178
+ if(!this.isInitialized)
1179
+ this.initShred();
1180
+
1181
+ var cb = obj.on, res;
1182
+
1183
+ var transform = function(response) {
1184
+ var out = {
1185
+ headers: response._headers,
1186
+ url: response.request.url,
1187
+ method: response.request.method,
1188
+ status: response.status,
1189
+ data: response.content.data
1190
+ };
1191
+
1192
+ var contentType = (response._headers["content-type"]||response._headers["Content-Type"]||null)
1193
+
1194
+ if(contentType != null) {
1195
+ if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
1196
+ if(response.content.data && response.content.data !== "")
1197
+ out.obj = JSON.parse(response.content.data);
1198
+ else
1199
+ out.obj = {}
1200
+ }
1201
+ }
1202
+ return out;
1203
+ };
1204
+
1205
+ res = {
1206
+ error: function(response) {
1207
+ if (obj)
1208
+ return cb.error(transform(response));
1209
+ },
1210
+ redirect: function(response) {
1211
+ if (obj)
1212
+ return cb.redirect(transform(response));
1213
+ },
1214
+ 307: function(response) {
1215
+ if (obj)
1216
+ return cb.redirect(transform(response));
1217
+ },
1218
+ response: function(response) {
1219
+ if (obj)
1220
+ return cb.response(transform(response));
1221
+ }
1222
+ };
1223
+ if (obj) {
1224
+ obj.on = res;
1225
+ }
1226
+ return this.shred.request(obj);
1227
+ };
1228
+
1229
+ /**
1230
+ * SwaggerAuthorizations applys the correct authorization to an operation being executed
1231
+ */
1232
+ var SwaggerAuthorizations = function() {
1233
+ this.authz = {};
1234
+ };
1235
+
1236
+ SwaggerAuthorizations.prototype.add = function(name, auth) {
1237
+ this.authz[name] = auth;
1238
+ return auth;
1239
+ };
1240
+
1241
+ SwaggerAuthorizations.prototype.remove = function(name) {
1242
+ return delete this.authz[name];
1243
+ };
1244
+
1245
+ SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
1246
+ status = null;
1247
+ for (key in this.authz) {
1248
+ value = this.authz[key];
1249
+ result = value.apply(obj, authorizations);
1250
+ if (result === false)
1251
+ status = false;
1252
+ if (result === true)
1253
+ status = true;
1254
+ }
1255
+ return status;
1256
+ };
1257
+
1258
+ /**
1259
+ * ApiKeyAuthorization allows a query param or header to be injected
1260
+ */
1261
+ var ApiKeyAuthorization = function(name, value, type) {
1262
+ this.name = name;
1263
+ this.value = value;
1264
+ this.type = type;
1265
+ };
1266
+
1267
+ ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
1268
+ if (this.type === "query") {
1269
+ if (obj.url.indexOf('?') > 0)
1270
+ obj.url = obj.url + "&" + this.name + "=" + this.value;
1271
+ else
1272
+ obj.url = obj.url + "?" + this.name + "=" + this.value;
1273
+ return true;
1274
+ } else if (this.type === "header") {
1275
+ obj.headers[this.name] = this.value;
1276
+ return true;
1277
+ }
1278
+ };
1279
+
1280
+ /**
1281
+ * Password Authorization is a basic auth implementation
1282
+ */
1283
+ var PasswordAuthorization = function(name, username, password) {
1284
+ this.name = name;
1285
+ this.username = username;
1286
+ this.password = password;
1287
+ this._btoa = null;
1288
+
1289
+ if (typeof window !== 'undefined')
1290
+ return this._btoa = btoa;
1291
+ else
1292
+ return this._btoa = require("btoa");
1293
+ };
1294
+
1295
+ PasswordAuthorization.prototype.apply = function(obj, authorizations) {
1296
+ obj.headers["Authorization"] = "Basic " + this._btoa(this.username + ":" + this.password);
1297
+ return true;
1298
+ };
1299
+
1300
+ var e = (typeof window !== 'undefined' ? window : exports);
1301
+
1302
+ e.SwaggerHttp = SwaggerHttp;
1303
+ e.SwaggerRequest = SwaggerRequest;
1304
+ e.authorizations = new SwaggerAuthorizations();
1305
+ e.JQueryHttpClient = JQueryHttpClient;
1306
+ e.ShredHttpClient = ShredHttpClient;
1307
+ e.SwaggerOperation = SwaggerOperation;
1308
+ e.SwaggerModel = SwaggerModel;
1309
+ e.SwaggerModelProperty = SwaggerModelProperty;
1310
+ e.SwaggerResource = SwaggerResource;
1311
+ e.SwaggerApi = SwaggerApi;