@speclynx/apidom-reference 1.12.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/NOTICE +16 -7
  3. package/README.md +0 -33
  4. package/dist/167.apidom-reference.browser.min.js +1 -1
  5. package/dist/451.apidom-reference.browser.min.js +1 -1
  6. package/dist/apidom-reference.browser.js +24594 -23365
  7. package/dist/apidom-reference.browser.min.js +1 -1
  8. package/package.json +24 -57
  9. package/src/configuration/saturated.cjs +34 -42
  10. package/src/configuration/saturated.mjs +0 -8
  11. package/src/dereference/index.cjs +4 -4
  12. package/src/dereference/index.mjs +1 -1
  13. package/src/dereference/strategies/apidom/index.cjs +7 -7
  14. package/src/dereference/strategies/apidom/index.mjs +5 -6
  15. package/src/dereference/strategies/apidom/selectors/element-id.cjs +4 -2
  16. package/src/dereference/strategies/apidom/selectors/element-id.mjs +5 -3
  17. package/src/dereference/strategies/apidom/visitor.cjs +31 -17
  18. package/src/dereference/strategies/apidom/visitor.mjs +25 -12
  19. package/src/dereference/strategies/asyncapi-2/index.cjs +6 -9
  20. package/src/dereference/strategies/asyncapi-2/index.mjs +6 -10
  21. package/src/dereference/strategies/asyncapi-2/visitor.cjs +67 -80
  22. package/src/dereference/strategies/asyncapi-2/visitor.mjs +59 -72
  23. package/src/dereference/strategies/openapi-2/index.cjs +6 -9
  24. package/src/dereference/strategies/openapi-2/index.mjs +6 -10
  25. package/src/dereference/strategies/openapi-2/visitor.cjs +91 -100
  26. package/src/dereference/strategies/openapi-2/visitor.mjs +81 -90
  27. package/src/dereference/strategies/openapi-3-0/index.cjs +6 -9
  28. package/src/dereference/strategies/openapi-3-0/index.mjs +6 -10
  29. package/src/dereference/strategies/openapi-3-0/visitor.cjs +92 -115
  30. package/src/dereference/strategies/openapi-3-0/visitor.mjs +74 -97
  31. package/src/dereference/strategies/openapi-3-1/index.cjs +6 -9
  32. package/src/dereference/strategies/openapi-3-1/index.mjs +6 -10
  33. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.cjs +2 -1
  34. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.mjs +3 -2
  35. package/src/dereference/strategies/openapi-3-1/selectors/uri.cjs +2 -2
  36. package/src/dereference/strategies/openapi-3-1/selectors/uri.mjs +2 -2
  37. package/src/dereference/strategies/openapi-3-1/util.cjs +3 -2
  38. package/src/dereference/strategies/openapi-3-1/util.mjs +4 -3
  39. package/src/dereference/strategies/openapi-3-1/visitor.cjs +130 -156
  40. package/src/dereference/strategies/openapi-3-1/visitor.mjs +106 -132
  41. package/src/dereference/util.cjs +2 -2
  42. package/src/dereference/util.mjs +1 -1
  43. package/src/parse/parsers/apidom-json/index.cjs +5 -5
  44. package/src/parse/parsers/apidom-json/index.mjs +2 -2
  45. package/src/parse/parsers/arazzo-json-1/index.cjs +1 -2
  46. package/src/parse/parsers/arazzo-json-1/index.mjs +1 -2
  47. package/src/parse/parsers/asyncapi-json-2/index.cjs +1 -2
  48. package/src/parse/parsers/asyncapi-json-2/index.mjs +1 -2
  49. package/src/parse/parsers/binary/index-browser.cjs +3 -3
  50. package/src/parse/parsers/binary/index-browser.mjs +1 -1
  51. package/src/parse/parsers/binary/index-node.cjs +3 -3
  52. package/src/parse/parsers/binary/index-node.mjs +1 -1
  53. package/src/parse/parsers/json/index.cjs +1 -2
  54. package/src/parse/parsers/json/index.mjs +1 -2
  55. package/src/parse/parsers/openapi-json-2/index.cjs +1 -2
  56. package/src/parse/parsers/openapi-json-2/index.mjs +1 -2
  57. package/src/parse/parsers/openapi-json-3-0/index.cjs +1 -2
  58. package/src/parse/parsers/openapi-json-3-0/index.mjs +1 -2
  59. package/src/parse/parsers/openapi-json-3-1/index.cjs +1 -2
  60. package/src/parse/parsers/openapi-json-3-1/index.mjs +1 -2
  61. package/src/resolve/index.cjs +4 -4
  62. package/src/resolve/index.mjs +1 -1
  63. package/types/File.d.ts +1 -1
  64. package/types/Reference.d.ts +1 -1
  65. package/types/ReferenceSet.d.ts +1 -1
  66. package/types/apidom-reference.d.ts +8 -9
  67. package/types/bundle/index.d.ts +1 -1
  68. package/types/bundle/strategies/BundleStrategy.d.ts +1 -1
  69. package/types/bundle/strategies/openapi-3-1/index.d.ts +1 -1
  70. package/types/dereference/index.d.ts +1 -1
  71. package/types/dereference/strategies/DereferenceStrategy.d.ts +1 -1
  72. package/types/dereference/strategies/apidom/index.d.ts +1 -1
  73. package/types/dereference/strategies/apidom/selectors/element-id.d.ts +1 -1
  74. package/types/dereference/strategies/apidom/visitor.d.ts +3 -2
  75. package/types/dereference/strategies/asyncapi-2/index.d.ts +2 -2
  76. package/types/dereference/strategies/asyncapi-2/visitor.d.ts +5 -14
  77. package/types/dereference/strategies/openapi-2/index.d.ts +2 -2
  78. package/types/dereference/strategies/openapi-2/visitor.d.ts +6 -17
  79. package/types/dereference/strategies/openapi-3-0/index.d.ts +2 -2
  80. package/types/dereference/strategies/openapi-3-0/visitor.d.ts +7 -20
  81. package/types/dereference/strategies/openapi-3-1/index.d.ts +2 -2
  82. package/types/dereference/strategies/openapi-3-1/selectors/$anchor.d.ts +1 -1
  83. package/types/dereference/strategies/openapi-3-1/selectors/uri.d.ts +1 -1
  84. package/types/dereference/strategies/openapi-3-1/util.d.ts +1 -1
  85. package/types/dereference/strategies/openapi-3-1/visitor.d.ts +8 -23
  86. package/types/dereference/util.d.ts +1 -1
  87. package/types/index.d.ts +1 -1
  88. package/types/options/index.d.ts +1 -1
  89. package/types/parse/index.d.ts +1 -1
  90. package/types/parse/parsers/Parser.d.ts +1 -1
  91. package/types/parse/parsers/apidom-json/index.d.ts +1 -1
  92. package/types/parse/parsers/arazzo-json-1/index.d.ts +1 -2
  93. package/types/parse/parsers/arazzo-yaml-1/index.d.ts +1 -1
  94. package/types/parse/parsers/asyncapi-json-2/index.d.ts +1 -2
  95. package/types/parse/parsers/asyncapi-yaml-2/index.d.ts +1 -1
  96. package/types/parse/parsers/binary/index-browser.d.ts +1 -1
  97. package/types/parse/parsers/binary/index-node.d.ts +1 -1
  98. package/types/parse/parsers/json/index.d.ts +1 -2
  99. package/types/parse/parsers/openapi-json-2/index.d.ts +1 -2
  100. package/types/parse/parsers/openapi-json-3-0/index.d.ts +1 -2
  101. package/types/parse/parsers/openapi-json-3-1/index.d.ts +1 -2
  102. package/types/parse/parsers/openapi-yaml-2/index.d.ts +1 -1
  103. package/types/parse/parsers/openapi-yaml-3-0/index.d.ts +1 -1
  104. package/types/parse/parsers/openapi-yaml-3-1/index.d.ts +1 -1
  105. package/types/parse/parsers/yaml-1-2/index.d.ts +1 -1
  106. package/types/resolve/index.d.ts +1 -1
  107. package/src/parse/parsers/api-design-systems-json/index.cjs +0 -55
  108. package/src/parse/parsers/api-design-systems-json/index.mjs +0 -49
  109. package/src/parse/parsers/api-design-systems-yaml/index.cjs +0 -54
  110. package/src/parse/parsers/api-design-systems-yaml/index.mjs +0 -48
  111. package/types/parse/parsers/api-design-systems-json/index.d.ts +0 -21
  112. package/types/parse/parsers/api-design-systems-yaml/index.d.ts +0 -20
