-
-
Notifications
You must be signed in to change notification settings - Fork 151
/
bundle.js
1333 lines (1170 loc) · 36.9 KB
/
bundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* Swagger Parser v5.0.0 (July 24th 2018)
*
* http://bigstickcarpet.com/swagger-parser
*
* @author James Messinger (http://bigstickcarpet.com)
* @license MIT
*/
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';
var format = require('format-util');
var slice = Array.prototype.slice;
var protectedProperties = ['name', 'message', 'stack'];
var errorPrototypeProperties = [
'name', 'message', 'description', 'number', 'code', 'fileName', 'lineNumber', 'columnNumber',
'sourceURL', 'line', 'column', 'stack'
];
module.exports = create(Error);
module.exports.error = create(Error);
module.exports.eval = create(EvalError);
module.exports.range = create(RangeError);
module.exports.reference = create(ReferenceError);
module.exports.syntax = create(SyntaxError);
module.exports.type = create(TypeError);
module.exports.uri = create(URIError);
module.exports.formatter = format;
/**
* Creates a new {@link ono} function that creates the given Error class.
*
* @param {Class} Klass - The Error subclass to create
* @returns {ono}
*/
function create (Klass) {
/**
* @param {Error} [err] - The original error, if any
* @param {object} [props] - An object whose properties will be added to the error object
* @param {string} [message] - The error message. May contain {@link util#format} placeholders
* @param {...*} [params] - Parameters that map to the `message` placeholders
* @returns {Error}
*/
return function onoFactory (err, props, message, params) { // eslint-disable-line no-unused-vars
var formatArgs = [];
var formattedMessage = '';
// Determine which arguments were actually specified
if (typeof err === 'string') {
formatArgs = slice.call(arguments);
err = props = undefined;
}
else if (typeof props === 'string') {
formatArgs = slice.call(arguments, 1);
props = undefined;
}
else if (typeof message === 'string') {
formatArgs = slice.call(arguments, 2);
}
// If there are any format arguments, then format the error message
if (formatArgs.length > 0) {
formattedMessage = module.exports.formatter.apply(null, formatArgs);
}
if (err && err.message) {
// The inner-error's message will be added to the new message
formattedMessage += (formattedMessage ? ' \n' : '') + err.message;
}
// Create the new error
// NOTE: DON'T move this to a separate function! We don't want to pollute the stack trace
var newError = new Klass(formattedMessage);
// Extend the new error with the additional properties
extendError(newError, err); // Copy properties of the original error
extendToJSON(newError); // Replace the original toJSON method
extend(newError, props); // Copy custom properties, possibly including a custom toJSON method
return newError;
};
}
/**
* Extends the targetError with the properties of the source error.
*
* @param {Error} targetError - The error object to extend
* @param {?Error} sourceError - The source error object, if any
*/
function extendError (targetError, sourceError) {
extendStack(targetError, sourceError);
extend(targetError, sourceError);
}
/**
* JavaScript engines differ in how errors are serialized to JSON - especially when it comes
* to custom error properties and stack traces. So we add our own toJSON method that ALWAYS
* outputs every property of the error.
*/
function extendToJSON (error) {
error.toJSON = errorToJSON;
// Also add an inspect() method, for compatibility with Node.js' `util.inspect()` method
error.inspect = errorToString;
}
/**
* Extends the target object with the properties of the source object.
*
* @param {object} target - The object to extend
* @param {?source} source - The object whose properties are copied
*/
function extend (target, source) {
if (source && typeof source === 'object') {
var keys = Object.keys(source);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
// Don't copy "protected" properties, since they have special meaning/behavior
// and are set by the onoFactory function
if (protectedProperties.indexOf(key) >= 0) {
continue;
}
try {
target[key] = source[key];
}
catch (e) {
// This property is read-only, so it can't be copied
}
}
}
}
/**
* Custom JSON serializer for Error objects.
* Returns all built-in error properties, as well as extended properties.
*
* @returns {object}
*/
function errorToJSON () {
var json = {};
// Get all the properties of this error
var keys = Object.keys(this);
// Also include properties from the Error prototype
keys = keys.concat(errorPrototypeProperties);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var value = this[key];
var type = typeof value;
if (type !== 'undefined' && type !== 'function') {
json[key] = value;
}
}
return json;
}
/**
* Serializes Error objects as human-readable JSON strings for debugging/logging purposes.
*
* @returns {string}
*/
function errorToString () {
return JSON.stringify(this, null, 2).replace(/\\n/g, '\n');
}
/**
* Extend the error stack to include its cause
*
* @param {Error} targetError
* @param {Error} sourceError
*/
function extendStack (targetError, sourceError) {
if (hasLazyStack(targetError)) {
if (sourceError) {
lazyJoinStacks(targetError, sourceError);
}
else {
lazyPopStack(targetError);
}
}
else {
if (sourceError) {
targetError.stack = joinStacks(targetError.stack, sourceError.stack);
}
else {
targetError.stack = popStack(targetError.stack);
}
}
}
/**
* Appends the original {@link Error#stack} property to the new Error's stack.
*
* @param {string} newStack
* @param {string} originalStack
* @returns {string}
*/
function joinStacks (newStack, originalStack) {
newStack = popStack(newStack);
if (newStack && originalStack) {
return newStack + '\n\n' + originalStack;
}
else {
return newStack || originalStack;
}
}
/**
* Removes Ono from the stack, so that the stack starts at the original error location
*
* @param {string} stack
* @returns {string}
*/
function popStack (stack) {
if (stack) {
var lines = stack.split('\n');
if (lines.length < 2) {
// The stack only has one line, so there's nothing we can remove
return stack;
}
// Find the `onoFactory` call in the stack, and remove it
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line.indexOf('onoFactory') >= 0) {
lines.splice(i, 1);
return lines.join('\n');
}
}
// If we get here, then the stack doesn't contain a call to `onoFactory`.
// This may be due to minification or some optimization of the JS engine.
// So just return the stack as-is.
return stack;
}
}
/**
* Does a one-time determination of whether this JavaScript engine
* supports lazy `Error.stack` properties.
*/
var supportsLazyStack = (function () {
return !!(
// ES5 property descriptors must be supported
Object.getOwnPropertyDescriptor && Object.defineProperty &&
// Chrome on Android doesn't support lazy stacks :(
(typeof navigator === 'undefined' || !/Android/.test(navigator.userAgent))
);
}());
/**
* Does this error have a lazy stack property?
*
* @param {Error} err
* @returns {boolean}
*/
function hasLazyStack (err) {
if (!supportsLazyStack) {
return false;
}
var descriptor = Object.getOwnPropertyDescriptor(err, 'stack');
if (!descriptor) {
return false;
}
return typeof descriptor.get === 'function';
}
/**
* Calls {@link joinStacks} lazily, when the {@link Error#stack} property is accessed.
*
* @param {Error} targetError
* @param {Error} sourceError
*/
function lazyJoinStacks (targetError, sourceError) {
var targetStack = Object.getOwnPropertyDescriptor(targetError, 'stack');
Object.defineProperty(targetError, 'stack', {
get: function () {
return joinStacks(targetStack.get.apply(targetError), sourceError.stack);
},
enumerable: false,
configurable: true
});
}
/**
* Calls {@link popStack} lazily, when the {@link Error#stack} property is accessed.
*
* @param {Error} error
*/
function lazyPopStack (error) {
var targetStack = Object.getOwnPropertyDescriptor(error, 'stack');
Object.defineProperty(error, 'stack', {
get: function () {
return popStack(targetStack.get.apply(error));
},
enumerable: false,
configurable: true
});
}
},{"format-util":2}],2:[function(require,module,exports){
function format(fmt) {
var re = /(%?)(%([jds]))/g
, args = Array.prototype.slice.call(arguments, 1);
if(args.length) {
fmt = fmt.replace(re, function(match, escaped, ptn, flag) {
var arg = args.shift();
switch(flag) {
case 's':
arg = '' + arg;
break;
case 'd':
arg = Number(arg);
break;
case 'j':
arg = JSON.stringify(arg);
break;
}
if(!escaped) {
return arg;
}
args.unshift(arg);
return match;
})
}
// arguments remain after formatting
if(args.length) {
fmt += ' ' + args.join(' ');
}
// update escaped %% values
fmt = fmt.replace(/%{2,2}/g, '%');
return '' + fmt;
}
module.exports = format;
},{}],3:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
// If obj.hasOwnProperty has been overridden, then calling
// obj.hasOwnProperty(prop) will break.
// See: https://github.com/joyent/node/issues/1707
function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
module.exports = function(qs, sep, eq, options) {
sep = sep || '&';
eq = eq || '=';
var obj = {};
if (typeof qs !== 'string' || qs.length === 0) {
return obj;
}
var regexp = /\+/g;
qs = qs.split(sep);
var maxKeys = 1000;
if (options && typeof options.maxKeys === 'number') {
maxKeys = options.maxKeys;
}
var len = qs.length;
// maxKeys <= 0 means that we should not limit keys count
if (maxKeys > 0 && len > maxKeys) {
len = maxKeys;
}
for (var i = 0; i < len; ++i) {
var x = qs[i].replace(regexp, '%20'),
idx = x.indexOf(eq),
kstr, vstr, k, v;
if (idx >= 0) {
kstr = x.substr(0, idx);
vstr = x.substr(idx + 1);
} else {
kstr = x;
vstr = '';
}
k = decodeURIComponent(kstr);
v = decodeURIComponent(vstr);
if (!hasOwnProperty(obj, k)) {
obj[k] = v;
} else if (isArray(obj[k])) {
obj[k].push(v);
} else {
obj[k] = [obj[k], v];
}
}
return obj;
};
var isArray = Array.isArray || function (xs) {
return Object.prototype.toString.call(xs) === '[object Array]';
};
},{}],4:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
var stringifyPrimitive = function(v) {
switch (typeof v) {
case 'string':
return v;
case 'boolean':
return v ? 'true' : 'false';
case 'number':
return isFinite(v) ? v : '';
default:
return '';
}
};
module.exports = function(obj, sep, eq, name) {
sep = sep || '&';
eq = eq || '=';
if (obj === null) {
obj = undefined;
}
if (typeof obj === 'object') {
return map(objectKeys(obj), function(k) {
var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
if (isArray(obj[k])) {
return map(obj[k], function(v) {
return ks + encodeURIComponent(stringifyPrimitive(v));
}).join(sep);
} else {
return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
}
}).join(sep);
}
if (!name) return '';
return encodeURIComponent(stringifyPrimitive(name)) + eq +
encodeURIComponent(stringifyPrimitive(obj));
};
var isArray = Array.isArray || function (xs) {
return Object.prototype.toString.call(xs) === '[object Array]';
};
function map (xs, f) {
if (xs.map) return xs.map(f);
var res = [];
for (var i = 0; i < xs.length; i++) {
res.push(f(xs[i], i));
}
return res;
}
var objectKeys = Object.keys || function (obj) {
var res = [];
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
}
return res;
};
},{}],5:[function(require,module,exports){
'use strict';
exports.decode = exports.parse = require('./decode');
exports.encode = exports.stringify = require('./encode');
},{"./decode":3,"./encode":4}],6:[function(require,module,exports){
'use strict';
var debug = location.hostname === 'localhost';
module.exports = analytics;
/**
* Initializes Google Analytics and sends a "pageview" hit
*/
function analytics () {
if (!debug) {
ga('create', 'UA-68102273-1', 'auto');
ga('send', 'pageview');
}
}
/**
* Tracks an event in Google Analytics
*
* @param {string} category - the object type (e.g. "button", "menu", "link", etc.)
* @param {string} action - the action (e.g. "click", "show", "hide", etc.)
* @param {string} [label] - label for categorization
* @param {number} [value] - numeric value, such as a counter
*/
analytics.trackEvent = function (category, action, label, value) {
if (debug) {
console.log('Reporting an event to Google Analytics: ', category, action, label, value);
}
else {
ga('send', 'event', category, action, label, value);
}
};
/**
* Tracks an error in Google Analytics
*
* @param {Error} err
*/
analytics.trackError = function (err) {
if (debug) {
console.error('Reporting an error to Google Analytics: ', err);
}
else {
ga('send', 'exception', { exDescription: err.message });
}
};
},{}],7:[function(require,module,exports){
'use strict';
var form = require('./form'),
analytics = require('./analytics');
module.exports = dropdowns;
/**
* Adds all the drop-down menu functionality
*/
function dropdowns () {
// Set the initial method name (in case it was set by the querystring module)
setSelectedMethod(form.method.button.val());
// Update each dropdown's label when its value(s) change
onChange(form.allow.menu, setAllowLabel);
onChange(form.refs.menu, setRefsLabel);
onChange(form.validate.menu, setValidateLabel);
// Track option changes
trackCheckbox(form.allow.json);
trackCheckbox(form.allow.yaml);
trackCheckbox(form.allow.text);
trackCheckbox(form.allow.empty);
trackCheckbox(form.allow.unknown);
trackCheckbox(form.refs.external);
trackCheckbox(form.refs.circular);
trackCheckbox(form.validate.schema);
trackCheckbox(form.validate.spec);
// Change the button text whenever a new method is selected
form.method.menu.find('a').on('click', function (event) {
form.method.menu.dropdown('toggle');
event.stopPropagation();
var methodName = $(this).data('value');
setSelectedMethod(methodName);
trackButtonLabel(methodName);
});
}
/**
* Calls the given function whenever the user selects (or deselects)
* a value in the given drop-down menu.
*
* @param {jQuery} menu
* @param {function} setLabel
*/
function onChange (menu, setLabel) {
var dropdown = menu.parent('.dropdown');
// Don't auto-close the menu when items are clicked
menu.find('a').on('click', function (event) {
event.stopPropagation();
});
// Set the label immediately, and again whenever the menu is closed
setLabel();
dropdown.on('hidden.bs.dropdown', setLabel);
// Track when a dropdown menu is shown
dropdown.on('shown.bs.dropdown', function () {
analytics.trackEvent('options', 'shown', menu.attr('id'));
});
}
/**
* Sets the "allow" label, based on which options are selected
*/
function setAllowLabel () {
var values = getCheckedAndUnchecked(
form.allow.json, form.allow.yaml, form.allow.text, form.allow.empty, form.allow.unknown);
switch (values.checked.length) {
case 0:
form.allow.label.text('No file types allowed');
break;
case 1:
form.allow.label.text('Only allow ' + values.checked[0] + ' files');
break;
case 2:
form.allow.label.text('Only allow ' + values.checked[0] + ' and ' + values.checked[1]);
break;
case 3:
form.allow.label.text('Don\'t allow ' + values.unchecked[0] + ' or ' + values.unchecked[1]);
break;
case 4:
form.allow.label.text('Don\'t allow ' + values.unchecked[0] + ' files');
break;
case 5:
form.allow.label.text('Allow all file types');
}
}
/**
* Sets the "refs" label, based on which options are selected
*/
function setRefsLabel () {
var values = getCheckedAndUnchecked(form.refs.external, form.refs.circular);
switch (values.checked.length) {
case 0:
form.refs.label.text('Only follow internal $refs');
break;
case 1:
form.refs.label.text('Don\'t follow ' + values.unchecked[0] + ' $refs');
break;
case 2:
form.refs.label.text('Follow all $refs');
}
}
/**
* Sets the "validate" label, based on which options are selected
*/
function setValidateLabel () {
var values = getCheckedAndUnchecked(form.validate.schema, form.validate.spec);
switch (values.checked.length) {
case 0:
form.validate.label.text('Don\'t validate anything');
break;
case 1:
form.validate.label.text('Don\'t validate Swagger ' + values.unchecked[0]);
break;
case 2:
form.validate.label.text('Validate everything');
}
}
/**
* Updates the UI to match the specified method name
*
* @param {string} methodName - The method name (e.g. "validate", "dereference", etc.)
*/
function setSelectedMethod (methodName) {
form.method.button.val(methodName.toLowerCase());
methodName = methodName[0].toUpperCase() + methodName.substr(1);
form.method.button.text(methodName + ' it!');
form.tabs.url.text(methodName + ' a URL');
form.tabs.text.text(methodName + ' Text');
}
/**
* Tracks changes to a checkbox option
*
* @param {jQuery} checkbox
*/
function trackCheckbox (checkbox) {
checkbox.on('change', function () {
var value = checkbox.is(':checked') ? 1 : 0;
analytics.trackEvent('options', 'changed', checkbox.attr('name'), value);
});
}
/**
* Tracks changes to the "Validate!" button
*
* @param {string} methodName - The method name (e.g. "validate", "dereference", etc.)
*/
function trackButtonLabel (methodName) {
var value = ['', 'parse', 'resolve', 'bundle', 'dereference', 'validate'].indexOf(methodName);
analytics.trackEvent('options', 'changed', 'method', value);
}
/**
* Examines the given checkboxes, and returns arrays of checked and unchecked values.
*
* @param {...jQuery} checkboxes
* @returns {{checked: string[], unchecked: string[]}}
*/
function getCheckedAndUnchecked (checkboxes) {
var checked = [], unchecked = [];
for (var i = 0; i < arguments.length; i++) {
var checkbox = arguments[i];
if (checkbox.is(':checked')) {
checked.push(checkbox.data('value'));
}
else {
unchecked.push(checkbox.data('value'));
}
}
return { checked: checked, unchecked: unchecked };
}
},{"./analytics":6,"./form":9}],8:[function(require,module,exports){
'use strict';
var form = require('./form'),
ono = require('ono'),
ACE_THEME = 'ace/theme/terminal';
module.exports = editors;
/**
* Initializes the ACE text editors
*/
function editors () {
editors.textBox = form.textBox = ace.edit('text-box');
form.textBox.setTheme(ACE_THEME);
var session = form.textBox.getSession();
session.setMode('ace/mode/yaml');
session.setTabSize(2);
editors.results = $('#results');
editors.tabs = editors.results.find('.nav-tabs');
editors.panes = editors.results.find('.tab-content');
}
/**
* Removes all results tabs and editors
*/
editors.clearResults = function () {
editors.results.removeClass('error animated').addClass('hidden');
editors.tabs.children().remove();
editors.panes.children().remove();
};
/**
* Displays a successful result
*
* @param {string} title - The title of the tab
* @param {object|string} content - An object that will be displayed as JSON in the editor
*/
editors.showResult = function (title, content) {
editors.results.removeClass('hidden');
editors.addResult(title || 'Sample API', content);
showResults();
};
/**
* Displays an error result
*
* @param {Error} err
*/
editors.showError = function (err) {
editors.results.removeClass('hidden').addClass('error');
editors.addResult('Error!', err);
showResults();
};
/**
* Adds a results tab with an Ace Editor containing the given content
*
* @param {string} title - The title of the tab
* @param {object|string} content - An object that will be displayed as JSON in the editor
*/
editors.addResult = function (title, content) {
var index = editors.tabs.children().length;
var titleId = 'results-tab-' + index + '-title';
var editorId = 'results-' + index;
var active = index === 0 ? 'active' : '';
// Add a tab and pane
editors.tabs.append(
'<li id="results-tab-' + index + '" class="' + active + '" role="presentation">' +
' <a id="' + titleId + '" href="#results-pane-' + index + '" role="tab" aria-controls="results-pane-' + index + '" data-toggle="tab"></a>' +
'</li>'
);
editors.panes.append(
'<div id="results-pane-' + index + '" class="tab-pane ' + active + '" role="tabpanel">' +
' <pre id="' + editorId + '" class="editor"></pre>' +
'</div>'
);
// Set the tab title
var shortTitle = getShortTitle(title);
editors.tabs.find('#' + titleId).text(shortTitle).attr('title', title);
// Set the <pre> content
content = toText(content);
editors.panes.find('#' + editorId).text(content.text);
// Turn the <pre> into an Ace Editor
var editor = ace.edit(editorId);
editor.setTheme(ACE_THEME);
editor.session.setOption('useWorker', false);
content.isJSON && editor.getSession().setMode('ace/mode/json');
editor.setReadOnly(true);
};
/**
* Returns a short version of the given title text, to better fit in a tab
*
* @param {string} title
* @returns {string}
*/
function getShortTitle (title) {
// Get just the file name
var lastSlash = title.lastIndexOf('/');
if (lastSlash !== -1) {
title = title.substr(lastSlash + 1);
}
if (title.length > 15) {
// It's still too long, so, just return the first 10 characters
title = title.substr(0, 10) + '...';
}
return title;
}
/**
* Ensures that the results are visible, and plays an animation to get the user's attention.
*/
function showResults () {
var results = editors.results;
setTimeout(function () {
results[0].scrollIntoView();
results.addClass('animated')
.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
// Remove the "animated" class when the animation ends,
// so we can replay the animation again next time
results.removeClass('animated');
});
});
}
/**
* Converts the given object to text.
* If possible, it is converted to JSON; otherwise, plain text.
*
* @param {object} obj
* @returns {object}
*/
function toText (obj) {
if (obj instanceof Error) {
return {
isJSON: false,
text: obj.message + '\n\n' + obj.stack
};
}
else {
try {
return {
isJSON: true,
text: JSON.stringify(obj, null, 2)
};
}
catch (e) {
return {
isJSON: false,
text: 'This API is valid, but it cannot be shown because it contains circular references\n\n' + e.stack
};
}
}
}
},{"./form":9,"ono":1}],9:[function(require,module,exports){
'use strict';
module.exports = form;
/**
* Finds all form fields and exposes them as properties.
*/
function form () {
form.form = $('#swagger-parser-form');
form.allow = {
label: form.form.find('#allow-label'),
menu: form.form.find('#allow-menu'),
json: form.form.find('input[name=allow-json]'),
yaml: form.form.find('input[name=allow-yaml]'),
text: form.form.find('input[name=allow-text]'),
empty: form.form.find('input[name=allow-empty]'),
unknown: form.form.find('input[name=allow-unknown]')
};
form.refs = {
label: form.form.find('#refs-label'),
menu: form.form.find('#refs-menu'),
external: form.form.find('input[name=refs-external]'),
circular: form.form.find('input[name=refs-circular]')
};
form.validate = {
label: form.form.find('#validate-label'),
menu: form.form.find('#validate-menu'),
schema: form.form.find('input[name=validate-schema]'),
spec: form.form.find('input[name=validate-spec]')
};
form.tabs = {
url: form.form.find('#url-tab'),
text: form.form.find('#text-tab')
};
form.method = {
button: form.form.find('button[name=method]'),
menu: form.form.find('#method-menu')
};
form.samples = {
url: {
container: form.form.find('#url-sample'),
link: form.form.find('#url-sample-link'),
},
text: {
container: form.form.find('#text-sample'),
link: form.form.find('#text-sample-link'),
}
};
form.url = form.form.find('input[name=url]');
form.textBox = null; // This is set in editors.js
form.bookmark = form.form.find('#bookmark');
}
/**
* Returns a Swagger Parser options object,
* set to the current values of all the form fields.
*/
form.getOptions = function () {
return {
parse: {
json: form.allow.json.is(':checked') ? {
allowEmpty: form.allow.empty.is(':checked'),
} : false,
yaml: form.allow.yaml.is(':checked') ? {
allowEmpty: form.allow.empty.is(':checked'),