@speclynx/apidom-reference 4.13.0 → 4.14.0
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 +6 -0
- package/README.md +45 -3
- package/dist/apidom-reference.browser.js +1333 -167
- package/dist/apidom-reference.browser.min.js +1 -1
- package/package.json +28 -28
- package/src/bundle/strategies/openapi-2/visitor.cjs +8 -16
- package/src/bundle/strategies/openapi-2/visitor.mjs +8 -16
- package/src/bundle/strategies/openapi-3-0/visitor.cjs +10 -18
- package/src/bundle/strategies/openapi-3-0/visitor.mjs +10 -18
- package/src/bundle/strategies/openapi-3-1/index.cjs +59 -2
- package/src/bundle/strategies/openapi-3-1/index.mjs +54 -2
- package/src/bundle/strategies/openapi-3-1/visitor.cjs +811 -0
- package/src/bundle/strategies/openapi-3-1/visitor.mjs +803 -0
- package/src/util/url.cjs +26 -4
- package/src/util/url.mjs +23 -2
- package/types/apidom-reference.d.ts +10 -0
- package/types/bundle/strategies/openapi-2/visitor.d.ts +2 -2
- package/types/bundle/strategies/openapi-3-0/visitor.d.ts +2 -2
- package/types/bundle/strategies/openapi-3-1/index.d.ts +6 -1
- package/types/bundle/strategies/openapi-3-1/visitor.d.ts +141 -0
- package/types/util/url.d.ts +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speclynx/apidom-reference",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.14.0",
|
|
4
4
|
"description": "Advanced algorithms for semantic ApiDOM manipulations like dereferencing or resolution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apidom",
|
|
@@ -289,32 +289,32 @@
|
|
|
289
289
|
"license": "Apache-2.0",
|
|
290
290
|
"dependencies": {
|
|
291
291
|
"@babel/runtime-corejs3": "^8.0.0",
|
|
292
|
-
"@speclynx/apidom-core": "4.
|
|
293
|
-
"@speclynx/apidom-datamodel": "4.
|
|
294
|
-
"@speclynx/apidom-error": "4.
|
|
295
|
-
"@speclynx/apidom-json-pointer": "4.
|
|
296
|
-
"@speclynx/apidom-ns-arazzo-1": "4.
|
|
297
|
-
"@speclynx/apidom-ns-asyncapi-2": "4.
|
|
298
|
-
"@speclynx/apidom-ns-json-schema-2020-12": "4.
|
|
299
|
-
"@speclynx/apidom-ns-openapi-2": "4.
|
|
300
|
-
"@speclynx/apidom-ns-openapi-3-0": "4.
|
|
301
|
-
"@speclynx/apidom-ns-openapi-3-1": "4.
|
|
302
|
-
"@speclynx/apidom-ns-overlay-1": "4.
|
|
303
|
-
"@speclynx/apidom-parser-adapter-arazzo-json-1": "4.
|
|
304
|
-
"@speclynx/apidom-parser-adapter-arazzo-yaml-1": "4.
|
|
305
|
-
"@speclynx/apidom-parser-adapter-asyncapi-json-2": "4.
|
|
306
|
-
"@speclynx/apidom-parser-adapter-asyncapi-yaml-2": "4.
|
|
307
|
-
"@speclynx/apidom-parser-adapter-json": "4.
|
|
308
|
-
"@speclynx/apidom-parser-adapter-openapi-json-2": "4.
|
|
309
|
-
"@speclynx/apidom-parser-adapter-openapi-json-3-0": "4.
|
|
310
|
-
"@speclynx/apidom-parser-adapter-openapi-json-3-1": "4.
|
|
311
|
-
"@speclynx/apidom-parser-adapter-openapi-yaml-2": "4.
|
|
312
|
-
"@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "4.
|
|
313
|
-
"@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "4.
|
|
314
|
-
"@speclynx/apidom-parser-adapter-overlay-json-1": "4.
|
|
315
|
-
"@speclynx/apidom-parser-adapter-overlay-yaml-1": "4.
|
|
316
|
-
"@speclynx/apidom-parser-adapter-yaml-1-2": "4.
|
|
317
|
-
"@speclynx/apidom-traverse": "4.
|
|
292
|
+
"@speclynx/apidom-core": "4.14.0",
|
|
293
|
+
"@speclynx/apidom-datamodel": "4.14.0",
|
|
294
|
+
"@speclynx/apidom-error": "4.14.0",
|
|
295
|
+
"@speclynx/apidom-json-pointer": "4.14.0",
|
|
296
|
+
"@speclynx/apidom-ns-arazzo-1": "4.14.0",
|
|
297
|
+
"@speclynx/apidom-ns-asyncapi-2": "4.14.0",
|
|
298
|
+
"@speclynx/apidom-ns-json-schema-2020-12": "4.14.0",
|
|
299
|
+
"@speclynx/apidom-ns-openapi-2": "4.14.0",
|
|
300
|
+
"@speclynx/apidom-ns-openapi-3-0": "4.14.0",
|
|
301
|
+
"@speclynx/apidom-ns-openapi-3-1": "4.14.0",
|
|
302
|
+
"@speclynx/apidom-ns-overlay-1": "4.14.0",
|
|
303
|
+
"@speclynx/apidom-parser-adapter-arazzo-json-1": "4.14.0",
|
|
304
|
+
"@speclynx/apidom-parser-adapter-arazzo-yaml-1": "4.14.0",
|
|
305
|
+
"@speclynx/apidom-parser-adapter-asyncapi-json-2": "4.14.0",
|
|
306
|
+
"@speclynx/apidom-parser-adapter-asyncapi-yaml-2": "4.14.0",
|
|
307
|
+
"@speclynx/apidom-parser-adapter-json": "4.14.0",
|
|
308
|
+
"@speclynx/apidom-parser-adapter-openapi-json-2": "4.14.0",
|
|
309
|
+
"@speclynx/apidom-parser-adapter-openapi-json-3-0": "4.14.0",
|
|
310
|
+
"@speclynx/apidom-parser-adapter-openapi-json-3-1": "4.14.0",
|
|
311
|
+
"@speclynx/apidom-parser-adapter-openapi-yaml-2": "4.14.0",
|
|
312
|
+
"@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "4.14.0",
|
|
313
|
+
"@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "4.14.0",
|
|
314
|
+
"@speclynx/apidom-parser-adapter-overlay-json-1": "4.14.0",
|
|
315
|
+
"@speclynx/apidom-parser-adapter-overlay-yaml-1": "4.14.0",
|
|
316
|
+
"@speclynx/apidom-parser-adapter-yaml-1-2": "4.14.0",
|
|
317
|
+
"@speclynx/apidom-traverse": "4.14.0",
|
|
318
318
|
"@swaggerexpert/arazzo-runtime-expression": "^2.0.3",
|
|
319
319
|
"axios": "^1.18.0",
|
|
320
320
|
"picomatch": "^4.0.4",
|
|
@@ -336,5 +336,5 @@
|
|
|
336
336
|
"README.md",
|
|
337
337
|
"CHANGELOG.md"
|
|
338
338
|
],
|
|
339
|
-
"gitHead": "
|
|
339
|
+
"gitHead": "ae231056cc8865f2467fa97ca456975301bbe265"
|
|
340
340
|
}
|
|
@@ -177,11 +177,11 @@ class OpenAPI2BundleVisitor {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
/**
|
|
180
|
-
* Normalizes a self-
|
|
180
|
+
* Normalizes a self-reference (e.g. `./root.json#/definitions/Pet`)
|
|
181
181
|
* to a bare fragment (`#/definitions/Pet`) so the bundled document stays
|
|
182
182
|
* transferable. Bare fragments are returned unchanged.
|
|
183
183
|
*/
|
|
184
|
-
|
|
184
|
+
normalizeSelfReference(ref) {
|
|
185
185
|
return ref.startsWith('#') ? ref : url.getHash(ref);
|
|
186
186
|
}
|
|
187
187
|
|
|
@@ -262,16 +262,8 @@ class OpenAPI2BundleVisitor {
|
|
|
262
262
|
*/
|
|
263
263
|
basenameOf(jsonPointer, baseURI) {
|
|
264
264
|
const tokens = (0, _apidomJsonPointer.parse)(jsonPointer).tree;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const lastSlash = baseURI.lastIndexOf('/');
|
|
268
|
-
const lastDot = baseURI.lastIndexOf('.');
|
|
269
|
-
const fileName = baseURI.slice(lastSlash + 1);
|
|
270
|
-
// strip the extension only when the last dot belongs to the file name
|
|
271
|
-
candidate = lastDot > lastSlash ? baseURI.slice(lastSlash + 1, lastDot) : fileName;
|
|
272
|
-
}
|
|
273
|
-
if (candidate === '') candidate = 'Schema';
|
|
274
|
-
return candidate;
|
|
265
|
+
const lastToken = tokens.length > 0 ? tokens[tokens.length - 1] : '';
|
|
266
|
+
return lastToken || url.getBasename(baseURI) || 'Schema';
|
|
275
267
|
}
|
|
276
268
|
|
|
277
269
|
/**
|
|
@@ -326,9 +318,9 @@ class OpenAPI2BundleVisitor {
|
|
|
326
318
|
const isInternalReference = this.entryURI === retrievalURI;
|
|
327
319
|
const isExternalReference = !isInternalReference;
|
|
328
320
|
if (isInternalReference) {
|
|
329
|
-
// normalize self-
|
|
321
|
+
// normalize self-references to a bare fragment so the bundled
|
|
330
322
|
// document stays transferable; bare fragments are left untouched
|
|
331
|
-
referencingElement.set('$ref', this.
|
|
323
|
+
referencingElement.set('$ref', this.normalizeSelfReference($ref));
|
|
332
324
|
path.skip();
|
|
333
325
|
return;
|
|
334
326
|
}
|
|
@@ -485,9 +477,9 @@ class OpenAPI2BundleVisitor {
|
|
|
485
477
|
const isInternalReference = this.entryURI === retrievalURI;
|
|
486
478
|
const isExternalReference = !isInternalReference;
|
|
487
479
|
if (isInternalReference) {
|
|
488
|
-
// normalize self-
|
|
480
|
+
// normalize self-references to a bare fragment so the bundled
|
|
489
481
|
// document stays transferable; bare fragments are left untouched
|
|
490
|
-
pathItemElement.set('$ref', this.
|
|
482
|
+
pathItemElement.set('$ref', this.normalizeSelfReference($ref));
|
|
491
483
|
return;
|
|
492
484
|
}
|
|
493
485
|
|
|
@@ -169,11 +169,11 @@ class OpenAPI2BundleVisitor {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
/**
|
|
172
|
-
* Normalizes a self-
|
|
172
|
+
* Normalizes a self-reference (e.g. `./root.json#/definitions/Pet`)
|
|
173
173
|
* to a bare fragment (`#/definitions/Pet`) so the bundled document stays
|
|
174
174
|
* transferable. Bare fragments are returned unchanged.
|
|
175
175
|
*/
|
|
176
|
-
|
|
176
|
+
normalizeSelfReference(ref) {
|
|
177
177
|
return ref.startsWith('#') ? ref : url.getHash(ref);
|
|
178
178
|
}
|
|
179
179
|
|
|
@@ -254,16 +254,8 @@ class OpenAPI2BundleVisitor {
|
|
|
254
254
|
*/
|
|
255
255
|
basenameOf(jsonPointer, baseURI) {
|
|
256
256
|
const tokens = parseJSONPointer(jsonPointer).tree;
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const lastSlash = baseURI.lastIndexOf('/');
|
|
260
|
-
const lastDot = baseURI.lastIndexOf('.');
|
|
261
|
-
const fileName = baseURI.slice(lastSlash + 1);
|
|
262
|
-
// strip the extension only when the last dot belongs to the file name
|
|
263
|
-
candidate = lastDot > lastSlash ? baseURI.slice(lastSlash + 1, lastDot) : fileName;
|
|
264
|
-
}
|
|
265
|
-
if (candidate === '') candidate = 'Schema';
|
|
266
|
-
return candidate;
|
|
257
|
+
const lastToken = tokens.length > 0 ? tokens[tokens.length - 1] : '';
|
|
258
|
+
return lastToken || url.getBasename(baseURI) || 'Schema';
|
|
267
259
|
}
|
|
268
260
|
|
|
269
261
|
/**
|
|
@@ -318,9 +310,9 @@ class OpenAPI2BundleVisitor {
|
|
|
318
310
|
const isInternalReference = this.entryURI === retrievalURI;
|
|
319
311
|
const isExternalReference = !isInternalReference;
|
|
320
312
|
if (isInternalReference) {
|
|
321
|
-
// normalize self-
|
|
313
|
+
// normalize self-references to a bare fragment so the bundled
|
|
322
314
|
// document stays transferable; bare fragments are left untouched
|
|
323
|
-
referencingElement.set('$ref', this.
|
|
315
|
+
referencingElement.set('$ref', this.normalizeSelfReference($ref));
|
|
324
316
|
path.skip();
|
|
325
317
|
return;
|
|
326
318
|
}
|
|
@@ -477,9 +469,9 @@ class OpenAPI2BundleVisitor {
|
|
|
477
469
|
const isInternalReference = this.entryURI === retrievalURI;
|
|
478
470
|
const isExternalReference = !isInternalReference;
|
|
479
471
|
if (isInternalReference) {
|
|
480
|
-
// normalize self-
|
|
472
|
+
// normalize self-references to a bare fragment so the bundled
|
|
481
473
|
// document stays transferable; bare fragments are left untouched
|
|
482
|
-
pathItemElement.set('$ref', this.
|
|
474
|
+
pathItemElement.set('$ref', this.normalizeSelfReference($ref));
|
|
483
475
|
return;
|
|
484
476
|
}
|
|
485
477
|
|
|
@@ -188,11 +188,11 @@ class OpenAPI3_0BundleVisitor {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
/**
|
|
191
|
-
* Normalizes a self-
|
|
191
|
+
* Normalizes a self-reference (e.g. `./root.json#/components/schemas/Pet`)
|
|
192
192
|
* to a bare fragment (`#/components/schemas/Pet`) so the bundled document stays
|
|
193
193
|
* transferable. Bare fragments are returned unchanged.
|
|
194
194
|
*/
|
|
195
|
-
|
|
195
|
+
normalizeSelfReference(ref) {
|
|
196
196
|
return ref.startsWith('#') ? ref : url.getHash(ref);
|
|
197
197
|
}
|
|
198
198
|
|
|
@@ -278,16 +278,8 @@ class OpenAPI3_0BundleVisitor {
|
|
|
278
278
|
*/
|
|
279
279
|
basenameOf(jsonPointer, baseURI) {
|
|
280
280
|
const tokens = (0, _apidomJsonPointer.parse)(jsonPointer).tree;
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const lastSlash = baseURI.lastIndexOf('/');
|
|
284
|
-
const lastDot = baseURI.lastIndexOf('.');
|
|
285
|
-
const fileName = baseURI.slice(lastSlash + 1);
|
|
286
|
-
// strip the extension only when the last dot belongs to the file name
|
|
287
|
-
candidate = lastDot > lastSlash ? baseURI.slice(lastSlash + 1, lastDot) : fileName;
|
|
288
|
-
}
|
|
289
|
-
if (candidate === '') candidate = 'Schema';
|
|
290
|
-
return candidate;
|
|
281
|
+
const lastToken = tokens.length > 0 ? tokens[tokens.length - 1] : '';
|
|
282
|
+
return lastToken || url.getBasename(baseURI) || 'Schema';
|
|
291
283
|
}
|
|
292
284
|
|
|
293
285
|
/**
|
|
@@ -337,9 +329,9 @@ class OpenAPI3_0BundleVisitor {
|
|
|
337
329
|
const isInternalReference = this.entryURI === retrievalURI;
|
|
338
330
|
const isExternalReference = !isInternalReference;
|
|
339
331
|
if (isInternalReference) {
|
|
340
|
-
// normalize self-
|
|
332
|
+
// normalize self-references to a bare fragment so the bundled
|
|
341
333
|
// document stays transferable; bare fragments are left untouched
|
|
342
|
-
referencingElement.set('$ref', this.
|
|
334
|
+
referencingElement.set('$ref', this.normalizeSelfReference($ref));
|
|
343
335
|
path.skip();
|
|
344
336
|
return;
|
|
345
337
|
}
|
|
@@ -481,9 +473,9 @@ class OpenAPI3_0BundleVisitor {
|
|
|
481
473
|
const isInternalReference = this.entryURI === retrievalURI;
|
|
482
474
|
const isExternalReference = !isInternalReference;
|
|
483
475
|
if (isInternalReference) {
|
|
484
|
-
// normalize self-
|
|
476
|
+
// normalize self-references to a bare fragment so the bundled
|
|
485
477
|
// document stays transferable; bare fragments are left untouched
|
|
486
|
-
pathItemElement.set('$ref', this.
|
|
478
|
+
pathItemElement.set('$ref', this.normalizeSelfReference($ref));
|
|
487
479
|
return;
|
|
488
480
|
}
|
|
489
481
|
|
|
@@ -628,9 +620,9 @@ class OpenAPI3_0BundleVisitor {
|
|
|
628
620
|
const retrievalURI = this.toBaseURI(operationRef);
|
|
629
621
|
const isInternalReference = this.entryURI === retrievalURI;
|
|
630
622
|
if (isInternalReference) {
|
|
631
|
-
// normalize self-
|
|
623
|
+
// normalize a self-reference operationRef to a bare fragment so the bundled
|
|
632
624
|
// document stays transferable; bare fragments are left untouched
|
|
633
|
-
linkElement.set('operationRef', this.
|
|
625
|
+
linkElement.set('operationRef', this.normalizeSelfReference(operationRef));
|
|
634
626
|
return;
|
|
635
627
|
}
|
|
636
628
|
|
|
@@ -180,11 +180,11 @@ class OpenAPI3_0BundleVisitor {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
|
-
* Normalizes a self-
|
|
183
|
+
* Normalizes a self-reference (e.g. `./root.json#/components/schemas/Pet`)
|
|
184
184
|
* to a bare fragment (`#/components/schemas/Pet`) so the bundled document stays
|
|
185
185
|
* transferable. Bare fragments are returned unchanged.
|
|
186
186
|
*/
|
|
187
|
-
|
|
187
|
+
normalizeSelfReference(ref) {
|
|
188
188
|
return ref.startsWith('#') ? ref : url.getHash(ref);
|
|
189
189
|
}
|
|
190
190
|
|
|
@@ -270,16 +270,8 @@ class OpenAPI3_0BundleVisitor {
|
|
|
270
270
|
*/
|
|
271
271
|
basenameOf(jsonPointer, baseURI) {
|
|
272
272
|
const tokens = parseJSONPointer(jsonPointer).tree;
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const lastSlash = baseURI.lastIndexOf('/');
|
|
276
|
-
const lastDot = baseURI.lastIndexOf('.');
|
|
277
|
-
const fileName = baseURI.slice(lastSlash + 1);
|
|
278
|
-
// strip the extension only when the last dot belongs to the file name
|
|
279
|
-
candidate = lastDot > lastSlash ? baseURI.slice(lastSlash + 1, lastDot) : fileName;
|
|
280
|
-
}
|
|
281
|
-
if (candidate === '') candidate = 'Schema';
|
|
282
|
-
return candidate;
|
|
273
|
+
const lastToken = tokens.length > 0 ? tokens[tokens.length - 1] : '';
|
|
274
|
+
return lastToken || url.getBasename(baseURI) || 'Schema';
|
|
283
275
|
}
|
|
284
276
|
|
|
285
277
|
/**
|
|
@@ -329,9 +321,9 @@ class OpenAPI3_0BundleVisitor {
|
|
|
329
321
|
const isInternalReference = this.entryURI === retrievalURI;
|
|
330
322
|
const isExternalReference = !isInternalReference;
|
|
331
323
|
if (isInternalReference) {
|
|
332
|
-
// normalize self-
|
|
324
|
+
// normalize self-references to a bare fragment so the bundled
|
|
333
325
|
// document stays transferable; bare fragments are left untouched
|
|
334
|
-
referencingElement.set('$ref', this.
|
|
326
|
+
referencingElement.set('$ref', this.normalizeSelfReference($ref));
|
|
335
327
|
path.skip();
|
|
336
328
|
return;
|
|
337
329
|
}
|
|
@@ -473,9 +465,9 @@ class OpenAPI3_0BundleVisitor {
|
|
|
473
465
|
const isInternalReference = this.entryURI === retrievalURI;
|
|
474
466
|
const isExternalReference = !isInternalReference;
|
|
475
467
|
if (isInternalReference) {
|
|
476
|
-
// normalize self-
|
|
468
|
+
// normalize self-references to a bare fragment so the bundled
|
|
477
469
|
// document stays transferable; bare fragments are left untouched
|
|
478
|
-
pathItemElement.set('$ref', this.
|
|
470
|
+
pathItemElement.set('$ref', this.normalizeSelfReference($ref));
|
|
479
471
|
return;
|
|
480
472
|
}
|
|
481
473
|
|
|
@@ -620,9 +612,9 @@ class OpenAPI3_0BundleVisitor {
|
|
|
620
612
|
const retrievalURI = this.toBaseURI(operationRef);
|
|
621
613
|
const isInternalReference = this.entryURI === retrievalURI;
|
|
622
614
|
if (isInternalReference) {
|
|
623
|
-
// normalize self-
|
|
615
|
+
// normalize a self-reference operationRef to a bare fragment so the bundled
|
|
624
616
|
// document stays transferable; bare fragments are left untouched
|
|
625
|
-
linkElement.set('operationRef', this.
|
|
617
|
+
linkElement.set('operationRef', this.normalizeSelfReference(operationRef));
|
|
626
618
|
return;
|
|
627
619
|
}
|
|
628
620
|
|
|
@@ -4,9 +4,20 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
Object.defineProperty(exports, "OpenAPI3_1BundleVisitor", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _visitor.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
7
13
|
exports.default = void 0;
|
|
14
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
15
|
+
var _apidomTraverse = require("@speclynx/apidom-traverse");
|
|
8
16
|
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-1");
|
|
17
|
+
var _Reference = _interopRequireDefault(require("../../../Reference.cjs"));
|
|
18
|
+
var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
|
|
9
19
|
var _BundleStrategy = _interopRequireDefault(require("../BundleStrategy.cjs"));
|
|
20
|
+
var _visitor = _interopRequireDefault(require("./visitor.cjs"));
|
|
10
21
|
/**
|
|
11
22
|
* @public
|
|
12
23
|
*/
|
|
@@ -30,8 +41,54 @@ class OpenAPI3_1BundleStrategy extends _BundleStrategy.default {
|
|
|
30
41
|
// assert by inspecting ApiDOM
|
|
31
42
|
return (0, _apidomNsOpenapi.isOpenApi3_1Element)(file.parseResult?.result);
|
|
32
43
|
}
|
|
33
|
-
async bundle(file) {
|
|
34
|
-
|
|
44
|
+
async bundle(file, options) {
|
|
45
|
+
const immutableRefSet = options.bundle.refSet ?? new _ReferenceSet.default();
|
|
46
|
+
const mutableRefSet = new _ReferenceSet.default();
|
|
47
|
+
let refSet = immutableRefSet;
|
|
48
|
+
let reference;
|
|
49
|
+
|
|
50
|
+
// determine the initial reference
|
|
51
|
+
if (!immutableRefSet.has(file.uri)) {
|
|
52
|
+
reference = new _Reference.default({
|
|
53
|
+
uri: file.uri,
|
|
54
|
+
value: file.parseResult
|
|
55
|
+
});
|
|
56
|
+
immutableRefSet.add(reference);
|
|
57
|
+
} else {
|
|
58
|
+
// pre-computed refSet was provided as configuration option
|
|
59
|
+
reference = immutableRefSet.find(ref => ref.uri === file.uri);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Clone refSet due the bundling process being mutable.
|
|
64
|
+
* We don't want to mutate the original refSet and the references.
|
|
65
|
+
*/
|
|
66
|
+
if (options.bundle.immutable) {
|
|
67
|
+
immutableRefSet.refs.map(ref => new _Reference.default({
|
|
68
|
+
...ref,
|
|
69
|
+
value: (0, _apidomDatamodel.cloneDeep)(ref.value)
|
|
70
|
+
})).forEach(ref => mutableRefSet.add(ref));
|
|
71
|
+
reference = mutableRefSet.find(ref => ref.uri === file.uri);
|
|
72
|
+
refSet = mutableRefSet;
|
|
73
|
+
}
|
|
74
|
+
const visitor = new _visitor.default({
|
|
75
|
+
reference: reference,
|
|
76
|
+
options
|
|
77
|
+
});
|
|
78
|
+
await (0, _apidomTraverse.traverseAsync)(refSet.rootRef.value, visitor, {
|
|
79
|
+
mutable: true
|
|
80
|
+
});
|
|
81
|
+
const parseResult = reference.value;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Release all memory if this refSet was not provided as a configuration option.
|
|
85
|
+
* If provided as configuration option, then provider is responsible for cleanup.
|
|
86
|
+
*/
|
|
87
|
+
if (options.bundle.refSet === null) {
|
|
88
|
+
immutableRefSet.clean();
|
|
89
|
+
}
|
|
90
|
+
mutableRefSet.clean();
|
|
91
|
+
return parseResult;
|
|
35
92
|
}
|
|
36
93
|
}
|
|
37
94
|
var _default = exports.default = OpenAPI3_1BundleStrategy;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { cloneDeep } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import { traverseAsync } from '@speclynx/apidom-traverse';
|
|
1
3
|
import { mediaTypes, isOpenApi3_1Element } from '@speclynx/apidom-ns-openapi-3-1';
|
|
4
|
+
import Reference from "../../../Reference.mjs";
|
|
5
|
+
import ReferenceSet from "../../../ReferenceSet.mjs";
|
|
2
6
|
import BundleStrategy from "../BundleStrategy.mjs";
|
|
7
|
+
import OpenAPI3_1BundleVisitor from "./visitor.mjs";
|
|
3
8
|
/**
|
|
4
9
|
* @public
|
|
5
10
|
*/
|
|
@@ -22,8 +27,55 @@ class OpenAPI3_1BundleStrategy extends BundleStrategy {
|
|
|
22
27
|
// assert by inspecting ApiDOM
|
|
23
28
|
return isOpenApi3_1Element(file.parseResult?.result);
|
|
24
29
|
}
|
|
25
|
-
async bundle(file) {
|
|
26
|
-
|
|
30
|
+
async bundle(file, options) {
|
|
31
|
+
const immutableRefSet = options.bundle.refSet ?? new ReferenceSet();
|
|
32
|
+
const mutableRefSet = new ReferenceSet();
|
|
33
|
+
let refSet = immutableRefSet;
|
|
34
|
+
let reference;
|
|
35
|
+
|
|
36
|
+
// determine the initial reference
|
|
37
|
+
if (!immutableRefSet.has(file.uri)) {
|
|
38
|
+
reference = new Reference({
|
|
39
|
+
uri: file.uri,
|
|
40
|
+
value: file.parseResult
|
|
41
|
+
});
|
|
42
|
+
immutableRefSet.add(reference);
|
|
43
|
+
} else {
|
|
44
|
+
// pre-computed refSet was provided as configuration option
|
|
45
|
+
reference = immutableRefSet.find(ref => ref.uri === file.uri);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Clone refSet due the bundling process being mutable.
|
|
50
|
+
* We don't want to mutate the original refSet and the references.
|
|
51
|
+
*/
|
|
52
|
+
if (options.bundle.immutable) {
|
|
53
|
+
immutableRefSet.refs.map(ref => new Reference({
|
|
54
|
+
...ref,
|
|
55
|
+
value: cloneDeep(ref.value)
|
|
56
|
+
})).forEach(ref => mutableRefSet.add(ref));
|
|
57
|
+
reference = mutableRefSet.find(ref => ref.uri === file.uri);
|
|
58
|
+
refSet = mutableRefSet;
|
|
59
|
+
}
|
|
60
|
+
const visitor = new OpenAPI3_1BundleVisitor({
|
|
61
|
+
reference: reference,
|
|
62
|
+
options
|
|
63
|
+
});
|
|
64
|
+
await traverseAsync(refSet.rootRef.value, visitor, {
|
|
65
|
+
mutable: true
|
|
66
|
+
});
|
|
67
|
+
const parseResult = reference.value;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Release all memory if this refSet was not provided as a configuration option.
|
|
71
|
+
* If provided as configuration option, then provider is responsible for cleanup.
|
|
72
|
+
*/
|
|
73
|
+
if (options.bundle.refSet === null) {
|
|
74
|
+
immutableRefSet.clean();
|
|
75
|
+
}
|
|
76
|
+
mutableRefSet.clean();
|
|
77
|
+
return parseResult;
|
|
27
78
|
}
|
|
28
79
|
}
|
|
80
|
+
export { OpenAPI3_1BundleVisitor };
|
|
29
81
|
export default OpenAPI3_1BundleStrategy;
|