@speclynx/apidom-reference 4.12.1 → 4.13.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 +54 -1
- package/dist/apidom-reference.browser.js +945 -51
- package/dist/apidom-reference.browser.min.js +1 -1
- package/package.json +33 -28
- package/src/bundle/strategies/openapi-2/index.cjs +94 -0
- package/src/bundle/strategies/openapi-2/index.mjs +81 -0
- package/src/bundle/strategies/openapi-2/visitor.cjs +567 -0
- package/src/bundle/strategies/openapi-2/visitor.mjs +559 -0
- package/src/configuration/saturated.cjs +12 -11
- package/src/configuration/saturated.mjs +2 -1
- package/types/bundle/strategies/openapi-2/index.d.ts +31 -0
- package/types/bundle/strategies/openapi-2/visitor.d.ts +131 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speclynx/apidom-reference",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"description": "Advanced algorithms for semantic ApiDOM manipulations like dereferencing or resolution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apidom",
|
|
@@ -249,6 +249,11 @@
|
|
|
249
249
|
"require": "./src/dereference/strategies/openapi-3-1/selectors/uri.cjs",
|
|
250
250
|
"types": "./types/dereference/strategies/openapi-3-1/selectors/uri.d.ts"
|
|
251
251
|
},
|
|
252
|
+
"./bundle/strategies/openapi-2": {
|
|
253
|
+
"import": "./src/bundle/strategies/openapi-2/index.mjs",
|
|
254
|
+
"require": "./src/bundle/strategies/openapi-2/index.cjs",
|
|
255
|
+
"types": "./types/bundle/strategies/openapi-2/index.d.ts"
|
|
256
|
+
},
|
|
252
257
|
"./bundle/strategies/openapi-3-0": {
|
|
253
258
|
"import": "./src/bundle/strategies/openapi-3-0/index.mjs",
|
|
254
259
|
"require": "./src/bundle/strategies/openapi-3-0/index.cjs",
|
|
@@ -284,32 +289,32 @@
|
|
|
284
289
|
"license": "Apache-2.0",
|
|
285
290
|
"dependencies": {
|
|
286
291
|
"@babel/runtime-corejs3": "^8.0.0",
|
|
287
|
-
"@speclynx/apidom-core": "4.
|
|
288
|
-
"@speclynx/apidom-datamodel": "4.
|
|
289
|
-
"@speclynx/apidom-error": "4.
|
|
290
|
-
"@speclynx/apidom-json-pointer": "4.
|
|
291
|
-
"@speclynx/apidom-ns-arazzo-1": "4.
|
|
292
|
-
"@speclynx/apidom-ns-asyncapi-2": "4.
|
|
293
|
-
"@speclynx/apidom-ns-json-schema-2020-12": "4.
|
|
294
|
-
"@speclynx/apidom-ns-openapi-2": "4.
|
|
295
|
-
"@speclynx/apidom-ns-openapi-3-0": "4.
|
|
296
|
-
"@speclynx/apidom-ns-openapi-3-1": "4.
|
|
297
|
-
"@speclynx/apidom-ns-overlay-1": "4.
|
|
298
|
-
"@speclynx/apidom-parser-adapter-arazzo-json-1": "4.
|
|
299
|
-
"@speclynx/apidom-parser-adapter-arazzo-yaml-1": "4.
|
|
300
|
-
"@speclynx/apidom-parser-adapter-asyncapi-json-2": "4.
|
|
301
|
-
"@speclynx/apidom-parser-adapter-asyncapi-yaml-2": "4.
|
|
302
|
-
"@speclynx/apidom-parser-adapter-json": "4.
|
|
303
|
-
"@speclynx/apidom-parser-adapter-openapi-json-2": "4.
|
|
304
|
-
"@speclynx/apidom-parser-adapter-openapi-json-3-0": "4.
|
|
305
|
-
"@speclynx/apidom-parser-adapter-openapi-json-3-1": "4.
|
|
306
|
-
"@speclynx/apidom-parser-adapter-openapi-yaml-2": "4.
|
|
307
|
-
"@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "4.
|
|
308
|
-
"@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "4.
|
|
309
|
-
"@speclynx/apidom-parser-adapter-overlay-json-1": "4.
|
|
310
|
-
"@speclynx/apidom-parser-adapter-overlay-yaml-1": "4.
|
|
311
|
-
"@speclynx/apidom-parser-adapter-yaml-1-2": "4.
|
|
312
|
-
"@speclynx/apidom-traverse": "4.
|
|
292
|
+
"@speclynx/apidom-core": "4.13.0",
|
|
293
|
+
"@speclynx/apidom-datamodel": "4.13.0",
|
|
294
|
+
"@speclynx/apidom-error": "4.13.0",
|
|
295
|
+
"@speclynx/apidom-json-pointer": "4.13.0",
|
|
296
|
+
"@speclynx/apidom-ns-arazzo-1": "4.13.0",
|
|
297
|
+
"@speclynx/apidom-ns-asyncapi-2": "4.13.0",
|
|
298
|
+
"@speclynx/apidom-ns-json-schema-2020-12": "4.13.0",
|
|
299
|
+
"@speclynx/apidom-ns-openapi-2": "4.13.0",
|
|
300
|
+
"@speclynx/apidom-ns-openapi-3-0": "4.13.0",
|
|
301
|
+
"@speclynx/apidom-ns-openapi-3-1": "4.13.0",
|
|
302
|
+
"@speclynx/apidom-ns-overlay-1": "4.13.0",
|
|
303
|
+
"@speclynx/apidom-parser-adapter-arazzo-json-1": "4.13.0",
|
|
304
|
+
"@speclynx/apidom-parser-adapter-arazzo-yaml-1": "4.13.0",
|
|
305
|
+
"@speclynx/apidom-parser-adapter-asyncapi-json-2": "4.13.0",
|
|
306
|
+
"@speclynx/apidom-parser-adapter-asyncapi-yaml-2": "4.13.0",
|
|
307
|
+
"@speclynx/apidom-parser-adapter-json": "4.13.0",
|
|
308
|
+
"@speclynx/apidom-parser-adapter-openapi-json-2": "4.13.0",
|
|
309
|
+
"@speclynx/apidom-parser-adapter-openapi-json-3-0": "4.13.0",
|
|
310
|
+
"@speclynx/apidom-parser-adapter-openapi-json-3-1": "4.13.0",
|
|
311
|
+
"@speclynx/apidom-parser-adapter-openapi-yaml-2": "4.13.0",
|
|
312
|
+
"@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "4.13.0",
|
|
313
|
+
"@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "4.13.0",
|
|
314
|
+
"@speclynx/apidom-parser-adapter-overlay-json-1": "4.13.0",
|
|
315
|
+
"@speclynx/apidom-parser-adapter-overlay-yaml-1": "4.13.0",
|
|
316
|
+
"@speclynx/apidom-parser-adapter-yaml-1-2": "4.13.0",
|
|
317
|
+
"@speclynx/apidom-traverse": "4.13.0",
|
|
313
318
|
"@swaggerexpert/arazzo-runtime-expression": "^2.0.3",
|
|
314
319
|
"axios": "^1.18.0",
|
|
315
320
|
"picomatch": "^4.0.4",
|
|
@@ -331,5 +336,5 @@
|
|
|
331
336
|
"README.md",
|
|
332
337
|
"CHANGELOG.md"
|
|
333
338
|
],
|
|
334
|
-
"gitHead": "
|
|
339
|
+
"gitHead": "178b5324324332132479271fb9ac747a7ddbfccc"
|
|
335
340
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "OpenAPI2BundleVisitor", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _visitor.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
exports.default = void 0;
|
|
14
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
15
|
+
var _apidomTraverse = require("@speclynx/apidom-traverse");
|
|
16
|
+
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-2");
|
|
17
|
+
var _Reference = _interopRequireDefault(require("../../../Reference.cjs"));
|
|
18
|
+
var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
|
|
19
|
+
var _BundleStrategy = _interopRequireDefault(require("../BundleStrategy.cjs"));
|
|
20
|
+
var _visitor = _interopRequireDefault(require("./visitor.cjs"));
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
class OpenAPI2BundleStrategy extends _BundleStrategy.default {
|
|
29
|
+
constructor(options) {
|
|
30
|
+
super({
|
|
31
|
+
...(options ?? {}),
|
|
32
|
+
name: 'openapi-2'
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
canBundle(file) {
|
|
36
|
+
// assert by media type
|
|
37
|
+
if (file.mediaType !== 'text/plain') {
|
|
38
|
+
return _apidomNsOpenapi.mediaTypes.includes(file.mediaType);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// assert by inspecting ApiDOM
|
|
42
|
+
return (0, _apidomNsOpenapi.isSwaggerElement)(file.parseResult?.result);
|
|
43
|
+
}
|
|
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;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
var _default = exports.default = OpenAPI2BundleStrategy;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { cloneDeep } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import { traverseAsync } from '@speclynx/apidom-traverse';
|
|
3
|
+
import { mediaTypes, isSwaggerElement } from '@speclynx/apidom-ns-openapi-2';
|
|
4
|
+
import Reference from "../../../Reference.mjs";
|
|
5
|
+
import ReferenceSet from "../../../ReferenceSet.mjs";
|
|
6
|
+
import BundleStrategy from "../BundleStrategy.mjs";
|
|
7
|
+
import OpenAPI2BundleVisitor from "./visitor.mjs";
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
class OpenAPI2BundleStrategy extends BundleStrategy {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
super({
|
|
17
|
+
...(options ?? {}),
|
|
18
|
+
name: 'openapi-2'
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
canBundle(file) {
|
|
22
|
+
// assert by media type
|
|
23
|
+
if (file.mediaType !== 'text/plain') {
|
|
24
|
+
return mediaTypes.includes(file.mediaType);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// assert by inspecting ApiDOM
|
|
28
|
+
return isSwaggerElement(file.parseResult?.result);
|
|
29
|
+
}
|
|
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 OpenAPI2BundleVisitor({
|
|
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;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export { OpenAPI2BundleVisitor };
|
|
81
|
+
export default OpenAPI2BundleStrategy;
|