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