forked from json-schema-form/angular-schema-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-schema-form.js
5727 lines (5180 loc) · 285 KB
/
angular-schema-form.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
/*!
* angular-schema-form
* @version 1.0.0-alpha.5
* @date Mon, 17 Jul 2017 14:13:21 GMT
* @link https://github.com/json-schema-form/angular-schema-form
* @license MIT
* Copyright (c) 2014-2017 JSON Schema Form
*/
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 21);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports) {
module.exports = angular;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global, setImmediate) {/*!
* json-schema-form-core
* @version 1.0.0-alpha.5
* @date Sat, 24 Jun 2017 14:16:26 GMT
* @link https://github.com/json-schema-form/json-schema-form-core
* @license MIT
* Copyright (c) 2014-2017 JSON Schema Form
*/
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 13);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_objectpath__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_objectpath___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_objectpath__);
/* harmony reexport (binding) */ if(__webpack_require__.o(__WEBPACK_IMPORTED_MODULE_0_objectpath__, "parse")) __webpack_require__.d(__webpack_exports__, "parse", function() { return __WEBPACK_IMPORTED_MODULE_0_objectpath__["parse"]; });
/* harmony reexport (binding) */ if(__webpack_require__.o(__WEBPACK_IMPORTED_MODULE_0_objectpath__, "stringify")) __webpack_require__.d(__webpack_exports__, "stringify", function() { return __WEBPACK_IMPORTED_MODULE_0_objectpath__["stringify"]; });
/* harmony reexport (binding) */ if(__webpack_require__.o(__WEBPACK_IMPORTED_MODULE_0_objectpath__, "normalize")) __webpack_require__.d(__webpack_exports__, "normalize", function() { return __WEBPACK_IMPORTED_MODULE_0_objectpath__["normalize"]; });
/* harmony export (immutable) */ __webpack_exports__["name"] = name;
/**
* I am a name formatter function for processing keys into names for classes or Id.
*
* @param {Array<string>} key I am the key array of a processed schema key
* @param {string} separator I am the separator between the key items and optional form name
* @param {string} formName I am an optional form name
* @param {boolean} omitNumbers I determine if numeric values should be included in the output or withheld
*
* @return {string} I am the formatted key
*/
function name(key, separator) {
var formName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
var omitNumbers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
if (key) {
var fieldKey = key.slice();
var fieldSeparator = separator || '-';
if (omitNumbers) {
fieldKey = fieldKey.filter(function (currentKey) {
return typeof currentKey !== 'number';
});
};
return (formName.length !== 0 ? formName + fieldSeparator : '') + fieldKey.join(fieldSeparator);
};
return '';
};
/***/ }),
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
// Takes a titleMap in either object or list format and returns one
/* harmony default export */ __webpack_exports__["a"] = function (titleMap, originalEnum) {
if (!Array.isArray(titleMap)) {
var _ret = function () {
var canonical = [];
if (originalEnum) {
originalEnum.forEach(function (value) {
canonical.push({ name: titleMap[value], value: value });
});
} else {
Object.keys(titleMap).forEach(function (value) {
canonical.push({ name: titleMap[value], value: value });
});
}
return {
v: canonical
};
}();
if ((typeof _ret === "undefined" ? "undefined" : _typeof(_ret)) === "object") return _ret.v;
}
return titleMap;
};
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(11).ObjectPath;
/***/ }),
/* 3 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__sf_path__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__canonical_title_map__ = __webpack_require__(1);
/* harmony export (immutable) */ __webpack_exports__["defaultFormDefinition"] = defaultFormDefinition;
/* harmony export (immutable) */ __webpack_exports__["stdFormObj"] = stdFormObj;
/* harmony export (immutable) */ __webpack_exports__["text"] = text;
/* harmony export (immutable) */ __webpack_exports__["number"] = number;
/* harmony export (immutable) */ __webpack_exports__["integer"] = integer;
/* harmony export (immutable) */ __webpack_exports__["checkbox"] = checkbox;
/* harmony export (immutable) */ __webpack_exports__["select"] = select;
/* harmony export (immutable) */ __webpack_exports__["checkboxes"] = checkboxes;
/* harmony export (immutable) */ __webpack_exports__["fieldset"] = fieldset;
/* harmony export (immutable) */ __webpack_exports__["array"] = array;
/* harmony export (immutable) */ __webpack_exports__["createDefaults"] = createDefaults;
/* harmony export (immutable) */ __webpack_exports__["defaultForm"] = defaultForm;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
/* Utils */
var stripNullType = function stripNullType(type) {
if (Array.isArray(type) && type.length === 2) {
if (type[0] === 'null') {
return type[1];
};
if (type[1] === 'null') {
return type[0];
};
};
return type;
};
// Creates an default titleMap list from an enum, i.e. a list of strings.
var enumToTitleMap = function enumToTitleMap(enm) {
var titleMap = []; // canonical titleMap format is a list.
enm.forEach(function (name) {
titleMap.push({ name: name, value: name });
});
return titleMap;
};
/**
* Creates a default form definition from a schema.
*/
function defaultFormDefinition(schemaTypes, name, schema, options) {
var rules = schemaTypes[stripNullType(schema.type)];
if (rules) {
var def = void 0;
// We give each rule a possibility to recurse it's children.
var innerDefaultFormDefinition = function innerDefaultFormDefinition(childName, childSchema, childOptions) {
return defaultFormDefinition(schemaTypes, childName, childSchema, childOptions);
};
for (var i = 0; i < rules.length; i++) {
def = rules[i](name, schema, options, innerDefaultFormDefinition);
// first handler in list that actually returns something is our handler!
if (def) {
// Do we have form defaults in the schema under the x-schema-form-attribute?
if (def.schema['x-schema-form']) {
Object.assign(def, def.schema['x-schema-form']);
}
return def;
}
}
}
}
/**
* Creates a form object with all common properties
*/
function stdFormObj(name, schema, options) {
options = options || {};
// The Object.assign used to be a angular.copy. Should work though.
var f = options.global && options.global.formDefaults ? Object.assign({}, options.global.formDefaults) : {};
if (options.global && options.global.supressPropertyTitles === true) {
f.title = schema.title;
} else {
f.title = schema.title || name;
}
if (schema.description) {
f.description = schema.description;
}
if (options.required === true || schema.required === true) {
f.required = true;
}
if (schema.maxLength) {
f.maxlength = schema.maxLength;
}
if (schema.minLength) {
f.minlength = schema.minLength;
}
if (schema.readOnly || schema.readonly) {
f.readonly = true;
}
if (schema.minimum) {
f.minimum = schema.minimum + (schema.exclusiveMinimum ? 1 : 0);
}
if (schema.maximum) {
f.maximum = schema.maximum - (schema.exclusiveMaximum ? 1 : 0);
}
// Non standard attributes (DONT USE DEPRECATED)
// If you must set stuff like this in the schema use the x-schema-form attribute
if (schema.validationMessage) {
f.validationMessage = schema.validationMessage;
}
if (schema.enumNames) {
f.titleMap = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__canonical_title_map__["a" /* default */])(schema.enumNames, schema['enum']);
}
f.schema = schema;
// Ng model options doesn't play nice with undefined, might be defined
// globally though
f.ngModelOptions = f.ngModelOptions || {};
return f;
};
/*** Schema types to form type mappings, with defaults ***/
function text(name, schema, options) {
if (stripNullType(schema.type) === 'string' && !schema['enum']) {
var f = stdFormObj(name, schema, options);
f.key = options.path;
f.type = 'text';
options.lookup[__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__sf_path__["stringify"])(options.path)] = f;
return f;
}
}
// default in json form for number and integer is a text field
// input type="number" would be more suitable don't ya think?
function number(name, schema, options) {
if (stripNullType(schema.type) === 'number') {
var f = stdFormObj(name, schema, options);
f.key = options.path;
f.type = 'number';
options.lookup[__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__sf_path__["stringify"])(options.path)] = f;
return f;
}
}
function integer(name, schema, options) {
if (stripNullType(schema.type) === 'integer') {
var f = stdFormObj(name, schema, options);
f.key = options.path;
f.type = 'number';
options.lookup[__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__sf_path__["stringify"])(options.path)] = f;
return f;
}
}
function checkbox(name, schema, options) {
if (stripNullType(schema.type) === 'boolean') {
var f = stdFormObj(name, schema, options);
f.key = options.path;
f.type = 'checkbox';
options.lookup[__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__sf_path__["stringify"])(options.path)] = f;
return f;
}
}
function select(name, schema, options) {
if (stripNullType(schema.type) === 'string' && schema['enum']) {
var f = stdFormObj(name, schema, options);
f.key = options.path;
f.type = 'select';
if (!f.titleMap) {
f.titleMap = enumToTitleMap(schema['enum']);
}
options.lookup[__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__sf_path__["stringify"])(options.path)] = f;
return f;
}
}
function checkboxes(name, schema, options) {
if (stripNullType(schema.type) === 'array' && schema.items && schema.items['enum']) {
var f = stdFormObj(name, schema, options);
f.key = options.path;
f.type = 'checkboxes';
if (!f.titleMap) {
f.titleMap = enumToTitleMap(schema.items['enum']);
}
options.lookup[__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__sf_path__["stringify"])(options.path)] = f;
return f;
}
}
function fieldset(name, schema, options, defaultFormDef) {
if (stripNullType(schema.type) === 'object') {
var _ret = function () {
var f = stdFormObj(name, schema, options);
f.type = 'fieldset';
f.key = options.path;
f.items = [];
options.lookup[__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__sf_path__["stringify"])(options.path)] = f;
// recurse down into properties
if (schema.properties) {
Object.keys(schema.properties).forEach(function (key) {
var value = schema.properties[key];
var path = options.path.slice();
path.push(key);
if (options.ignore[__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__sf_path__["stringify"])(path)] !== true) {
var required = schema.required && schema.required.indexOf(key) !== -1;
var def = defaultFormDef(key, value, {
path: path,
required: required || false,
lookup: options.lookup,
ignore: options.ignore,
global: options.global
});
if (def) {
f.items.push(def);
}
}
});
}
return {
v: f
};
}();
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
}
}
function array(name, schema, options, defaultFormDef) {
if (stripNullType(schema.type) === 'array') {
var f = stdFormObj(name, schema, options);
f.type = 'array';
f.key = options.path;
options.lookup[__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__sf_path__["stringify"])(options.path)] = f;
var required = schema.required && schema.required.indexOf(options.path[options.path.length - 1]) !== -1;
// The default is to always just create one child. This works since if the
// schemas items declaration is of type: "object" then we get a fieldset.
// We also follow json form notatation, adding empty brackets "[]" to
// signify arrays.
var arrPath = options.path.slice();
arrPath.push('');
f.items = [defaultFormDef(name, schema.items, {
path: arrPath,
required: required || false,
lookup: options.lookup,
ignore: options.ignore,
global: options.global
})];
return f;
}
}
function createDefaults() {
// First sorted by schema type then a list.
// Order has importance. First handler returning an form snippet will be used.
return {
string: [select, text],
object: [fieldset],
number: [number],
integer: [integer],
boolean: [checkbox],
array: [checkboxes, array]
};
};
/**
* Create form defaults from schema
*/
function defaultForm(schema, defaultSchemaTypes, ignore, globalOptions) {
var form = [];
var lookup = {}; // Map path => form obj for fast lookup in merging
ignore = ignore || {};
globalOptions = globalOptions || {};
defaultSchemaTypes = defaultSchemaTypes || createDefaults();
if (schema.properties) {
Object.keys(schema.properties).forEach(function (key) {
if (ignore[key] !== true) {
var required = schema.required && schema.required.indexOf(key) !== -1;
var def = defaultFormDefinition(defaultSchemaTypes, key, schema.properties[key], {
path: [key], // Path to this property in bracket notation.
lookup: lookup, // Extra map to register with. Optimization for merger.
ignore: ignore, // The ignore list of paths (sans root level name)
required: required, // Is it required? (v4 json schema style)
global: globalOptions // Global options, including form defaults
});
if (def) {
form.push(def);
}
}
});
} else {
throw new Error('Not implemented. Only type "object" allowed at root level of schema.');
}
return { form: form, lookup: lookup };
}
/***/ }),
/* 4 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__lib_schema_defaults__ = __webpack_require__(3);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__lib_sf_path__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__lib_canonical_title_map__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__lib_merge__ = __webpack_require__(6);
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "merge", function() { return __WEBPACK_IMPORTED_MODULE_3__lib_merge__["a"]; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__lib_select__ = __webpack_require__(8);
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "select", function() { return __WEBPACK_IMPORTED_MODULE_4__lib_select__["a"]; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__lib_resolve__ = __webpack_require__(7);
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "jsonref", function() { return __WEBPACK_IMPORTED_MODULE_5__lib_resolve__["a"]; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__lib_traverse__ = __webpack_require__(9);
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "traverseSchema", function() { return __WEBPACK_IMPORTED_MODULE_6__lib_traverse__["a"]; });
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "traverseForm", function() { return __WEBPACK_IMPORTED_MODULE_6__lib_traverse__["b"]; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__lib_validate__ = __webpack_require__(10);
/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "validate", function() { return __WEBPACK_IMPORTED_MODULE_7__lib_validate__["a"]; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "sfPath", function() { return sfPath; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "schemaDefaults", function() { return schemaDefaults; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "canonicalTitleMap", function() { return canonicalTitleMap; });
var sfPath = __WEBPACK_IMPORTED_MODULE_1__lib_sf_path__;
var schemaDefaults = __WEBPACK_IMPORTED_MODULE_0__lib_schema_defaults__;
var canonicalTitleMap = __WEBPACK_IMPORTED_MODULE_2__lib_canonical_title_map__["a" /* default */];
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;var require;var require;var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj;}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};(function(f){if(( false?"undefined":_typeof(exports))==="object"&&typeof module!=="undefined"){module.exports=f();}else if(true){!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (f),
__WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
(__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));}else{var g;if(typeof window!=="undefined"){g=window;}else if(typeof global!=="undefined"){g=global;}else if(typeof self!=="undefined"){g=self;}else{g=this;}g.JsonRefs=f();}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return require(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f;}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e);},l,l.exports,e,t,n,r);}return n[o].exports;}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++){s(r[o]);}return s;}({1:[function(require,module,exports){/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Jeremy Whitlock
*
* 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';/**
* Various utilities for JSON References *(http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03)* and
* JSON Pointers *(https://tools.ietf.org/html/rfc6901)*.
*
* @module JsonRefs
*/var path=require('path');var PathLoader=require('path-loader');var qs=require('querystring');var slash=require('slash');var URI=require('uri-js');var badPtrTokenRegex=/~(?:[^01]|$)/g;var remoteCache={};var remoteTypes=['relative','remote'];var remoteUriTypes=['absolute','uri'];var uriDetailsCache={};// Load promises polyfill if necessary
/* istanbul ignore if */if(typeof Promise==='undefined'){require('native-promise-only');}/* Internal Functions */// This is a very simplistic clone function that does not take into account non-JSON types. For these types the
// original value is used as the clone. So while it's not a complete deep clone, for the needs of this project
// this should be sufficient.
function clone(obj){var cloned;if(isType(obj,'Array')){cloned=[];obj.forEach(function(value,index){cloned[index]=clone(value);});}else if(isType(obj,'Object')){cloned={};Object.keys(obj).forEach(function(key){cloned[key]=clone(obj[key]);});}else{cloned=obj;}return cloned;}function combineQueryParams(qs1,qs2){var combined={};function mergeQueryParams(obj){Object.keys(obj).forEach(function(key){combined[key]=obj[key];});}mergeQueryParams(qs.parse(qs1||''));mergeQueryParams(qs.parse(qs2||''));return Object.keys(combined).length===0?undefined:qs.stringify(combined);}function combineURIs(u1,u2){// Convert Windows paths
if(isType(u1,'String')){u1=slash(u1);}if(isType(u2,'String')){u2=slash(u2);}var u2Details=parseURI(isType(u2,'Undefined')?'':u2);var u1Details;var combinedDetails;if(remoteUriTypes.indexOf(u2Details.reference)>-1){combinedDetails=u2Details;}else{u1Details=isType(u1,'Undefined')?undefined:parseURI(u1);if(!isType(u1Details,'Undefined')){combinedDetails=u1Details;// Join the paths
combinedDetails.path=slash(path.join(u1Details.path,u2Details.path));// Join query parameters
combinedDetails.query=combineQueryParams(u1Details.query,u2Details.query);}else{combinedDetails=u2Details;}}// Remove the fragment
combinedDetails.fragment=undefined;// For relative URIs, add back the '..' since it was removed above
return(remoteUriTypes.indexOf(combinedDetails.reference)===-1&&combinedDetails.path.indexOf('../')===0?'../':'')+URI.serialize(combinedDetails);}function findAncestors(obj,path){var ancestors=[];var node;if(path.length>0){node=obj;path.slice(0,path.length-1).forEach(function(seg){if(seg in node){node=node[seg];ancestors.push(node);}});}return ancestors;}function processSubDocument(mode,doc,subDocPath,refDetails,options,parents,parentPtrs,allRefs,indirect){var refValue;var rOptions;if(subDocPath.length>0){try{refValue=findValue(doc,subDocPath);}catch(err){// We only mark missing remote references as missing because local references can have deferred values
if(mode==='remote'){refDetails.error=err.message;refDetails.missing=true;}}}else{refValue=doc;}if(!isType(refValue,'Undefined')){refDetails.value=refValue;}if(isType(refValue,'Array')||isType(refValue,'Object')){rOptions=clone(options);if(mode==='local'){delete rOptions.subDocPath;// Traverse the dereferenced value
doc=refValue;}else{rOptions.relativeBase=path.dirname(parents[parents.length-1]);if(subDocPath.length===0){delete rOptions.subDocPath;}else{rOptions.subDocPath=subDocPath;}}return findRefsRecursive(doc,rOptions,parents,parentPtrs,allRefs,indirect);}}// Should this be its own exported API?
function findRefsRecursive(obj,options,parents,parentPtrs,allRefs,indirect){var allTasks=Promise.resolve();var parentPath=parentPtrs.length?pathFromPtr(parentPtrs[parentPtrs.length-1]):[];var refs=findRefs(obj,options);var subDocPath=options.subDocPath||[];var subDocPtr=pathToPtr(subDocPath);var ancestorPtrs=['#'];parents.forEach(function(parent,index){if(parent.charAt(0)!=='#'){ancestorPtrs.push(parentPtrs[index]);}});// Reverse the order so we search them in the proper order
ancestorPtrs.reverse();if((parents[parents.length-1]||'').charAt(0)!=='#'){allRefs.documents[pathToPtr(parentPath)]=obj;}Object.keys(refs).forEach(function(refPtr){var refDetails=refs[refPtr];var location;var parentIndex;var refFullPath;var refFullPtr;// If there are no parents, treat the reference pointer as-is. Otherwise, the reference is a reference within a
// remote document and its sub document path prefix must be removed.
if(parents.length===0){refFullPath=parentPath.concat(pathFromPtr(refPtr));}else{refFullPath=parentPath.concat(pathFromPtr(refPtr).slice(parents.length===0?0:subDocPath.length));}refFullPtr=pathToPtr(refFullPath);// It is possible to process the same reference more than once in the event of hierarchical references so we avoid
// processing a reference if we've already done so.
if(!isType(allRefs[refFullPtr],'Undefined')){return;}// Record the reference metadata
allRefs.refs[refFullPtr]=refs[refPtr];// Do not process invalid references
if(isType(refDetails.error,'Undefined')&&refDetails.type!=='invalid'){if(remoteTypes.indexOf(refDetails.type)>-1){location=combineURIs(options.relativeBase,refDetails.uri);parentIndex=parents.indexOf(location);}else{location=refDetails.uri;parentIndex=parentPtrs.indexOf(location);}// Record ancestor paths
refDetails.ancestorPtrs=ancestorPtrs;// Record if the reference is indirect based on its parent
refDetails.indirect=indirect;// Only process non-circular references further
if(parentIndex===-1){if(remoteTypes.indexOf(refDetails.type)>-1){allTasks=allTasks.then(function(){return getRemoteDocument(location,options).then(function(doc){return processSubDocument('remote',doc,isType(refDetails.uriDetails.fragment,'Undefined')?[]:pathFromPtr(decodeURI(refDetails.uriDetails.fragment)),refDetails,options,parents.concat(location),parentPtrs.concat(refFullPtr),allRefs,indirect);}).catch(function(err){refDetails.error=err.message;refDetails.missing=true;});});}else{if(refFullPtr.indexOf(location+'/')!==0&&refFullPtr!==location&&subDocPtr.indexOf(location+'/')!==0&&subDocPtr!==location){if(location.indexOf(subDocPtr+'/')!==0){allTasks=allTasks.then(function(){return processSubDocument('local',obj,pathFromPtr(location),refDetails,options,parents.concat(location),parentPtrs.concat(refFullPtr),allRefs,indirect||location.indexOf(subDocPtr+'/')===-1&&location!==subDocPtr);});}}else{refDetails.circular=true;}}}else{// Mark seen ancestors as circular
parentPtrs.slice(parentIndex).forEach(function(parentPtr){allRefs.refs[parentPtr].circular=true;});refDetails.circular=true;}}});allTasks=allTasks.then(function(){// Identify indirect, local circular references (Issue 82)
var circulars=[];var processedRefPtrs=[];var processedRefs=[];function walkRefs(parentPtrs,parentRefs,refPtr,ref){Object.keys(allRefs.refs).forEach(function(dRefPtr){var dRefDetails=allRefs.refs[dRefPtr];// Do not process already processed references or references that are not a nested references
if(processedRefs.indexOf(ref)===-1&&processedRefPtrs.indexOf(refPtr)===-1&&circulars.indexOf(ref)===-1&&dRefPtr!==refPtr&&dRefPtr.indexOf(ref+'/')===0){if(parentRefs.indexOf(ref)>-1){parentRefs.forEach(function(parentRef){if(circulars.indexOf(ref)===-1){circulars.push(parentRef);}});}else{walkRefs(parentPtrs.concat(refPtr),parentRefs.concat(ref),dRefPtr,dRefDetails.uri);}processedRefPtrs.push(refPtr);processedRefs.push(ref);}});}Object.keys(allRefs.refs).forEach(function(refPtr){var refDetails=allRefs.refs[refPtr];// Only process local, non-circular references
if(refDetails.type==='local'&&!refDetails.circular&&circulars.indexOf(refDetails.uri)===-1){walkRefs([],[],refPtr,refDetails.uri);}});Object.keys(allRefs.refs).forEach(function(refPtr){var refDetails=allRefs.refs[refPtr];if(circulars.indexOf(refDetails.uri)>-1){refDetails.circular=true;}});}).then(function(){return allRefs;});return allTasks;}function findValue(obj,path){var value=obj;path.forEach(function(seg){seg=decodeURI(seg);if(seg in value){value=value[seg];}else{throw Error('JSON Pointer points to missing location: '+pathToPtr(path));}});return value;}function getExtraRefKeys(ref){return Object.keys(ref).filter(function(key){return key!=='$ref';});}function getRefType(refDetails){var type;// Convert the URI reference to one of our types
switch(refDetails.uriDetails.reference){case'absolute':case'uri':type='remote';break;case'same-document':type='local';break;default:type=refDetails.uriDetails.reference;}return type;}function getRemoteDocument(url,options){var cacheEntry=remoteCache[url];var allTasks=Promise.resolve();var loaderOptions=clone(options.loaderOptions||{});if(isType(cacheEntry,'Undefined')){// If there is no content processor, default to processing the raw response as JSON
if(isType(loaderOptions.processContent,'Undefined')){loaderOptions.processContent=function(res,callback){callback(undefined,JSON.parse(res.text));};}// Attempt to load the resource using path-loader
allTasks=PathLoader.load(decodeURI(url),loaderOptions);// Update the cache
allTasks=allTasks.then(function(res){remoteCache[url]={value:res};return res;}).catch(function(err){remoteCache[url]={error:err};throw err;});}else{// Return the cached version
allTasks=allTasks.then(function(){return cacheEntry.value;});}// Return a cloned version to avoid updating the cache
allTasks=allTasks.then(function(res){return clone(res);});return allTasks;}function isRefLike(obj,throwWithDetails){var refLike=true;try{if(!isType(obj,'Object')){throw new Error('obj is not an Object');}else if(!isType(obj.$ref,'String')){throw new Error('obj.$ref is not a String');}}catch(err){if(throwWithDetails){throw err;}refLike=false;}return refLike;}function isType(obj,type){// A PhantomJS bug (https://github.com/ariya/phantomjs/issues/11722) prohibits us from using the same approach for
// undefined checking that we use for other types.
if(type==='Undefined'){return typeof obj==='undefined';}else{return Object.prototype.toString.call(obj)==='[object '+type+']';}}function makeRefFilter(options){var refFilter;var validTypes;if(isType(options.filter,'Array')||isType(options.filter,'String')){validTypes=isType(options.filter,'String')?[options.filter]:options.filter;refFilter=function refFilter(refDetails){// Check the exact type or for invalid URIs, check its original type
return validTypes.indexOf(refDetails.type)>-1||validTypes.indexOf(getRefType(refDetails))>-1;};}else if(isType(options.filter,'Function')){refFilter=options.filter;}else if(isType(options.filter,'Undefined')){refFilter=function refFilter(){return true;};}return function(refDetails,path){return(refDetails.type!=='invalid'||options.includeInvalid===true)&&refFilter(refDetails,path);};}function makeSubDocPath(options){var subDocPath;if(isType(options.subDocPath,'Array')){subDocPath=options.subDocPath;}else if(isType(options.subDocPath,'String')){subDocPath=pathFromPtr(options.subDocPath);}else if(isType(options.subDocPath,'Undefined')){subDocPath=[];}return subDocPath;}function parseURI(uri){// We decode first to avoid doubly encoding
return URI.parse(encodeURI(decodeURI(uri)));}function setValue(obj,refPath,value){findValue(obj,refPath.slice(0,refPath.length-1))[decodeURI(refPath[refPath.length-1])]=value;}function walk(ancestors,node,path,fn){var processChildren=true;function walkItem(item,segment){path.push(segment);walk(ancestors,item,path,fn);path.pop();}// Call the iteratee
if(isType(fn,'Function')){processChildren=fn(ancestors,node,path);}// We do not process circular objects again
if(ancestors.indexOf(node)===-1){ancestors.push(node);if(processChildren!==false){if(isType(node,'Array')){node.forEach(function(member,index){walkItem(member,index.toString());});}else if(isType(node,'Object')){Object.keys(node).forEach(function(key){walkItem(node[key],key);});}}}ancestors.pop();}function validateOptions(options,obj){if(isType(options,'Undefined')){// Default to an empty options object
options={};}else{// Clone the options so we do not alter the ones passed in
options=clone(options);}if(!isType(options,'Object')){throw new TypeError('options must be an Object');}else if(!isType(options.filter,'Undefined')&&!isType(options.filter,'Array')&&!isType(options.filter,'Function')&&!isType(options.filter,'String')){throw new TypeError('options.filter must be an Array, a Function of a String');}else if(!isType(options.includeInvalid,'Undefined')&&!isType(options.includeInvalid,'Boolean')){throw new TypeError('options.includeInvalid must be a Boolean');}else if(!isType(options.refPreProcessor,'Undefined')&&!isType(options.refPreProcessor,'Function')){throw new TypeError('options.refPreProcessor must be a Function');}else if(!isType(options.refPostProcessor,'Undefined')&&!isType(options.refPostProcessor,'Function')){throw new TypeError('options.refPostProcessor must be a Function');}else if(!isType(options.subDocPath,'Undefined')&&!isType(options.subDocPath,'Array')&&!isPtr(options.subDocPath)){// If a pointer is provided, throw an error if it's not the proper type
throw new TypeError('options.subDocPath must be an Array of path segments or a valid JSON Pointer');}options.filter=makeRefFilter(options);// Set the subDocPath to avoid everyone else having to compute it
options.subDocPath=makeSubDocPath(options);if(!isType(obj,'Undefined')){try{findValue(obj,options.subDocPath);}catch(err){err.message=err.message.replace('JSON Pointer','options.subDocPath');throw err;}}return options;}/* Module Members *//*
* Each of the functions below are defined as function statements and *then* exported in two steps instead of one due
* to a bug in jsdoc (https://github.com/jsdoc2md/jsdoc-parse/issues/18) that causes our documentation to be
* generated improperly. The impact to the user is significant enough for us to warrant working around it until this
* is fixed.
*//**
* The options used for various JsonRefs APIs.
*
* @typedef {object} JsonRefsOptions
*
* @param {string|string[]|function} [filter=function () {return true;}] - The filter to use when gathering JSON
* References *(If this value is a single string or an array of strings, the value(s) are expected to be the `type(s)`
* you are interested in collecting as described in {@link module:JsonRefs.getRefDetails}. If it is a function, it is
* expected that the function behaves like {@link module:JsonRefs~RefDetailsFilter}.)*
* @param {boolean} [includeInvalid=false] - Whether or not to include invalid JSON Reference details *(This will make
* it so that objects that are like JSON Reference objects, as in they are an `Object` and the have a `$ref` property,
* but fail validation will be included. This is very useful for when you want to know if you have invalid JSON
* Reference definitions. This will not mean that APIs will process invalid JSON References but the reasons as to why
* the JSON References are invalid will be included in the returned metadata.)*
* @param {object} [loaderOptions] - The options to pass to
* {@link https://github.com/whitlockjc/path-loader/blob/master/docs/API.md#module_PathLoader.load|PathLoader~load}
* @param {module:JsonRefs~RefPreProcessor} [refPreProcessor] - The callback used to pre-process a JSON Reference like
* object *(This is called prior to validating the JSON Reference like object and getting its details)*
* @param {module:JsonRefs~RefPostProcessor} [refPostProcessor] - The callback used to post-process the JSON Reference
* metadata *(This is called prior filtering the references)*
* @param {string} [options.relativeBase] - The base location to use when resolving relative references *(Only useful
* for APIs that do remote reference resolution. If this value is not defined,
* {@link https://github.com/whitlockjc/path-loader|path-loader} will use `window.location.href` for the browser and
* `process.cwd()` for Node.js.)*
* @param {string|string[]} [options.subDocPath=[]] - The JSON Pointer or array of path segments to the sub document
* location to search from
*//**
* Simple function used to filter out JSON References.
*
* @typedef {function} RefDetailsFilter
*
* @param {module:JsonRefs~UnresolvedRefDetails} refDetails - The JSON Reference details to test
* @param {string[]} path - The path to the JSON Reference
*
* @returns {boolean} whether the JSON Reference should be filtered *(out)* or not
*//**
* Simple function used to pre-process a JSON Reference like object.
*
* @typedef {function} RefPreProcessor
*
* @param {object} obj - The JSON Reference like object
* @param {string[]} path - The path to the JSON Reference like object
*
* @returns {object} the processed JSON Reference like object
*//**
* Simple function used to post-process a JSON Reference details.
*
* @typedef {function} RefPostProcessor
*
* @param {module:JsonRefs~UnresolvedRefDetails} refDetails - The JSON Reference details to test
* @param {string[]} path - The path to the JSON Reference
*
* @returns {object} the processed JSON Reference details object
*//**
* Detailed information about resolved JSON References.
*
* @typedef {module:JsonRefs~UnresolvedRefDetails} ResolvedRefDetails
*
* @property {boolean} [circular] - Whether or not the JSON Reference is circular *(Will not be set if the JSON
* Reference is not circular)*
* @property {boolean} [missing] - Whether or not the referenced value was missing or not *(Will not be set if the
* referenced value is not missing)*
* @property {*} [value] - The referenced value *(Will not be set if the referenced value is missing)*
*//**
* The results of resolving the JSON References of an array/object.
*
* @typedef {object} ResolvedRefsResults
*
* @property {module:JsonRefs~ResolvedRefDetails} refs - An object whose keys are JSON Pointers *(fragment version)*
* to where the JSON Reference is defined and whose values are {@link module:JsonRefs~ResolvedRefDetails}
* @property {object} resolved - The array/object with its JSON References fully resolved
*//**
* An object containing the retrieved document and detailed information about its JSON References.
*
* @typedef {module:JsonRefs~ResolvedRefsResults} RetrievedRefsResults
*
* @property {object} value - The retrieved document
*//**
* An object containing the retrieved document, the document with its references resolved and detailed information
* about its JSON References.
*
* @typedef {object} RetrievedResolvedRefsResults
*
* @property {module:JsonRefs~UnresolvedRefDetails} refs - An object whose keys are JSON Pointers *(fragment version)*
* to where the JSON Reference is defined and whose values are {@link module:JsonRefs~UnresolvedRefDetails}
* @property {ResolvedRefsResults} - An object whose keys are JSON Pointers *(fragment version)*
* to where the JSON Reference is defined and whose values are {@link module:JsonRefs~ResolvedRefDetails}
* @property {object} value - The retrieved document
*//**
* Detailed information about unresolved JSON References.
*
* @typedef {object} UnresolvedRefDetails
*
* @property {object} def - The JSON Reference definition
* @property {string} [error] - The error information for invalid JSON Reference definition *(Only present when the
* JSON Reference definition is invalid or there was a problem retrieving a remote reference during resolution)*
* @property {string} uri - The URI portion of the JSON Reference
* @property {object} uriDetails - Detailed information about the URI as provided by
* {@link https://github.com/garycourt/uri-js|URI.parse}.
* @property {string} type - The JSON Reference type *(This value can be one of the following: `invalid`, `local`,
* `relative` or `remote`.)*
* @property {string} [warning] - The warning information *(Only present when the JSON Reference definition produces a
* warning)*
*//**
* Clears the internal cache of remote documents, reference details, etc.
*
* @alias module:JsonRefs.clearCache
*/function clearCache(){remoteCache={};}/**
* Takes an array of path segments and decodes the JSON Pointer tokens in them.
*
* @param {string[]} path - The array of path segments
*
* @returns {string} the array of path segments with their JSON Pointer tokens decoded
*
* @throws {Error} if the path is not an `Array`
*
* @see {@link https://tools.ietf.org/html/rfc6901#section-3}
*
* @alias module:JsonRefs.decodePath
*/function decodePath(path){if(!isType(path,'Array')){throw new TypeError('path must be an array');}return path.map(function(seg){if(!isType(seg,'String')){seg=JSON.stringify(seg);}return decodeURI(seg.replace(/~1/g,'/').replace(/~0/g,'~'));});}/**
* Takes an array of path segments and encodes the special JSON Pointer characters in them.
*
* @param {string[]} path - The array of path segments
*
* @returns {string} the array of path segments with their JSON Pointer tokens encoded
*
* @throws {Error} if the path is not an `Array`
*
* @see {@link https://tools.ietf.org/html/rfc6901#section-3}
*
* @alias module:JsonRefs.encodePath
*/function encodePath(path){if(!isType(path,'Array')){throw new TypeError('path must be an array');}return path.map(function(seg){if(!isType(seg,'String')){seg=JSON.stringify(seg);}return seg.replace(/~/g,'~0').replace(/\//g,'~1');});}/**
* Finds JSON References defined within the provided array/object.
*
* @param {array|object} obj - The structure to find JSON References within
* @param {module:JsonRefs~JsonRefsOptions} [options] - The JsonRefs options
*
* @returns {object} an object whose keys are JSON Pointers *(fragment version)* to where the JSON Reference is defined
* and whose values are {@link module:JsonRefs~UnresolvedRefDetails}.
*
* @throws {Error} when the input arguments fail validation or if `options.subDocPath` points to an invalid location
*
* @alias module:JsonRefs.findRefs
*
* @example
* // Finding all valid references
* var allRefs = JsonRefs.findRefs(obj);
* // Finding all remote references
* var remoteRefs = JsonRefs.findRefs(obj, {filter: ['relative', 'remote']});
* // Finding all invalid references
* var invalidRefs = JsonRefs.findRefs(obj, {filter: 'invalid', includeInvalid: true});
*/function findRefs(obj,options){var refs={};// Validate the provided document
if(!isType(obj,'Array')&&!isType(obj,'Object')){throw new TypeError('obj must be an Array or an Object');}// Validate options
options=validateOptions(options,obj);// Walk the document (or sub document) and find all JSON References
walk(findAncestors(obj,options.subDocPath),findValue(obj,options.subDocPath),clone(options.subDocPath),function(ancestors,node,path){var processChildren=true;var refDetails;if(isRefLike(node)){// Pre-process the node when necessary
if(!isType(options.refPreProcessor,'Undefined')){node=options.refPreProcessor(clone(node),path);}refDetails=getRefDetails(node);// Post-process the reference details
if(!isType(options.refPostProcessor,'Undefined')){refDetails=options.refPostProcessor(refDetails,path);}if(options.filter(refDetails,path)){refs[pathToPtr(path)]=refDetails;}// Whenever a JSON Reference has extra children, its children should not be processed.
// See: http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03#section-3
if(getExtraRefKeys(node).length>0){processChildren=false;}}return processChildren;});return refs;}/**
* Finds JSON References defined within the document at the provided location.
*
* This API is identical to {@link module:JsonRefs.findRefs} except this API will retrieve a remote document and then
* return the result of {@link module:JsonRefs.findRefs} on the retrieved document.
*
* @param {string} location - The location to retrieve *(Can be relative or absolute, just make sure you look at the
* {@link module:JsonRefs~JsonRefsOptions|options documentation} to see how relative references are handled.)*
* @param {module:JsonRefs~JsonRefsOptions} [options] - The JsonRefs options
*
* @returns {Promise} a promise that resolves a {@link module:JsonRefs~RetrievedRefsResults} and rejects with an
* `Error` when the input arguments fail validation, when `options.subDocPath` points to an invalid location or when
* the location argument points to an unloadable resource
*
* @alias module:JsonRefs.findRefsAt
*
* @example
* // Example that only resolves references within a sub document
* JsonRefs.findRefsAt('http://petstore.swagger.io/v2/swagger.json', {
* subDocPath: '#/definitions'
* })
* .then(function (res) {
* // Do something with the response
* //
* // res.refs: JSON Reference locations and details
* // res.value: The retrieved document
* }, function (err) {
* console.log(err.stack);
* });
*/function findRefsAt(location,options){var allTasks=Promise.resolve();allTasks=allTasks.then(function(){// Validate the provided location
if(!isType(location,'String')){throw new TypeError('location must be a string');}// Validate options
options=validateOptions(options);// Combine the location and the optional relative base
location=combineURIs(options.relativeBase,location);return getRemoteDocument(location,options);}).then(function(res){var cacheEntry=clone(remoteCache[location]);var cOptions=clone(options);var uriDetails=parseURI(location);if(isType(cacheEntry.refs,'Undefined')){// Do not filter any references so the cache is complete
delete cOptions.filter;delete cOptions.subDocPath;cOptions.includeInvalid=true;remoteCache[location].refs=findRefs(res,cOptions);}// Add the filter options back
if(!isType(options.filter,'Undefined')){cOptions.filter=options.filter;}if(!isType(uriDetails.fragment,'Undefined')){cOptions.subDocPath=pathFromPtr(decodeURI(uriDetails.fragment));}else if(!isType(uriDetails.subDocPath,'Undefined')){cOptions.subDocPath=options.subDocPath;}// This will use the cache so don't worry about calling it twice
return{refs:findRefs(res,cOptions),value:res};});return allTasks;}/**
* Returns detailed information about the JSON Reference.
*
* @param {object} obj - The JSON Reference definition
*
* @returns {module:JsonRefs~UnresolvedRefDetails} the detailed information
*
* @alias module:JsonRefs.getRefDetails
*/function getRefDetails(obj){var details={def:obj};var cacheKey;var extraKeys;var uriDetails;try{if(isRefLike(obj,true)){cacheKey=obj.$ref;uriDetails=uriDetailsCache[cacheKey];if(isType(uriDetails,'Undefined')){uriDetails=uriDetailsCache[cacheKey]=parseURI(cacheKey);}details.uri=cacheKey;details.uriDetails=uriDetails;if(isType(uriDetails.error,'Undefined')){details.type=getRefType(details);}else{details.error=details.uriDetails.error;details.type='invalid';}// Identify warning
extraKeys=getExtraRefKeys(obj);if(extraKeys.length>0){details.warning='Extra JSON Reference properties will be ignored: '+extraKeys.join(', ');}}else{details.type='invalid';}}catch(err){details.error=err.message;details.type='invalid';}return details;}/**
* Returns whether the argument represents a JSON Pointer.
*
* A string is a JSON Pointer if the following are all true:
*
* * The string is of type `String`
* * The string must be empty, `#` or start with a `/` or `#/`
*
* @param {string} ptr - The string to check
* @param {boolean} [throwWithDetails=false] - Whether or not to throw an `Error` with the details as to why the value
* provided is invalid
*
* @returns {boolean} the result of the check
*
* @throws {error} when the provided value is invalid and the `throwWithDetails` argument is `true`
*
* @alias module:JsonRefs.isPtr
*
* @see {@link https://tools.ietf.org/html/rfc6901#section-3}
*
* @example
* // Separating the different ways to invoke isPtr for demonstration purposes
* if (isPtr(str)) {
* // Handle a valid JSON Pointer
* } else {
* // Get the reason as to why the value is not a JSON Pointer so you can fix/report it
* try {
* isPtr(str, true);
* } catch (err) {
* // The error message contains the details as to why the provided value is not a JSON Pointer
* }
* }
*/function isPtr(ptr,throwWithDetails){var valid=true;var firstChar;try{if(isType(ptr,'String')){if(ptr!==''){firstChar=ptr.charAt(0);if(['#','/'].indexOf(firstChar)===-1){throw new Error('ptr must start with a / or #/');}else if(firstChar==='#'&&ptr!=='#'&&ptr.charAt(1)!=='/'){throw new Error('ptr must start with a / or #/');}else if(ptr.match(badPtrTokenRegex)){throw new Error('ptr has invalid token(s)');}}}else{throw new Error('ptr is not a String');}}catch(err){if(throwWithDetails===true){throw err;}valid=false;}return valid;}/**
* Returns whether the argument represents a JSON Reference.
*
* An object is a JSON Reference only if the following are all true:
*
* * The object is of type `Object`
* * The object has a `$ref` property
* * The `$ref` property is a valid URI *(We do not require 100% strict URIs and will handle unescaped special
* characters.)*
*
* @param {object} obj - The object to check
* @param {boolean} [throwWithDetails=false] - Whether or not to throw an `Error` with the details as to why the value
* provided is invalid
*
* @returns {boolean} the result of the check
*
* @throws {error} when the provided value is invalid and the `throwWithDetails` argument is `true`
*
* @alias module:JsonRefs.isRef
*
* @see {@link http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03#section-3}
*
* @example
* // Separating the different ways to invoke isRef for demonstration purposes
* if (isRef(obj)) {
* // Handle a valid JSON Reference
* } else {
* // Get the reason as to why the value is not a JSON Reference so you can fix/report it
* try {
* isRef(str, true);
* } catch (err) {
* // The error message contains the details as to why the provided value is not a JSON Reference
* }
* }
*/function isRef(obj,throwWithDetails){return isRefLike(obj,throwWithDetails)&&getRefDetails(obj,throwWithDetails).type!=='invalid';}/**
* Returns an array of path segments for the provided JSON Pointer.
*
* @param {string} ptr - The JSON Pointer
*
* @returns {string[]} the path segments
*
* @throws {Error} if the provided `ptr` argument is not a JSON Pointer
*
* @alias module:JsonRefs.pathFromPtr
*/function pathFromPtr(ptr){if(!isPtr(ptr)){throw new Error('ptr must be a JSON Pointer');}var segments=ptr.split('/');// Remove the first segment
segments.shift();return decodePath(segments);}/**
* Returns a JSON Pointer for the provided array of path segments.
*
* **Note:** If a path segment in `path` is not a `String`, it will be converted to one using `JSON.stringify`.
*
* @param {string[]} path - The array of path segments
* @param {boolean} [hashPrefix=true] - Whether or not create a hash-prefixed JSON Pointer
*
* @returns {string} the corresponding JSON Pointer
*
* @throws {Error} if the `path` argument is not an array
*
* @alias module:JsonRefs.pathToPtr
*/function pathToPtr(path,hashPrefix){if(!isType(path,'Array')){throw new Error('path must be an Array');}// Encode each segment and return
return(hashPrefix!==false?'#':'')+(path.length>0?'/':'')+encodePath(path).join('/');}/**
* Finds JSON References defined within the provided array/object and resolves them.
*
* @param {array|object} obj - The structure to find JSON References within
* @param {module:JsonRefs~JsonRefsOptions} [options] - The JsonRefs options
*
* @returns {Promise} a promise that resolves a {@link module:JsonRefs~ResolvedRefsResults} and rejects with an
* `Error` when the input arguments fail validation, when `options.subDocPath` points to an invalid location or when
* the location argument points to an unloadable resource
*
* @alias module:JsonRefs.resolveRefs
*
* @example
* // Example that only resolves relative and remote references
* JsonRefs.resolveRefs(swaggerObj, {
* filter: ['relative', 'remote']
* })
* .then(function (res) {
* // Do something with the response
* //
* // res.refs: JSON Reference locations and details
* // res.resolved: The document with the appropriate JSON References resolved
* }, function (err) {
* console.log(err.stack);
* });
*/function resolveRefs(obj,options){var allTasks=Promise.resolve();allTasks=allTasks.then(function(){// Validate the provided document
if(!isType(obj,'Array')&&!isType(obj,'Object')){throw new TypeError('obj must be an Array or an Object');}// Validate options
options=validateOptions(options,obj);// Clone the input so we do not alter it
obj=clone(obj);}).then(function(){return findRefsRecursive(obj,options,[],[],{documents:{},refs:{}});}).then(function(allRefs){var deferredRefs={};var refs={};function pathSorter(p1,p2){return pathFromPtr(p1).length-pathFromPtr(p2).length;}// Resolve all references with a known value
Object.keys(allRefs.refs).sort(pathSorter).forEach(function(refPtr){var refDetails=allRefs.refs[refPtr];// Record all direct references
if(!refDetails.indirect){refs[refPtr]=refDetails;}// Delete helper property