@@ -3,11 +3,13 @@
3
3
  var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
4
4
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
5
  exports.__esModule = true;
6
- exports.mutationReplacer = exports.default = void 0;
6
+ exports.default = void 0;
7
7
  var _ramda = require("ramda");
8
8
  var _ramdaAdjunct = require("ramda-adjunct");
9
+ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
9
10
  var _apidomCore = require("@speclynx/apidom-core");
10
11
  var _apidomError = require("@speclynx/apidom-error");
12
+ var _apidomTraverse = require("@speclynx/apidom-traverse");
11
13
  var _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
12
14
  var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-0");
13
15
  var _MaximumDereferenceDepthError = _interopRequireDefault(require("../../../errors/MaximumDereferenceDepthError.cjs"));
@@ -16,28 +18,13 @@ var url = _interopRequireWildcard(require("../../../util/url.cjs"));
16
18
  var _index = _interopRequireDefault(require("../../../parse/index.cjs"));
17
19
  var _Reference = _interopRequireDefault(require("../../../Reference.cjs"));
18
20
  var _util = require("../../util.cjs");
19
- // @ts-ignore
20
- const visitAsync = _apidomCore.visit[Symbol.for('nodejs.util.promisify.custom')];
21
-
22
21
  // initialize element identity manager
23
22
  const identityManager = new _apidomCore.IdentityManager();
