1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.default = void 0;
|
5 |
|
6 | var _helpers = require("../helpers");
|
7 |
|
8 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
9 |
|
10 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
11 |
|
12 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
13 |
|
14 | var _default = {
|
15 | key: 'allOf',
|
16 | plugin: (val, key, fullPath, specmap, patch) => {
|
17 |
|
18 |
|
19 |
|
20 | if (patch.meta && patch.meta.$$ref) {
|
21 | return undefined;
|
22 | }
|
23 |
|
24 | const parent = fullPath.slice(0, -1);
|
25 |
|
26 | if ((0, _helpers.isFreelyNamed)(parent)) {
|
27 | return undefined;
|
28 | }
|
29 |
|
30 | if (!Array.isArray(val)) {
|
31 | const err = new TypeError('allOf must be an array');
|
32 | err.fullPath = fullPath;
|
33 |
|
34 | return err;
|
35 | }
|
36 |
|
37 | let alreadyAddError = false;
|
38 |
|
39 |
|
40 | let originalDefinitionObj = patch.value;
|
41 | parent.forEach(part => {
|
42 | if (!originalDefinitionObj) return;
|
43 |
|
44 | originalDefinitionObj = originalDefinitionObj[part];
|
45 | });
|
46 | originalDefinitionObj = _objectSpread({}, originalDefinitionObj);
|
47 | delete originalDefinitionObj.allOf;
|
48 | const patches = [];
|
49 |
|
50 | patches.push(specmap.replace(parent, {}));
|
51 | val.forEach((toMerge, i) => {
|
52 | if (!specmap.isObject(toMerge)) {
|
53 | if (alreadyAddError) {
|
54 | return null;
|
55 | }
|
56 |
|
57 | alreadyAddError = true;
|
58 | const err = new TypeError('Elements in allOf must be objects');
|
59 | err.fullPath = fullPath;
|
60 |
|
61 | return patches.push(err);
|
62 | }
|
63 |
|
64 |
|
65 | patches.push(specmap.mergeDeep(parent, toMerge));
|
66 |
|
67 |
|
68 | const collapsedFullPath = fullPath.slice(0, -1);
|
69 | const absoluteRefPatches = (0, _helpers.generateAbsoluteRefPatches)(toMerge, collapsedFullPath, {
|
70 | getBaseUrlForNodePath: nodePath => {
|
71 | return specmap.getContext([...fullPath, i, ...nodePath]).baseDoc;
|
72 | },
|
73 | specmap
|
74 | });
|
75 | patches.push(...absoluteRefPatches);
|
76 | return undefined;
|
77 | });
|
78 |
|
79 | patches.push(specmap.mergeDeep(parent, originalDefinitionObj));
|
80 |
|
81 |
|
82 | if (!originalDefinitionObj.$$ref) {
|
83 | patches.push(specmap.remove([].concat(parent, '$$ref')));
|
84 | }
|
85 |
|
86 | return patches;
|
87 | }
|
88 | };
|
89 | exports.default = _default; |
\ | No newline at end of file |