jellyfish 1.0.2 → 1.1.0

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