24
23
 
25
24
  /**
26
- * Custom mutation replacer.
27
25
  * @public
28
26
  */
29
- const mutationReplacer = (newElement, oldElement, key, parent) => {
30
- if ((0, _apidomCore.isMemberElement)(parent)) {
31
- parent.value = newElement;
32
- } else if (Array.isArray(parent)) {
33
- parent[key] = newElement;
34
- }
35
- };
36
27
 
37
- /**
38
- * @public
39
- */
40
- exports.mutationReplacer = mutationReplacer;
41
28
  /**
42
29
  * @public
43
30
  */
@@ -91,7 +78,7 @@ class OpenAPI3_0DereferenceVisitor {
91
78
  // register new mutable reference with a refSet
92
79
  const mutableReference = new _Reference.default({
93
80
  uri: baseURI,
94
- value: (0, _apidomCore.cloneDeep)(parseResult),
81
+ value: (0, _apidomDatamodel.cloneDeep)(parseResult),
95
82
  depth: this.reference.depth + 1
96
83
  });
97
84
  refSet.add(mutableReference);
@@ -106,21 +93,25 @@ class OpenAPI3_0DereferenceVisitor {
106
93
  }
107
94
  return mutableReference;
108
95
  }
109
- toAncestorLineage(ancestors) {
96
+ toAncestorLineage(path) {
110
97
  /**
111
98
  * Compute full ancestors lineage.
112
99
  * Ancestors are flatten to unwrap all Element instances.
113
100
  */
114
- const directAncestors = new Set(ancestors.filter(_apidomCore.isElement));
101
+ const ancestorNodes = path.getAncestorNodes();
102
+ const directAncestors = new Set(ancestorNodes.filter(_apidomDatamodel.isElement));
115
103
  const ancestorsLineage = new _util.AncestorLineage(...this.ancestors, directAncestors);
116
104
  return [ancestorsLineage, directAncestors];
117
105
  }
118
- async ReferenceElement(referencingElement, key, parent, path, ancestors, link) {
106
+ async ReferenceElement(path) {
107
+ const referencingElement = path.node;
108
+
119
109
  // skip current referencing element as it's already been access
120
110
  if (this.indirections.includes(referencingElement)) {
121
- return false;
111
+ path.skip();
112
+ return;
122
113
  }
123
- const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
114
+ const [ancestorsLineage, directAncestors] = this.toAncestorLineage(path);
124
115
  const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(referencingElement.$ref));
125
116
  const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
126
117
  const isExternalReference = !isInternalReference;
@@ -128,12 +119,14 @@ class OpenAPI3_0DereferenceVisitor {
128
119
  // ignore resolving internal Reference Objects
129
120
  if (!this.options.resolve.internal && isInternalReference) {
130
121
  // skip traversing this reference element
131
- return false;
122
+ path.skip();
123
+ return;
132
124
  }
133
125
  // ignore resolving external Reference Objects
134
126
  if (!this.options.resolve.external && isExternalReference) {
135
127
  // skip traversing this reference element
136
- return false;
128
+ path.skip();
129
+ return;
137
130
  }
138
131
  const reference = await this.toReference((0, _apidomCore.toValue)(referencingElement.$ref));
139
132
  const $refBaseURI = url.resolve(retrievalURI, (0, _apidomCore.toValue)(referencingElement.$ref));
@@ -147,20 +140,21 @@ class OpenAPI3_0DereferenceVisitor {
147
140
  /**
148
141
  * Applying semantics to a referenced element if semantics are missing.
149
142
  */
150
- if ((0, _apidomCore.isPrimitiveElement)(referencedElement)) {
143
+ if ((0, _apidomDatamodel.isPrimitiveElement)(referencedElement)) {
151
144
  const referencedElementType = (0, _apidomCore.toValue)(referencingElement.meta.get('referenced-element'));
152
145
  const cacheKey = `${referencedElementType}-${(0, _apidomCore.toValue)(identityManager.identify(referencedElement))}`;
153
146
  if (this.refractCache.has(cacheKey)) {
154
147
  referencedElement = this.refractCache.get(cacheKey);
155
148
  } else if ((0, _apidomNsOpenapi.isReferenceLikeElement)(referencedElement)) {
156
149
  // handling indirect references
157
- referencedElement = _apidomNsOpenapi.ReferenceElement.refract(referencedElement);
158
- referencedElement.setMetaProperty('referenced-element', referencedElementType);
150
+ referencedElement = (0, _apidomNsOpenapi.refractReference)(referencedElement);
151
+ referencedElement.meta.set('referenced-element', referencedElementType);
159
152
  this.refractCache.set(cacheKey, referencedElement);
160
153
  } else {
161
154
  // handling direct references
162
- const ElementClass = this.namespace.getElementClass(referencedElementType);
163
- referencedElement = ElementClass.refract(referencedElement);
155
+ referencedElement = (0, _apidomNsOpenapi.refract)(referencedElement, {
156
+ element: referencedElementType
157
+ });
164
158
  this.refractCache.set(cacheKey, referencedElement);
165
159
  }
166
160
  }
@@ -181,15 +175,16 @@ class OpenAPI3_0DereferenceVisitor {
181
175
  if (this.options.dereference.circular === 'error') {
182
176
  throw new _apidomError.ApiDOMError('Circular reference detected');
183
177
  } else if (this.options.dereference.circular === 'replace') {
184
- const refElement = new _apidomCore.RefElement(referencedElement.id, {
178
+ const refElement = new _apidomDatamodel.RefElement(referencedElement.id, {
185
179
  type: 'reference',
186
180
  uri: reference.uri,
187
181
  $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
188
182
  });
189
183
  const replacer = this.options.dereference.strategyOpts['openapi-3-0']?.circularReplacer ?? this.options.dereference.circularReplacer;
190
184
  const replacement = replacer(refElement);
191
- link.replaceWith(replacement, mutationReplacer);
192
- return !parent ? replacement : false;
185
+ this.indirections.pop();
186
+ path.replaceWith(replacement);
187
+ return;
193
188
  }
194
189
  }
195
190
 
@@ -215,9 +210,8 @@ class OpenAPI3_0DereferenceVisitor {
215
210
  refractCache: this.refractCache,
216
211
  ancestors: ancestorsLineage
217
212
  });
218
- referencedElement = await visitAsync(referencedElement, visitor, {
219
- keyMap: _apidomNsOpenapi.keyMap,
220
- nodeTypeGetter: _apidomNsOpenapi.getNodeType
213
+ referencedElement = await (0, _apidomTraverse.traverseAsync)(referencedElement, visitor, {
214
+ mutable: true
221
215
  });
222
216
 
223
217
  // remove referencing reference from ancestors lineage
@@ -228,39 +222,37 @@ class OpenAPI3_0DereferenceVisitor {
228
222
  /**
229
223
  * Creating a new version of referenced element to avoid modifying the original one.
230
224
  */
231
- const mergedElement = (0, _apidomCore.cloneShallow)(referencedElement);
225
+ const mergedElement = (0, _apidomDatamodel.cloneShallow)(referencedElement);
232
226
  // assign unique id to merged element
233
- mergedElement.setMetaProperty('id', identityManager.generateId());
227
+ mergedElement.meta.set('id', identityManager.generateId());
234
228
  // annotate referenced element with info about original referencing element
235
- mergedElement.setMetaProperty('ref-fields', {
229
+ mergedElement.meta.set('ref-fields', {
236
230
  $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
237
231
  });
238
232
  // annotate fragment with info about origin
239
- mergedElement.setMetaProperty('ref-origin', reference.uri);
233
+ mergedElement.meta.set('ref-origin', reference.uri);
240
234
  // annotate fragment with info about referencing element
241
- mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
235
+ mergedElement.meta.set('ref-referencing-element-id', (0, _apidomDatamodel.cloneDeep)(identityManager.identify(referencingElement)));
242
236
 
243
237
  /**
244
238
  * Transclude referencing element with merged referenced element.
245
239
  */
246
- link.replaceWith(mergedElement, mutationReplacer);
247
-
248
- /**
249
- * We're at the root of the tree, so we're just replacing the entire tree.
250
- */
251
- return !parent ? mergedElement : false;
240
+ path.replaceWith(mergedElement);
252
241
  }
253
- async PathItemElement(referencingElement, key, parent, path, ancestors, link) {
242
+ async PathItemElement(path) {
243
+ const referencingElement = path.node;
244
+
254
245
  // ignore PathItemElement without $ref field
255
- if (!(0, _apidomCore.isStringElement)(referencingElement.$ref)) {
256
- return undefined;
246
+ if (!(0, _apidomDatamodel.isStringElement)(referencingElement.$ref)) {
247
+ return;
257
248
  }
258
249
 
259
250
  // skip current referencing element as it's already been access
260
251
  if (this.indirections.includes(referencingElement)) {
261
- return false;
252
+ path.skip();
253
+ return;
262
254
  }
263
- const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
255
+ const [ancestorsLineage, directAncestors] = this.toAncestorLineage(path);
264
256
  const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(referencingElement.$ref));
265
257
  const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
266
258
  const isExternalReference = !isInternalReference;
@@ -268,12 +260,12 @@ class OpenAPI3_0DereferenceVisitor {
268
260
  // ignore resolving internal Path Item Objects
269
261
  if (!this.options.resolve.internal && isInternalReference) {
270
262
  // skip traversing this Path Item element but traverse all it's child elements
271
- return undefined;
263
+ return;
272
264
  }
273
265
  // ignore resolving external Path Item Objects
274
266
  if (!this.options.resolve.external && isExternalReference) {
275
267
  // skip traversing this Path Item element but traverse all it's child elements
276
- return undefined;
268
+ return;
277
269
  }
278
270
  const reference = await this.toReference((0, _apidomCore.toValue)(referencingElement.$ref));
279
271
  const $refBaseURI = url.resolve(retrievalURI, (0, _apidomCore.toValue)(referencingElement.$ref));
@@ -292,7 +284,7 @@ class OpenAPI3_0DereferenceVisitor {
292
284
  if (this.refractCache.has(cacheKey)) {
293
285
  referencedElement = this.refractCache.get(cacheKey);
294
286
  } else {
295
- referencedElement = _apidomNsOpenapi.PathItemElement.refract(referencedElement);
287
+ referencedElement = (0, _apidomNsOpenapi.refractPathItem)(referencedElement);
296
288
  this.refractCache.set(cacheKey, referencedElement);
297
289
  }
298
290
  }
@@ -313,15 +305,16 @@ class OpenAPI3_0DereferenceVisitor {
313
305
  if (this.options.dereference.circular === 'error') {
314
306
  throw new _apidomError.ApiDOMError('Circular reference detected');
315
307
  } else if (this.options.dereference.circular === 'replace') {
316
- const refElement = new _apidomCore.RefElement(referencedElement.id, {
308
+ const refElement = new _apidomDatamodel.RefElement(referencedElement.id, {
317
309
  type: 'path-item',
318
310
  uri: reference.uri,
319
311
  $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
320
312
  });
321
313
  const replacer = this.options.dereference.strategyOpts['openapi-3-0']?.circularReplacer ?? this.options.dereference.circularReplacer;
322
314
  const replacement = replacer(refElement);
323
- link.replaceWith(replacement, mutationReplacer);
324
- return !parent ? replacement : undefined;
315
+ this.indirections.pop();
316
+ path.replaceWith(replacement);
317
+ return;
325
318
  }
326
319
  }
327
320
 
@@ -336,7 +329,7 @@ class OpenAPI3_0DereferenceVisitor {
336
329
  */
337
330
  const isNonEntryDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri;
338
331
  const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
339
- if ((isExternalReference || isNonEntryDocument || (0, _apidomNsOpenapi.isPathItemElement)(referencedElement) && (0, _apidomCore.isStringElement)(referencedElement.$ref) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
332
+ if ((isExternalReference || isNonEntryDocument || (0, _apidomNsOpenapi.isPathItemElement)(referencedElement) && (0, _apidomDatamodel.isStringElement)(referencedElement.$ref) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
340
333
  // append referencing reference to ancestors lineage
341
334
  directAncestors.add(referencingElement);
342
335
  const visitor = new OpenAPI3_0DereferenceVisitor({
@@ -347,9 +340,8 @@ class OpenAPI3_0DereferenceVisitor {
347
340
  refractCache: this.refractCache,
348
341
  ancestors: ancestorsLineage
349
342
  });
350
- referencedElement = await visitAsync(referencedElement, visitor, {
351
- keyMap: _apidomNsOpenapi.keyMap,
352
- nodeTypeGetter: _apidomNsOpenapi.getNodeType
343
+ referencedElement = await (0, _apidomTraverse.traverseAsync)(referencedElement, visitor, {
344
+ mutable: true
353
345
  });
354
346
 
355
347
  // remove referencing reference from ancestors lineage
@@ -361,9 +353,9 @@ class OpenAPI3_0DereferenceVisitor {
361
353
  * Creating a new version of Path Item by merging fields from referenced Path Item with referencing one.
362
354
  */
363
355
  if ((0, _apidomNsOpenapi.isPathItemElement)(referencedElement)) {
364
- const mergedElement = new _apidomNsOpenapi.PathItemElement([...referencedElement.content], (0, _apidomCore.cloneDeep)(referencedElement.meta), (0, _apidomCore.cloneDeep)(referencedElement.attributes));
356
+ const mergedElement = (0, _apidomDatamodel.cloneShallow)(referencedElement);
365
357
  // assign unique id to merged element
366
- mergedElement.setMetaProperty('id', identityManager.generateId());
358
+ mergedElement.meta.set('id', identityManager.generateId());
367
359
  // existing keywords from referencing PathItemElement overrides ones from referenced element
368
360
  referencingElement.forEach((value, keyElement, item) => {
369
361
  mergedElement.remove((0, _apidomCore.toValue)(keyElement));
@@ -372,38 +364,35 @@ class OpenAPI3_0DereferenceVisitor {
372
364
  mergedElement.remove('$ref');
373
365
 
374
366
  // annotate referenced element with info about original referencing element
375
- mergedElement.setMetaProperty('ref-fields', {
367
+ mergedElement.meta.set('ref-fields', {
376
368
  $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
377
369
  });
378
370
  // annotate referenced element with info about origin
379
- mergedElement.setMetaProperty('ref-origin', reference.uri);
371
+ mergedElement.meta.set('ref-origin', reference.uri);
380
372
  // annotate fragment with info about referencing element
381
- mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
373
+ mergedElement.meta.set('ref-referencing-element-id', (0, _apidomDatamodel.cloneDeep)(identityManager.identify(referencingElement)));
382
374
  referencedElement = mergedElement;
383
375
  }
384
376
 
385
377
  /**
386
378
  * Transclude referencing element with merged referenced element.
387
379
  */
388
- link.replaceWith(referencedElement, mutationReplacer);
389
-
390
- /**
391
- * We're at the root of the tree, so we're just replacing the entire tree.
392
- */
393
- return !parent ? referencedElement : undefined;
380
+ path.replaceWith(referencedElement);
394
381
  }
395
- async LinkElement(linkElement, key, parent, path, ancestors, link) {
382
+ async LinkElement(path) {
383
+ const linkElement = path.node;
384
+
396
385
  // ignore LinkElement without operationRef or operationId field
397
- if (!(0, _apidomCore.isStringElement)(linkElement.operationRef) && !(0, _apidomCore.isStringElement)(linkElement.operationId)) {
398
- return undefined;
386
+ if (!(0, _apidomDatamodel.isStringElement)(linkElement.operationRef) && !(0, _apidomDatamodel.isStringElement)(linkElement.operationId)) {
387
+ return;
399
388
  }
400
389
 
401
390
  // operationRef and operationId fields are mutually exclusive
402
- if ((0, _apidomCore.isStringElement)(linkElement.operationRef) && (0, _apidomCore.isStringElement)(linkElement.operationId)) {
391
+ if ((0, _apidomDatamodel.isStringElement)(linkElement.operationRef) && (0, _apidomDatamodel.isStringElement)(linkElement.operationId)) {
403
392
  throw new _apidomError.ApiDOMError('LinkElement operationRef and operationId fields are mutually exclusive.');
404
393
  }
405
394
  let operationElement;
406
- if ((0, _apidomCore.isStringElement)(linkElement.operationRef)) {
395
+ if ((0, _apidomDatamodel.isStringElement)(linkElement.operationRef)) {
407
396
  // possibly non-semantic referenced element
408
397
  const jsonPointer = _apidomJsonPointer.URIFragmentIdentifier.fromURIReference((0, _apidomCore.toValue)(linkElement.operationRef));
409
398
  const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(linkElement.operationRef));
@@ -413,73 +402,66 @@ class OpenAPI3_0DereferenceVisitor {
413
402
  // ignore resolving internal Operation Object reference
414
403
  if (!this.options.resolve.internal && isInternalReference) {
415
404
  // skip traversing this Link element but traverse all it's child elements
416
- return undefined;
405
+ return;
417
406
  }
418
407
  // ignore resolving external Operation Object reference
419
408
  if (!this.options.resolve.external && isExternalReference) {
420
409
  // skip traversing this Link element but traverse all it's child elements
421
- return undefined;
410
+ return;
422
411
  }
423
412
  const reference = await this.toReference((0, _apidomCore.toValue)(linkElement.operationRef));
424
413
  operationElement = (0, _apidomJsonPointer.evaluate)(reference.value.result, jsonPointer);
425
414
  // applying semantics to a referenced element
426
- if ((0, _apidomCore.isPrimitiveElement)(operationElement)) {
415
+ if ((0, _apidomDatamodel.isPrimitiveElement)(operationElement)) {
427
416
  const cacheKey = `operation-${(0, _apidomCore.toValue)(identityManager.identify(operationElement))}`;
428
417
  if (this.refractCache.has(cacheKey)) {
429
418
  operationElement = this.refractCache.get(cacheKey);
430
419
  } else {
431
- operationElement = _apidomNsOpenapi.OperationElement.refract(operationElement);
420
+ operationElement = (0, _apidomNsOpenapi.refractOperation)(operationElement);
432
421
  this.refractCache.set(cacheKey, operationElement);
433
422
  }
434
423
  }
435
424
  // create shallow clone to be able to annotate with metadata
436
- operationElement = (0, _apidomCore.cloneShallow)(operationElement);
425
+ operationElement = (0, _apidomDatamodel.cloneShallow)(operationElement);
437
426
  // annotate operation element with info about origin
438
- operationElement.setMetaProperty('ref-origin', reference.uri);
439
- const linkElementCopy = (0, _apidomCore.cloneShallow)(linkElement);
427
+ operationElement.meta.set('ref-origin', reference.uri);
428
+ const linkElementCopy = (0, _apidomDatamodel.cloneShallow)(linkElement);
440
429
  linkElementCopy.operationRef?.meta.set('operation', operationElement);
441
430
 
442
431
  /**
443
432
  * Transclude Link Object containing Operation Object in its meta.
444
433
  */
445
- link.replaceWith(linkElementCopy, mutationReplacer);
446
-
447
- /**
448
- * We're at the root of the tree, so we're just replacing the entire tree.
449
- */
450
- return !parent ? linkElementCopy : undefined;
434
+ path.replaceWith(linkElementCopy);
435
+ return;
451
436
  }
452
- if ((0, _apidomCore.isStringElement)(linkElement.operationId)) {
437
+ if ((0, _apidomDatamodel.isStringElement)(linkElement.operationId)) {
453
438
  const operationId = (0, _apidomCore.toValue)(linkElement.operationId);
454
439
  const reference = await this.toReference(url.unsanitize(this.reference.uri));
455
- operationElement = (0, _apidomCore.find)(e => (0, _apidomNsOpenapi.isOperationElement)(e) && (0, _apidomCore.isElement)(e.operationId) && e.operationId.equals(operationId), reference.value.result);
440
+ operationElement = (0, _apidomTraverse.find)(reference.value.result, e => (0, _apidomNsOpenapi.isOperationElement)(e) && (0, _apidomDatamodel.isElement)(e.operationId) && e.operationId.equals(operationId));
456
441
  // OperationElement not found by its operationId
457
442
  if ((0, _ramdaAdjunct.isUndefined)(operationElement)) {
458
443
  throw new _apidomError.ApiDOMError(`OperationElement(operationId=${operationId}) not found.`);
459
444
  }
460
- const linkElementCopy = (0, _apidomCore.cloneShallow)(linkElement);
445
+ const linkElementCopy = (0, _apidomDatamodel.cloneShallow)(linkElement);
461
446
  linkElementCopy.operationId?.meta.set('operation', operationElement);
462
447
 
463
448
  /**
464
449
  * Transclude Link Object containing Operation Object in its meta.
465
450
  */
466
- link.replaceWith(linkElementCopy, mutationReplacer);
467
-
468
- /**
469
- * We're at the root of the tree, so we're just replacing the entire tree.
470
- */
471
- return !parent ? linkElementCopy : undefined;
451
+ path.replaceWith(linkElementCopy);
452
+ return;
472
453
  }
473
- return undefined;
474
454
  }
475
- async ExampleElement(exampleElement, key, parent, path, ancestors, link) {
455
+ async ExampleElement(path) {
456
+ const exampleElement = path.node;
457
+
476
458
  // ignore ExampleElement without externalValue field
477
- if (!(0, _apidomCore.isStringElement)(exampleElement.externalValue)) {
478
- return undefined;
459
+ if (!(0, _apidomDatamodel.isStringElement)(exampleElement.externalValue)) {
460
+ return;
479
461
  }
480
462
 
481
463
  // value and externalValue fields are mutually exclusive
482
- if (exampleElement.hasKey('value') && (0, _apidomCore.isStringElement)(exampleElement.externalValue)) {
464
+ if (exampleElement.hasKey('value') && (0, _apidomDatamodel.isStringElement)(exampleElement.externalValue)) {
483
465
  throw new _apidomError.ApiDOMError('ExampleElement value and externalValue fields are mutually exclusive.');
484
466
  }
485
467
  const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(exampleElement.externalValue));
@@ -489,31 +471,26 @@ class OpenAPI3_0DereferenceVisitor {
489
471
  // ignore resolving external Example Objects
490
472
  if (!this.options.resolve.internal && isInternalReference) {
491
473
  // skip traversing this Example element but traverse all it's child elements
492
- return undefined;
474
+ return;
493
475
  }
494
476
  // ignore resolving external Example Objects
495
477
  if (!this.options.resolve.external && isExternalReference) {
496
478
  // skip traversing this Example element but traverse all it's child elements
497
- return undefined;
479
+ return;
498
480
  }
499
481
  const reference = await this.toReference((0, _apidomCore.toValue)(exampleElement.externalValue));
500
482
 
501
483
  // shallow clone of the referenced element
502
- const valueElement = (0, _apidomCore.cloneShallow)(reference.value.result);
484
+ const valueElement = (0, _apidomDatamodel.cloneShallow)(reference.value.result);
503
485
  // annotate operation element with info about origin
504
- valueElement.setMetaProperty('ref-origin', reference.uri);
505
- const exampleElementCopy = (0, _apidomCore.cloneShallow)(exampleElement);
486
+ valueElement.meta.set('ref-origin', reference.uri);
487
+ const exampleElementCopy = (0, _apidomDatamodel.cloneShallow)(exampleElement);
506
488
  exampleElementCopy.value = valueElement;
507
489
 
508
490
  /**
509
491
  * Transclude Example Object containing external value.
510
492
  */
511
- link.replaceWith(exampleElementCopy, mutationReplacer);
512
-
513
- /**
514
- * We're at the root of the tree, so we're just replacing the entire tree.
515
- */
516
- return !parent ? exampleElementCopy : undefined;
493
+ path.replaceWith(exampleElementCopy);
517
494
  }
518
495
  }
519
496
  var _default = exports.default = OpenAPI3_0DereferenceVisitor;