@speclynx/apidom-reference 1.12.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 +86 -0
- package/LICENSE +202 -0
- package/LICENSES/AFL-3.0.txt +182 -0
- package/LICENSES/Apache-2.0.txt +202 -0
- package/LICENSES/BSD-3-Clause.txt +26 -0
- package/LICENSES/MIT.txt +9 -0
- package/NOTICE +65 -0
- package/README.md +2107 -0
- package/dist/167.apidom-reference.browser.js +10 -0
- package/dist/167.apidom-reference.browser.min.js +1 -0
- package/dist/451.apidom-reference.browser.js +10 -0
- package/dist/451.apidom-reference.browser.min.js +1 -0
- package/dist/9786785aaddf11f37840fad896531940.wasm +0 -0
- package/dist/apidom-reference.browser.js +85376 -0
- package/dist/apidom-reference.browser.min.js +1 -0
- package/package.json +304 -0
- package/src/File.cjs +50 -0
- package/src/File.mjs +44 -0
- package/src/Reference.cjs +31 -0
- package/src/Reference.mjs +27 -0
- package/src/ReferenceSet.cjs +60 -0
- package/src/ReferenceSet.mjs +57 -0
- package/src/bundle/index.cjs +61 -0
- package/src/bundle/index.mjs +55 -0
- package/src/bundle/strategies/BundleStrategy.cjs +20 -0
- package/src/bundle/strategies/BundleStrategy.mjs +16 -0
- package/src/bundle/strategies/openapi-3-1/index.cjs +35 -0
- package/src/bundle/strategies/openapi-3-1/index.mjs +29 -0
- package/src/configuration/empty.cjs +9 -0
- package/src/configuration/empty.mjs +1 -0
- package/src/configuration/saturated.cjs +95 -0
- package/src/configuration/saturated.mjs +87 -0
- package/src/dereference/index.cjs +86 -0
- package/src/dereference/index.mjs +79 -0
- package/src/dereference/strategies/DereferenceStrategy.cjs +20 -0
- package/src/dereference/strategies/DereferenceStrategy.mjs +16 -0
- package/src/dereference/strategies/apidom/index.cjs +89 -0
- package/src/dereference/strategies/apidom/index.mjs +84 -0
- package/src/dereference/strategies/apidom/selectors/element-id.cjs +36 -0
- package/src/dereference/strategies/apidom/selectors/element-id.mjs +30 -0
- package/src/dereference/strategies/apidom/visitor.cjs +165 -0
- package/src/dereference/strategies/apidom/visitor.mjs +159 -0
- package/src/dereference/strategies/asyncapi-2/index.cjs +100 -0
- package/src/dereference/strategies/asyncapi-2/index.mjs +94 -0
- package/src/dereference/strategies/asyncapi-2/visitor.cjs +412 -0
- package/src/dereference/strategies/asyncapi-2/visitor.mjs +406 -0
- package/src/dereference/strategies/openapi-2/index.cjs +102 -0
- package/src/dereference/strategies/openapi-2/index.mjs +96 -0
- package/src/dereference/strategies/openapi-2/visitor.cjs +530 -0
- package/src/dereference/strategies/openapi-2/visitor.mjs +524 -0
- package/src/dereference/strategies/openapi-3-0/index.cjs +102 -0
- package/src/dereference/strategies/openapi-3-0/index.mjs +96 -0
- package/src/dereference/strategies/openapi-3-0/visitor.cjs +519 -0
- package/src/dereference/strategies/openapi-3-0/visitor.mjs +513 -0
- package/src/dereference/strategies/openapi-3-1/index.cjs +105 -0
- package/src/dereference/strategies/openapi-3-1/index.mjs +96 -0
- package/src/dereference/strategies/openapi-3-1/selectors/$anchor.cjs +66 -0
- package/src/dereference/strategies/openapi-3-1/selectors/$anchor.mjs +55 -0
- package/src/dereference/strategies/openapi-3-1/selectors/uri.cjs +50 -0
- package/src/dereference/strategies/openapi-3-1/selectors/uri.mjs +42 -0
- package/src/dereference/strategies/openapi-3-1/util.cjs +67 -0
- package/src/dereference/strategies/openapi-3-1/util.mjs +58 -0
- package/src/dereference/strategies/openapi-3-1/visitor.cjs +776 -0
- package/src/dereference/strategies/openapi-3-1/visitor.mjs +770 -0
- package/src/dereference/util.cjs +31 -0
- package/src/dereference/util.mjs +27 -0
- package/src/errors/BundleError.cjs +10 -0
- package/src/errors/BundleError.mjs +7 -0
- package/src/errors/DereferenceError.cjs +10 -0
- package/src/errors/DereferenceError.mjs +7 -0
- package/src/errors/EvaluationElementIdError.cjs +10 -0
- package/src/errors/EvaluationElementIdError.mjs +7 -0
- package/src/errors/EvaluationJsonSchema$anchorError.cjs +11 -0
- package/src/errors/EvaluationJsonSchema$anchorError.mjs +6 -0
- package/src/errors/EvaluationJsonSchemaUriError.cjs +11 -0
- package/src/errors/EvaluationJsonSchemaUriError.mjs +6 -0
- package/src/errors/InvalidJsonSchema$anchorError.cjs +15 -0
- package/src/errors/InvalidJsonSchema$anchorError.mjs +10 -0
- package/src/errors/JsonSchema$anchorError.cjs +10 -0
- package/src/errors/JsonSchema$anchorError.mjs +7 -0
- package/src/errors/JsonSchemaUriError.cjs +10 -0
- package/src/errors/JsonSchemaUriError.mjs +7 -0
- package/src/errors/MaximumBundleDepthError.cjs +11 -0
- package/src/errors/MaximumBundleDepthError.mjs +6 -0
- package/src/errors/MaximumDereferenceDepthError.cjs +11 -0
- package/src/errors/MaximumDereferenceDepthError.mjs +6 -0
- package/src/errors/MaximumResolveDepthError.cjs +11 -0
- package/src/errors/MaximumResolveDepthError.mjs +6 -0
- package/src/errors/ParseError.cjs +10 -0
- package/src/errors/ParseError.mjs +7 -0
- package/src/errors/ParserError.cjs +11 -0
- package/src/errors/ParserError.mjs +6 -0
- package/src/errors/PluginError.cjs +18 -0
- package/src/errors/PluginError.mjs +15 -0
- package/src/errors/ResolveError.cjs +10 -0
- package/src/errors/ResolveError.mjs +7 -0
- package/src/errors/ResolverError.cjs +11 -0
- package/src/errors/ResolverError.mjs +6 -0
- package/src/errors/UnmatchedBundleStrategyError.cjs +11 -0
- package/src/errors/UnmatchedBundleStrategyError.mjs +6 -0
- package/src/errors/UnmatchedDereferenceStrategyError.cjs +11 -0
- package/src/errors/UnmatchedDereferenceStrategyError.mjs +6 -0
- package/src/errors/UnmatchedResolveStrategyError.cjs +11 -0
- package/src/errors/UnmatchedResolveStrategyError.mjs +6 -0
- package/src/errors/UnmatchedResolverError.cjs +11 -0
- package/src/errors/UnmatchedResolverError.mjs +6 -0
- package/src/index.cjs +142 -0
- package/src/index.mjs +101 -0
- package/src/options/index.cjs +185 -0
- package/src/options/index.mjs +182 -0
- package/src/options/util.cjs +24 -0
- package/src/options/util.mjs +19 -0
- package/src/parse/index.cjs +69 -0
- package/src/parse/index.mjs +63 -0
- package/src/parse/parsers/Parser.cjs +48 -0
- package/src/parse/parsers/Parser.mjs +44 -0
- package/src/parse/parsers/api-design-systems-json/index.cjs +55 -0
- package/src/parse/parsers/api-design-systems-json/index.mjs +49 -0
- package/src/parse/parsers/api-design-systems-yaml/index.cjs +54 -0
- package/src/parse/parsers/api-design-systems-yaml/index.mjs +48 -0
- package/src/parse/parsers/apidom-json/index.cjs +70 -0
- package/src/parse/parsers/apidom-json/index.mjs +64 -0
- package/src/parse/parsers/arazzo-json-1/index.cjs +55 -0
- package/src/parse/parsers/arazzo-json-1/index.mjs +49 -0
- package/src/parse/parsers/arazzo-yaml-1/index.cjs +54 -0
- package/src/parse/parsers/arazzo-yaml-1/index.mjs +48 -0
- package/src/parse/parsers/asyncapi-json-2/index.cjs +55 -0
- package/src/parse/parsers/asyncapi-json-2/index.mjs +49 -0
- package/src/parse/parsers/asyncapi-yaml-2/index.cjs +54 -0
- package/src/parse/parsers/asyncapi-yaml-2/index.mjs +48 -0
- package/src/parse/parsers/binary/index-browser.cjs +56 -0
- package/src/parse/parsers/binary/index-browser.mjs +50 -0
- package/src/parse/parsers/binary/index-node.cjs +51 -0
- package/src/parse/parsers/binary/index-node.mjs +45 -0
- package/src/parse/parsers/json/index.cjs +54 -0
- package/src/parse/parsers/json/index.mjs +48 -0
- package/src/parse/parsers/openapi-json-2/index.cjs +55 -0
- package/src/parse/parsers/openapi-json-2/index.mjs +49 -0
- package/src/parse/parsers/openapi-json-3-0/index.cjs +55 -0
- package/src/parse/parsers/openapi-json-3-0/index.mjs +49 -0
- package/src/parse/parsers/openapi-json-3-1/index.cjs +55 -0
- package/src/parse/parsers/openapi-json-3-1/index.mjs +49 -0
- package/src/parse/parsers/openapi-yaml-2/index.cjs +54 -0
- package/src/parse/parsers/openapi-yaml-2/index.mjs +48 -0
- package/src/parse/parsers/openapi-yaml-3-0/index.cjs +54 -0
- package/src/parse/parsers/openapi-yaml-3-0/index.mjs +48 -0
- package/src/parse/parsers/openapi-yaml-3-1/index.cjs +54 -0
- package/src/parse/parsers/openapi-yaml-3-1/index.mjs +48 -0
- package/src/parse/parsers/yaml-1-2/index.cjs +54 -0
- package/src/parse/parsers/yaml-1-2/index.mjs +48 -0
- package/src/resolve/index.cjs +67 -0
- package/src/resolve/index.mjs +60 -0
- package/src/resolve/resolvers/HTTPResolver.cjs +38 -0
- package/src/resolve/resolvers/HTTPResolver.mjs +31 -0
- package/src/resolve/resolvers/Resolver.cjs +20 -0
- package/src/resolve/resolvers/Resolver.mjs +16 -0
- package/src/resolve/resolvers/file/index-browser.cjs +24 -0
- package/src/resolve/resolvers/file/index-browser.mjs +19 -0
- package/src/resolve/resolvers/file/index-node.cjs +49 -0
- package/src/resolve/resolvers/file/index-node.mjs +42 -0
- package/src/resolve/resolvers/http-axios/index.cjs +80 -0
- package/src/resolve/resolvers/http-axios/index.mjs +73 -0
- package/src/resolve/strategies/ResolveStrategy.cjs +20 -0
- package/src/resolve/strategies/ResolveStrategy.mjs +16 -0
- package/src/resolve/strategies/apidom/index.cjs +49 -0
- package/src/resolve/strategies/apidom/index.mjs +43 -0
- package/src/resolve/strategies/asyncapi-2/index.cjs +49 -0
- package/src/resolve/strategies/asyncapi-2/index.mjs +43 -0
- package/src/resolve/strategies/openapi-2/index.cjs +49 -0
- package/src/resolve/strategies/openapi-2/index.mjs +43 -0
- package/src/resolve/strategies/openapi-3-0/index.cjs +49 -0
- package/src/resolve/strategies/openapi-3-0/index.mjs +43 -0
- package/src/resolve/strategies/openapi-3-1/index.cjs +49 -0
- package/src/resolve/strategies/openapi-3-1/index.mjs +43 -0
- package/src/resolve/util.cjs +37 -0
- package/src/resolve/util.mjs +30 -0
- package/src/util/plugins.cjs +44 -0
- package/src/util/plugins.mjs +37 -0
- package/src/util/url.cjs +288 -0
- package/src/util/url.mjs +274 -0
- package/types/File.d.ts +24 -0
- package/types/Reference.d.ts +23 -0
- package/types/ReferenceSet.d.ts +25 -0
- package/types/apidom-reference.d.ts +584 -0
- package/types/bundle/index.d.ts +7 -0
- package/types/bundle/strategies/BundleStrategy.d.ts +19 -0
- package/types/bundle/strategies/openapi-3-1/index.d.ts +26 -0
- package/types/configuration/empty.d.ts +1 -0
- package/types/configuration/saturated.d.ts +1 -0
- package/types/dereference/index.d.ts +11 -0
- package/types/dereference/strategies/DereferenceStrategy.d.ts +19 -0
- package/types/dereference/strategies/apidom/index.d.ts +30 -0
- package/types/dereference/strategies/apidom/selectors/element-id.d.ts +11 -0
- package/types/dereference/strategies/apidom/visitor.d.ts +32 -0
- package/types/dereference/strategies/asyncapi-2/index.d.ts +31 -0
- package/types/dereference/strategies/asyncapi-2/visitor.d.ts +43 -0
- package/types/dereference/strategies/openapi-2/index.d.ts +32 -0
- package/types/dereference/strategies/openapi-2/visitor.d.ts +47 -0
- package/types/dereference/strategies/openapi-3-0/index.d.ts +31 -0
- package/types/dereference/strategies/openapi-3-0/visitor.d.ts +49 -0
- package/types/dereference/strategies/openapi-3-1/index.d.ts +32 -0
- package/types/dereference/strategies/openapi-3-1/selectors/$anchor.d.ts +22 -0
- package/types/dereference/strategies/openapi-3-1/selectors/uri.d.ts +12 -0
- package/types/dereference/strategies/openapi-3-1/util.d.ts +21 -0
- package/types/dereference/strategies/openapi-3-1/visitor.d.ts +52 -0
- package/types/dereference/util.d.ts +9 -0
- package/types/errors/BundleError.d.ts +7 -0
- package/types/errors/DereferenceError.d.ts +7 -0
- package/types/errors/EvaluationElementIdError.d.ts +7 -0
- package/types/errors/EvaluationJsonSchema$anchorError.d.ts +7 -0
- package/types/errors/EvaluationJsonSchemaUriError.d.ts +7 -0
- package/types/errors/InvalidJsonSchema$anchorError.d.ts +8 -0
- package/types/errors/JsonSchema$anchorError.d.ts +7 -0
- package/types/errors/JsonSchemaUriError.d.ts +7 -0
- package/types/errors/MaximumBundleDepthError.d.ts +7 -0
- package/types/errors/MaximumDereferenceDepthError.d.ts +7 -0
- package/types/errors/MaximumResolveDepthError.d.ts +7 -0
- package/types/errors/ParseError.d.ts +7 -0
- package/types/errors/ParserError.d.ts +7 -0
- package/types/errors/PluginError.d.ts +12 -0
- package/types/errors/ResolveError.d.ts +7 -0
- package/types/errors/ResolverError.d.ts +7 -0
- package/types/errors/UnmatchedBundleStrategyError.d.ts +7 -0
- package/types/errors/UnmatchedDereferenceStrategyError.d.ts +7 -0
- package/types/errors/UnmatchedResolveStrategyError.d.ts +7 -0
- package/types/errors/UnmatchedResolverError.d.ts +7 -0
- package/types/index.d.ts +75 -0
- package/types/options/index.d.ts +62 -0
- package/types/options/util.d.ts +5 -0
- package/types/parse/index.d.ts +7 -0
- package/types/parse/parsers/Parser.d.ts +38 -0
- package/types/parse/parsers/api-design-systems-json/index.d.ts +21 -0
- package/types/parse/parsers/api-design-systems-yaml/index.d.ts +20 -0
- package/types/parse/parsers/apidom-json/index.d.ts +24 -0
- package/types/parse/parsers/arazzo-json-1/index.d.ts +21 -0
- package/types/parse/parsers/arazzo-yaml-1/index.d.ts +20 -0
- package/types/parse/parsers/asyncapi-json-2/index.d.ts +21 -0
- package/types/parse/parsers/asyncapi-yaml-2/index.d.ts +20 -0
- package/types/parse/parsers/binary/index-browser.d.ts +21 -0
- package/types/parse/parsers/binary/index-node.d.ts +21 -0
- package/types/parse/parsers/json/index.d.ts +20 -0
- package/types/parse/parsers/openapi-json-2/index.d.ts +21 -0
- package/types/parse/parsers/openapi-json-3-0/index.d.ts +21 -0
- package/types/parse/parsers/openapi-json-3-1/index.d.ts +21 -0
- package/types/parse/parsers/openapi-yaml-2/index.d.ts +20 -0
- package/types/parse/parsers/openapi-yaml-3-0/index.d.ts +20 -0
- package/types/parse/parsers/openapi-yaml-3-1/index.d.ts +20 -0
- package/types/parse/parsers/yaml-1-2/index.d.ts +20 -0
- package/types/resolve/index.d.ts +12 -0
- package/types/resolve/resolvers/HTTPResolver.d.ts +22 -0
- package/types/resolve/resolvers/Resolver.d.ts +17 -0
- package/types/resolve/resolvers/file/index-browser.d.ts +12 -0
- package/types/resolve/resolvers/file/index-node.d.ts +20 -0
- package/types/resolve/resolvers/http-axios/index.d.ts +30 -0
- package/types/resolve/strategies/ResolveStrategy.d.ts +19 -0
- package/types/resolve/strategies/apidom/index.d.ts +27 -0
- package/types/resolve/strategies/asyncapi-2/index.d.ts +27 -0
- package/types/resolve/strategies/openapi-2/index.d.ts +27 -0
- package/types/resolve/strategies/openapi-3-0/index.d.ts +27 -0
- package/types/resolve/strategies/openapi-3-1/index.d.ts +27 -0
- package/types/resolve/util.d.ts +6 -0
- package/types/util/plugins.d.ts +14 -0
- package/types/util/url.d.ts +106 -0
|
@@ -0,0 +1,776 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.mutationReplacer = exports.default = void 0;
|
|
7
|
+
var _ramda = require("ramda");
|
|
8
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
9
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
10
|
+
var _apidomError = require("@speclynx/apidom-error");
|
|
11
|
+
var _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
|
|
12
|
+
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-1");
|
|
13
|
+
var _$anchor = require("./selectors/$anchor.cjs");
|
|
14
|
+
var _uri = require("./selectors/uri.cjs");
|
|
15
|
+
var _MaximumDereferenceDepthError = _interopRequireDefault(require("../../../errors/MaximumDereferenceDepthError.cjs"));
|
|
16
|
+
var _MaximumResolveDepthError = _interopRequireDefault(require("../../../errors/MaximumResolveDepthError.cjs"));
|
|
17
|
+
var url = _interopRequireWildcard(require("../../../util/url.cjs"));
|
|
18
|
+
var _index = _interopRequireDefault(require("../../../parse/index.cjs"));
|
|
19
|
+
var _Reference = _interopRequireDefault(require("../../../Reference.cjs"));
|
|
20
|
+
var _File = _interopRequireDefault(require("../../../File.cjs"));
|
|
21
|
+
var _util = require("./util.cjs");
|
|
22
|
+
var _util2 = require("../../util.cjs");
|
|
23
|
+
var _EvaluationJsonSchemaUriError = _interopRequireDefault(require("../../../errors/EvaluationJsonSchemaUriError.cjs"));
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
const visitAsync = _apidomCore.visit[Symbol.for('nodejs.util.promisify.custom')];
|
|
26
|
+
|
|
27
|
+
// initialize element identity manager
|
|
28
|
+
const identityManager = new _apidomCore.IdentityManager();
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Custom mutation replacer.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
const mutationReplacer = (newElement, oldElement, key, parent) => {
|
|
35
|
+
if ((0, _apidomCore.isMemberElement)(parent)) {
|
|
36
|
+
parent.value = newElement;
|
|
37
|
+
} else if (Array.isArray(parent)) {
|
|
38
|
+
parent[key] = newElement;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
exports.mutationReplacer = mutationReplacer;
|
|
46
|
+
/**
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
class OpenAPI3_1DereferenceVisitor {
|
|
50
|
+
indirections;
|
|
51
|
+
namespace;
|
|
52
|
+
reference;
|
|
53
|
+
options;
|
|
54
|
+
ancestors;
|
|
55
|
+
refractCache;
|
|
56
|
+
constructor({
|
|
57
|
+
reference,
|
|
58
|
+
namespace,
|
|
59
|
+
options,
|
|
60
|
+
indirections = [],
|
|
61
|
+
ancestors = new _util2.AncestorLineage(),
|
|
62
|
+
refractCache = new Map()
|
|
63
|
+
}) {
|
|
64
|
+
this.indirections = indirections;
|
|
65
|
+
this.namespace = namespace;
|
|
66
|
+
this.reference = reference;
|
|
67
|
+
this.options = options;
|
|
68
|
+
this.ancestors = new _util2.AncestorLineage(...ancestors);
|
|
69
|
+
this.refractCache = refractCache;
|
|
70
|
+
}
|
|
71
|
+
toBaseURI(uri) {
|
|
72
|
+
return url.resolve(this.reference.uri, url.sanitize(url.stripHash(uri)));
|
|
73
|
+
}
|
|
74
|
+
async toReference(uri) {
|
|
75
|
+
// detect maximum depth of resolution
|
|
76
|
+
if (this.reference.depth >= this.options.resolve.maxDepth) {
|
|
77
|
+
throw new _MaximumResolveDepthError.default(`Maximum resolution depth of ${this.options.resolve.maxDepth} has been exceeded by file "${this.reference.uri}"`);
|
|
78
|
+
}
|
|
79
|
+
const baseURI = this.toBaseURI(uri);
|
|
80
|
+
const {
|
|
81
|
+
refSet
|
|
82
|
+
} = this.reference;
|
|
83
|
+
|
|
84
|
+
// we've already processed this Reference in past
|
|
85
|
+
if (refSet.has(baseURI)) {
|
|
86
|
+
return refSet.find((0, _ramda.propEq)(baseURI, 'uri'));
|
|
87
|
+
}
|
|
88
|
+
const parseResult = await (0, _index.default)(url.unsanitize(baseURI), {
|
|
89
|
+
...this.options,
|
|
90
|
+
parse: {
|
|
91
|
+
...this.options.parse,
|
|
92
|
+
mediaType: 'text/plain'
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// register new mutable reference with a refSet
|
|
97
|
+
const mutableReference = new _Reference.default({
|
|
98
|
+
uri: baseURI,
|
|
99
|
+
value: (0, _apidomCore.cloneDeep)(parseResult),
|
|
100
|
+
depth: this.reference.depth + 1
|
|
101
|
+
});
|
|
102
|
+
refSet.add(mutableReference);
|
|
103
|
+
if (this.options.dereference.immutable) {
|
|
104
|
+
// register new immutable reference with a refSet
|
|
105
|
+
const immutableReference = new _Reference.default({
|
|
106
|
+
uri: `immutable://${baseURI}`,
|
|
107
|
+
value: parseResult,
|
|
108
|
+
depth: this.reference.depth + 1
|
|
109
|
+
});
|
|
110
|
+
refSet.add(immutableReference);
|
|
111
|
+
}
|
|
112
|
+
return mutableReference;
|
|
113
|
+
}
|
|
114
|
+
toAncestorLineage(ancestors) {
|
|
115
|
+
/**
|
|
116
|
+
* Compute full ancestors lineage.
|
|
117
|
+
* Ancestors are flatten to unwrap all Element instances.
|
|
118
|
+
*/
|
|
119
|
+
const directAncestors = new Set(ancestors.filter(_apidomCore.isElement));
|
|
120
|
+
const ancestorsLineage = new _util2.AncestorLineage(...this.ancestors, directAncestors);
|
|
121
|
+
return [ancestorsLineage, directAncestors];
|
|
122
|
+
}
|
|
123
|
+
async ReferenceElement(referencingElement, key, parent, path, ancestors, link) {
|
|
124
|
+
// skip current referencing element as it's already been access
|
|
125
|
+
if (this.indirections.includes(referencingElement)) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
|
|
129
|
+
const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(referencingElement.$ref));
|
|
130
|
+
const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
|
|
131
|
+
const isExternalReference = !isInternalReference;
|
|
132
|
+
|
|
133
|
+
// ignore resolving internal Reference Objects
|
|
134
|
+
if (!this.options.resolve.internal && isInternalReference) {
|
|
135
|
+
// skip traversing this reference element and all it's child elements
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
// ignore resolving external Reference Objects
|
|
139
|
+
if (!this.options.resolve.external && isExternalReference) {
|
|
140
|
+
// skip traversing this reference element and all it's child elements
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
const reference = await this.toReference((0, _apidomCore.toValue)(referencingElement.$ref));
|
|
144
|
+
const $refBaseURI = url.resolve(retrievalURI, (0, _apidomCore.toValue)(referencingElement.$ref));
|
|
145
|
+
this.indirections.push(referencingElement);
|
|
146
|
+
const jsonPointer = _apidomJsonPointer.URIFragmentIdentifier.fromURIReference($refBaseURI);
|
|
147
|
+
|
|
148
|
+
// possibly non-semantic fragment
|
|
149
|
+
let referencedElement = (0, _apidomJsonPointer.evaluate)(reference.value.result, jsonPointer);
|
|
150
|
+
referencedElement.id = identityManager.identify(referencedElement);
|
|
151
|
+
|
|
152
|
+
// applying semantics to a fragment
|
|
153
|
+
if ((0, _apidomCore.isPrimitiveElement)(referencedElement)) {
|
|
154
|
+
const referencedElementType = (0, _apidomCore.toValue)(referencingElement.meta.get('referenced-element'));
|
|
155
|
+
const cacheKey = `${referencedElementType}-${(0, _apidomCore.toValue)(identityManager.identify(referencedElement))}`;
|
|
156
|
+
if (this.refractCache.has(cacheKey)) {
|
|
157
|
+
referencedElement = this.refractCache.get(cacheKey);
|
|
158
|
+
} else if ((0, _apidomNsOpenapi.isReferenceLikeElement)(referencedElement)) {
|
|
159
|
+
// handling indirect references
|
|
160
|
+
referencedElement = _apidomNsOpenapi.ReferenceElement.refract(referencedElement);
|
|
161
|
+
referencedElement.setMetaProperty('referenced-element', referencedElementType);
|
|
162
|
+
this.refractCache.set(cacheKey, referencedElement);
|
|
163
|
+
} else {
|
|
164
|
+
// handling direct references
|
|
165
|
+
const ElementClass = this.namespace.getElementClass(referencedElementType);
|
|
166
|
+
referencedElement = ElementClass.refract(referencedElement);
|
|
167
|
+
this.refractCache.set(cacheKey, referencedElement);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// detect direct or indirect reference
|
|
172
|
+
if (referencingElement === referencedElement) {
|
|
173
|
+
throw new _apidomError.ApiDOMError('Recursive Reference Object detected');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// detect maximum depth of dereferencing
|
|
177
|
+
if (this.indirections.length > this.options.dereference.maxDepth) {
|
|
178
|
+
throw new _MaximumDereferenceDepthError.default(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// detect second deep dive into the same fragment and avoid it
|
|
182
|
+
if (ancestorsLineage.includes(referencedElement)) {
|
|
183
|
+
reference.refSet.circular = true;
|
|
184
|
+
if (this.options.dereference.circular === 'error') {
|
|
185
|
+
throw new _apidomError.ApiDOMError('Circular reference detected');
|
|
186
|
+
} else if (this.options.dereference.circular === 'replace') {
|
|
187
|
+
const refElement = new _apidomCore.RefElement(referencedElement.id, {
|
|
188
|
+
type: 'reference',
|
|
189
|
+
uri: reference.uri,
|
|
190
|
+
$ref: (0, _apidomCore.toValue)(referencingElement.$ref)
|
|
191
|
+
});
|
|
192
|
+
const replacer = this.options.dereference.strategyOpts['openapi-3-1']?.circularReplacer ?? this.options.dereference.circularReplacer;
|
|
193
|
+
const replacement = replacer(refElement);
|
|
194
|
+
link.replaceWith(replacement, mutationReplacer);
|
|
195
|
+
return !parent ? replacement : false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Dive deep into the fragment.
|
|
201
|
+
*
|
|
202
|
+
* Cases to consider:
|
|
203
|
+
* 1. We're crossing document boundary
|
|
204
|
+
* 2. Fragment is from non-root document
|
|
205
|
+
* 3. Fragment is a Reference Object. We need to follow it to get the eventual value
|
|
206
|
+
* 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
|
|
207
|
+
*/
|
|
208
|
+
const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri;
|
|
209
|
+
const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
|
|
210
|
+
if ((isExternalReference || isNonRootDocument || (0, _apidomNsOpenapi.isReferenceElement)(referencedElement) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
|
|
211
|
+
// append referencing reference to ancestors lineage
|
|
212
|
+
directAncestors.add(referencingElement);
|
|
213
|
+
const visitor = new OpenAPI3_1DereferenceVisitor({
|
|
214
|
+
reference,
|
|
215
|
+
namespace: this.namespace,
|
|
216
|
+
indirections: [...this.indirections],
|
|
217
|
+
options: this.options,
|
|
218
|
+
refractCache: this.refractCache,
|
|
219
|
+
ancestors: ancestorsLineage
|
|
220
|
+
});
|
|
221
|
+
referencedElement = await visitAsync(referencedElement, visitor, {
|
|
222
|
+
keyMap: _apidomNsOpenapi.keyMap,
|
|
223
|
+
nodeTypeGetter: _apidomNsOpenapi.getNodeType
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// remove referencing reference from ancestors lineage
|
|
227
|
+
directAncestors.delete(referencingElement);
|
|
228
|
+
}
|
|
229
|
+
this.indirections.pop();
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Creating a new version of referenced element to avoid modifying the original one.
|
|
233
|
+
*/
|
|
234
|
+
const mergedElement = (0, _apidomCore.cloneShallow)(referencedElement);
|
|
235
|
+
// assign unique id to merged element
|
|
236
|
+
mergedElement.setMetaProperty('id', identityManager.generateId());
|
|
237
|
+
// annotate fragment with info about original Reference element
|
|
238
|
+
mergedElement.setMetaProperty('ref-fields', {
|
|
239
|
+
$ref: (0, _apidomCore.toValue)(referencingElement.$ref),
|
|
240
|
+
// @ts-ignore
|
|
241
|
+
description: (0, _apidomCore.toValue)(referencingElement.description),
|
|
242
|
+
// @ts-ignore
|
|
243
|
+
summary: (0, _apidomCore.toValue)(referencingElement.summary)
|
|
244
|
+
});
|
|
245
|
+
// annotate fragment with info about origin
|
|
246
|
+
mergedElement.setMetaProperty('ref-origin', reference.uri);
|
|
247
|
+
// annotate fragment with info about referencing element
|
|
248
|
+
mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
|
|
249
|
+
|
|
250
|
+
// override description and summary (outer has higher priority then inner)
|
|
251
|
+
if ((0, _apidomCore.isObjectElement)(referencedElement) && (0, _apidomCore.isObjectElement)(mergedElement)) {
|
|
252
|
+
if (referencingElement.hasKey('description') && 'description' in referencedElement) {
|
|
253
|
+
mergedElement.remove('description');
|
|
254
|
+
mergedElement.set('description', referencingElement.get('description'));
|
|
255
|
+
}
|
|
256
|
+
if (referencingElement.hasKey('summary') && 'summary' in referencedElement) {
|
|
257
|
+
mergedElement.remove('summary');
|
|
258
|
+
mergedElement.set('summary', referencingElement.get('summary'));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Transclude referencing element with merged referenced element.
|
|
264
|
+
*/
|
|
265
|
+
link.replaceWith(mergedElement, mutationReplacer);
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* We're at the root of the tree, so we're just replacing the entire tree.
|
|
269
|
+
*/
|
|
270
|
+
return !parent ? mergedElement : false;
|
|
271
|
+
}
|
|
272
|
+
async PathItemElement(referencingElement, key, parent, path, ancestors, link) {
|
|
273
|
+
// ignore PathItemElement without $ref field
|
|
274
|
+
if (!(0, _apidomCore.isStringElement)(referencingElement.$ref)) {
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// skip current referencing element as it's already been access
|
|
279
|
+
if (this.indirections.includes(referencingElement)) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
|
|
283
|
+
const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(referencingElement.$ref));
|
|
284
|
+
const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
|
|
285
|
+
const isExternalReference = !isInternalReference;
|
|
286
|
+
|
|
287
|
+
// ignore resolving external Path Item Objects
|
|
288
|
+
if (!this.options.resolve.internal && isInternalReference) {
|
|
289
|
+
// skip traversing this Path Item element but traverse all it's child elements
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
// ignore resolving external Path Item Objects
|
|
293
|
+
if (!this.options.resolve.external && isExternalReference) {
|
|
294
|
+
// skip traversing this Path Item element but traverse all it's child elements
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
const reference = await this.toReference((0, _apidomCore.toValue)(referencingElement.$ref));
|
|
298
|
+
const $refBaseURI = url.resolve(retrievalURI, (0, _apidomCore.toValue)(referencingElement.$ref));
|
|
299
|
+
this.indirections.push(referencingElement);
|
|
300
|
+
const jsonPointer = _apidomJsonPointer.URIFragmentIdentifier.fromURIReference($refBaseURI);
|
|
301
|
+
|
|
302
|
+
// possibly non-semantic referenced element
|
|
303
|
+
let referencedElement = (0, _apidomJsonPointer.evaluate)(reference.value.result, jsonPointer);
|
|
304
|
+
referencedElement.id = identityManager.identify(referencedElement);
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Applying semantics to a referenced element if semantics are missing.
|
|
308
|
+
*/
|
|
309
|
+
if ((0, _apidomCore.isPrimitiveElement)(referencedElement)) {
|
|
310
|
+
const cacheKey = `path-item-${(0, _apidomCore.toValue)(identityManager.identify(referencedElement))}`;
|
|
311
|
+
if (this.refractCache.has(cacheKey)) {
|
|
312
|
+
referencedElement = this.refractCache.get(cacheKey);
|
|
313
|
+
} else {
|
|
314
|
+
referencedElement = _apidomNsOpenapi.PathItemElement.refract(referencedElement);
|
|
315
|
+
this.refractCache.set(cacheKey, referencedElement);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// detect direct or indirect reference
|
|
320
|
+
if (referencingElement === referencedElement) {
|
|
321
|
+
throw new _apidomError.ApiDOMError('Recursive Path Item Object reference detected');
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// detect maximum depth of dereferencing
|
|
325
|
+
if (this.indirections.length > this.options.dereference.maxDepth) {
|
|
326
|
+
throw new _MaximumDereferenceDepthError.default(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// detect second deep dive into the same fragment and avoid it
|
|
330
|
+
if (ancestorsLineage.includes(referencedElement)) {
|
|
331
|
+
reference.refSet.circular = true;
|
|
332
|
+
if (this.options.dereference.circular === 'error') {
|
|
333
|
+
throw new _apidomError.ApiDOMError('Circular reference detected');
|
|
334
|
+
} else if (this.options.dereference.circular === 'replace') {
|
|
335
|
+
const refElement = new _apidomCore.RefElement(referencedElement.id, {
|
|
336
|
+
type: 'path-item',
|
|
337
|
+
uri: reference.uri,
|
|
338
|
+
$ref: (0, _apidomCore.toValue)(referencingElement.$ref)
|
|
339
|
+
});
|
|
340
|
+
const replacer = this.options.dereference.strategyOpts['openapi-3-1']?.circularReplacer ?? this.options.dereference.circularReplacer;
|
|
341
|
+
const replacement = replacer(refElement);
|
|
342
|
+
link.replaceWith(replacement, mutationReplacer);
|
|
343
|
+
return !parent ? replacement : false;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Dive deep into the fragment.
|
|
349
|
+
*
|
|
350
|
+
* Cases to consider:
|
|
351
|
+
* 1. We're crossing document boundary
|
|
352
|
+
* 2. Fragment is from non-root document
|
|
353
|
+
* 3. Fragment is a Path Item Object with $ref field. We need to follow it to get the eventual value
|
|
354
|
+
* 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
|
|
355
|
+
*/
|
|
356
|
+
const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri;
|
|
357
|
+
const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
|
|
358
|
+
if ((isExternalReference || isNonRootDocument || (0, _apidomNsOpenapi.isPathItemElement)(referencedElement) && (0, _apidomCore.isStringElement)(referencedElement.$ref) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
|
|
359
|
+
// append referencing reference to ancestors lineage
|
|
360
|
+
directAncestors.add(referencingElement);
|
|
361
|
+
const visitor = new OpenAPI3_1DereferenceVisitor({
|
|
362
|
+
reference,
|
|
363
|
+
namespace: this.namespace,
|
|
364
|
+
indirections: [...this.indirections],
|
|
365
|
+
options: this.options,
|
|
366
|
+
refractCache: this.refractCache,
|
|
367
|
+
ancestors: ancestorsLineage
|
|
368
|
+
});
|
|
369
|
+
referencedElement = await visitAsync(referencedElement, visitor, {
|
|
370
|
+
keyMap: _apidomNsOpenapi.keyMap,
|
|
371
|
+
nodeTypeGetter: _apidomNsOpenapi.getNodeType
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
// remove referencing reference from ancestors lineage
|
|
375
|
+
directAncestors.delete(referencingElement);
|
|
376
|
+
}
|
|
377
|
+
this.indirections.pop();
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Creating a new version of Path Item by merging fields from referenced Path Item with referencing one.
|
|
381
|
+
*/
|
|
382
|
+
if ((0, _apidomNsOpenapi.isPathItemElement)(referencedElement)) {
|
|
383
|
+
const mergedElement = new _apidomNsOpenapi.PathItemElement([...referencedElement.content], (0, _apidomCore.cloneDeep)(referencedElement.meta), (0, _apidomCore.cloneDeep)(referencedElement.attributes));
|
|
384
|
+
// assign unique id to merged element
|
|
385
|
+
mergedElement.setMetaProperty('id', identityManager.generateId());
|
|
386
|
+
// existing keywords from referencing PathItemElement overrides ones from referenced element
|
|
387
|
+
referencingElement.forEach((value, keyElement, item) => {
|
|
388
|
+
mergedElement.remove((0, _apidomCore.toValue)(keyElement));
|
|
389
|
+
mergedElement.content.push(item);
|
|
390
|
+
});
|
|
391
|
+
mergedElement.remove('$ref');
|
|
392
|
+
|
|
393
|
+
// annotate referenced element with info about original referencing element
|
|
394
|
+
mergedElement.setMetaProperty('ref-fields', {
|
|
395
|
+
$ref: (0, _apidomCore.toValue)(referencingElement.$ref)
|
|
396
|
+
});
|
|
397
|
+
// annotate referenced element with info about origin
|
|
398
|
+
mergedElement.setMetaProperty('ref-origin', reference.uri);
|
|
399
|
+
// annotate fragment with info about referencing element
|
|
400
|
+
mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
|
|
401
|
+
referencedElement = mergedElement;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Transclude referencing element with merged referenced element.
|
|
406
|
+
*/
|
|
407
|
+
link.replaceWith(referencedElement, mutationReplacer);
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* We're at the root of the tree, so we're just replacing the entire tree.
|
|
411
|
+
*/
|
|
412
|
+
return !parent ? referencedElement : undefined;
|
|
413
|
+
}
|
|
414
|
+
async LinkElement(linkElement, key, parent, path, ancestors, link) {
|
|
415
|
+
// ignore LinkElement without operationRef or operationId field
|
|
416
|
+
if (!(0, _apidomCore.isStringElement)(linkElement.operationRef) && !(0, _apidomCore.isStringElement)(linkElement.operationId)) {
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// operationRef and operationId fields are mutually exclusive
|
|
421
|
+
if ((0, _apidomCore.isStringElement)(linkElement.operationRef) && (0, _apidomCore.isStringElement)(linkElement.operationId)) {
|
|
422
|
+
throw new _apidomError.ApiDOMError('LinkElement operationRef and operationId fields are mutually exclusive.');
|
|
423
|
+
}
|
|
424
|
+
let operationElement;
|
|
425
|
+
if ((0, _apidomCore.isStringElement)(linkElement.operationRef)) {
|
|
426
|
+
// possibly non-semantic referenced element
|
|
427
|
+
const jsonPointer = _apidomJsonPointer.URIFragmentIdentifier.fromURIReference((0, _apidomCore.toValue)(linkElement.operationRef));
|
|
428
|
+
const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(linkElement.operationRef));
|
|
429
|
+
const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
|
|
430
|
+
const isExternalReference = !isInternalReference;
|
|
431
|
+
|
|
432
|
+
// ignore resolving internal Operation Object reference
|
|
433
|
+
if (!this.options.resolve.internal && isInternalReference) {
|
|
434
|
+
// skip traversing this Link element but traverse all it's child elements
|
|
435
|
+
return undefined;
|
|
436
|
+
}
|
|
437
|
+
// ignore resolving external Operation Object reference
|
|
438
|
+
if (!this.options.resolve.external && isExternalReference) {
|
|
439
|
+
// skip traversing this Link element but traverse all it's child elements
|
|
440
|
+
return undefined;
|
|
441
|
+
}
|
|
442
|
+
const reference = await this.toReference((0, _apidomCore.toValue)(linkElement.operationRef));
|
|
443
|
+
operationElement = (0, _apidomJsonPointer.evaluate)(reference.value.result, jsonPointer);
|
|
444
|
+
// applying semantics to a referenced element
|
|
445
|
+
if ((0, _apidomCore.isPrimitiveElement)(operationElement)) {
|
|
446
|
+
const cacheKey = `operation-${(0, _apidomCore.toValue)(identityManager.identify(operationElement))}`;
|
|
447
|
+
if (this.refractCache.has(cacheKey)) {
|
|
448
|
+
operationElement = this.refractCache.get(cacheKey);
|
|
449
|
+
} else {
|
|
450
|
+
operationElement = _apidomNsOpenapi.OperationElement.refract(operationElement);
|
|
451
|
+
this.refractCache.set(cacheKey, operationElement);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
// create shallow clone to be able to annotate with metadata
|
|
455
|
+
operationElement = (0, _apidomCore.cloneShallow)(operationElement);
|
|
456
|
+
// annotate operation element with info about origin
|
|
457
|
+
operationElement.setMetaProperty('ref-origin', reference.uri);
|
|
458
|
+
const linkElementCopy = (0, _apidomCore.cloneShallow)(linkElement);
|
|
459
|
+
linkElementCopy.operationRef?.meta.set('operation', operationElement);
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Transclude Link Object containing Operation Object in its meta.
|
|
463
|
+
*/
|
|
464
|
+
link.replaceWith(linkElementCopy, mutationReplacer);
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* We're at the root of the tree, so we're just replacing the entire tree.
|
|
468
|
+
*/
|
|
469
|
+
return !parent ? linkElementCopy : undefined;
|
|
470
|
+
}
|
|
471
|
+
if ((0, _apidomCore.isStringElement)(linkElement.operationId)) {
|
|
472
|
+
const operationId = (0, _apidomCore.toValue)(linkElement.operationId);
|
|
473
|
+
const reference = await this.toReference(url.unsanitize(this.reference.uri));
|
|
474
|
+
operationElement = (0, _apidomCore.find)(e => (0, _apidomNsOpenapi.isOperationElement)(e) && (0, _apidomCore.isElement)(e.operationId) && e.operationId.equals(operationId), reference.value.result);
|
|
475
|
+
// OperationElement not found by its operationId
|
|
476
|
+
if ((0, _ramdaAdjunct.isUndefined)(operationElement)) {
|
|
477
|
+
throw new _apidomError.ApiDOMError(`OperationElement(operationId=${operationId}) not found.`);
|
|
478
|
+
}
|
|
479
|
+
const linkElementCopy = (0, _apidomCore.cloneShallow)(linkElement);
|
|
480
|
+
linkElementCopy.operationId?.meta.set('operation', operationElement);
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Transclude Link Object containing Operation Object in its meta.
|
|
484
|
+
*/
|
|
485
|
+
link.replaceWith(linkElementCopy, mutationReplacer);
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* We're at the root of the tree, so we're just replacing the entire tree.
|
|
489
|
+
*/
|
|
490
|
+
return !parent ? linkElementCopy : undefined;
|
|
491
|
+
}
|
|
492
|
+
return undefined;
|
|
493
|
+
}
|
|
494
|
+
async ExampleElement(exampleElement, key, parent, path, ancestors, link) {
|
|
495
|
+
// ignore ExampleElement without externalValue field
|
|
496
|
+
if (!(0, _apidomCore.isStringElement)(exampleElement.externalValue)) {
|
|
497
|
+
return undefined;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// value and externalValue fields are mutually exclusive
|
|
501
|
+
if (exampleElement.hasKey('value') && (0, _apidomCore.isStringElement)(exampleElement.externalValue)) {
|
|
502
|
+
throw new _apidomError.ApiDOMError('ExampleElement value and externalValue fields are mutually exclusive.');
|
|
503
|
+
}
|
|
504
|
+
const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(exampleElement.externalValue));
|
|
505
|
+
const isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
|
|
506
|
+
const isExternalReference = !isInternalReference;
|
|
507
|
+
|
|
508
|
+
// ignore resolving internal Example Objects
|
|
509
|
+
if (!this.options.resolve.internal && isInternalReference) {
|
|
510
|
+
// skip traversing this Example element but traverse all it's child elements
|
|
511
|
+
return undefined;
|
|
512
|
+
}
|
|
513
|
+
// ignore resolving external Example Objects
|
|
514
|
+
if (!this.options.resolve.external && isExternalReference) {
|
|
515
|
+
// skip traversing this Example element but traverse all it's child elements
|
|
516
|
+
return undefined;
|
|
517
|
+
}
|
|
518
|
+
const reference = await this.toReference((0, _apidomCore.toValue)(exampleElement.externalValue));
|
|
519
|
+
|
|
520
|
+
// shallow clone of the referenced element
|
|
521
|
+
const valueElement = (0, _apidomCore.cloneShallow)(reference.value.result);
|
|
522
|
+
// annotate operation element with info about origin
|
|
523
|
+
valueElement.setMetaProperty('ref-origin', reference.uri);
|
|
524
|
+
const exampleElementCopy = (0, _apidomCore.cloneShallow)(exampleElement);
|
|
525
|
+
exampleElementCopy.value = valueElement;
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Transclude Example Object containing external value.
|
|
529
|
+
*/
|
|
530
|
+
link.replaceWith(exampleElementCopy, mutationReplacer);
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* We're at the root of the tree, so we're just replacing the entire tree.
|
|
534
|
+
*/
|
|
535
|
+
return !parent ? exampleElementCopy : undefined;
|
|
536
|
+
}
|
|
537
|
+
async SchemaElement(referencingElement, key, parent, path, ancestors, link) {
|
|
538
|
+
// skip current referencing schema as $ref keyword was not defined
|
|
539
|
+
if (!(0, _apidomCore.isStringElement)(referencingElement.$ref)) {
|
|
540
|
+
return undefined;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// skip current referencing element as it's already been access
|
|
544
|
+
if (this.indirections.includes(referencingElement)) {
|
|
545
|
+
return false;
|
|
546
|
+
}
|
|
547
|
+
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
|
|
548
|
+
|
|
549
|
+
// compute baseURI using rules around $id and $ref keywords
|
|
550
|
+
let reference = await this.toReference(url.unsanitize(this.reference.uri));
|
|
551
|
+
let {
|
|
552
|
+
uri: retrievalURI
|
|
553
|
+
} = reference;
|
|
554
|
+
const $refBaseURI = (0, _util.resolveSchema$refField)(retrievalURI, referencingElement);
|
|
555
|
+
const $refBaseURIStrippedHash = url.stripHash($refBaseURI);
|
|
556
|
+
const file = new _File.default({
|
|
557
|
+
uri: $refBaseURIStrippedHash
|
|
558
|
+
});
|
|
559
|
+
const isUnknownURI = (0, _ramda.none)(r => r.canRead(file), this.options.resolve.resolvers);
|
|
560
|
+
const isURL = !isUnknownURI;
|
|
561
|
+
let isInternalReference = url.stripHash(this.reference.uri) === $refBaseURI;
|
|
562
|
+
let isExternalReference = !isInternalReference;
|
|
563
|
+
this.indirections.push(referencingElement);
|
|
564
|
+
|
|
565
|
+
// determining reference, proper evaluation and selection mechanism
|
|
566
|
+
let referencedElement;
|
|
567
|
+
try {
|
|
568
|
+
if (isUnknownURI || isURL) {
|
|
569
|
+
// we're dealing with canonical URI or URL with possible fragment
|
|
570
|
+
retrievalURI = this.toBaseURI($refBaseURI);
|
|
571
|
+
const selector = $refBaseURI;
|
|
572
|
+
const referenceAsSchema = (0, _util.maybeRefractToSchemaElement)(reference.value.result);
|
|
573
|
+
referencedElement = (0, _uri.evaluate)(selector, referenceAsSchema);
|
|
574
|
+
referencedElement = (0, _util.maybeRefractToSchemaElement)(referencedElement);
|
|
575
|
+
referencedElement.id = identityManager.identify(referencedElement);
|
|
576
|
+
|
|
577
|
+
// ignore resolving internal Schema Objects
|
|
578
|
+
if (!this.options.resolve.internal && isInternalReference) {
|
|
579
|
+
// skip traversing this schema element but traverse all it's child elements
|
|
580
|
+
return undefined;
|
|
581
|
+
}
|
|
582
|
+
// ignore resolving external Schema Objects
|
|
583
|
+
if (!this.options.resolve.external && isExternalReference) {
|
|
584
|
+
// skip traversing this schema element but traverse all it's child elements
|
|
585
|
+
return undefined;
|
|
586
|
+
}
|
|
587
|
+
} else {
|
|
588
|
+
// we're assuming here that we're dealing with JSON Pointer here
|
|
589
|
+
retrievalURI = this.toBaseURI($refBaseURI);
|
|
590
|
+
isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
|
|
591
|
+
isExternalReference = !isInternalReference;
|
|
592
|
+
|
|
593
|
+
// ignore resolving internal Schema Objects
|
|
594
|
+
if (!this.options.resolve.internal && isInternalReference) {
|
|
595
|
+
// skip traversing this schema element but traverse all it's child elements
|
|
596
|
+
return undefined;
|
|
597
|
+
}
|
|
598
|
+
// ignore resolving external Schema Objects
|
|
599
|
+
if (!this.options.resolve.external && isExternalReference) {
|
|
600
|
+
// skip traversing this schema element but traverse all it's child elements
|
|
601
|
+
return undefined;
|
|
602
|
+
}
|
|
603
|
+
reference = await this.toReference(url.unsanitize($refBaseURI));
|
|
604
|
+
const selector = _apidomJsonPointer.URIFragmentIdentifier.fromURIReference($refBaseURI);
|
|
605
|
+
const referenceAsSchema = (0, _util.maybeRefractToSchemaElement)(reference.value.result);
|
|
606
|
+
referencedElement = (0, _apidomJsonPointer.evaluate)(referenceAsSchema, selector);
|
|
607
|
+
referencedElement = (0, _util.maybeRefractToSchemaElement)(referencedElement);
|
|
608
|
+
referencedElement.id = identityManager.identify(referencedElement);
|
|
609
|
+
}
|
|
610
|
+
} catch (error) {
|
|
611
|
+
/**
|
|
612
|
+
* No SchemaElement($id=URL) was not found, so we're going to try to resolve
|
|
613
|
+
* the URL and assume the returned response is a JSON Schema.
|
|
614
|
+
*/
|
|
615
|
+
if (isURL && error instanceof _EvaluationJsonSchemaUriError.default) {
|
|
616
|
+
if ((0, _$anchor.isAnchor)((0, _$anchor.uriToAnchor)($refBaseURI))) {
|
|
617
|
+
// we're dealing with JSON Schema $anchor here
|
|
618
|
+
isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
|
|
619
|
+
isExternalReference = !isInternalReference;
|
|
620
|
+
|
|
621
|
+
// ignore resolving internal Schema Objects
|
|
622
|
+
if (!this.options.resolve.internal && isInternalReference) {
|
|
623
|
+
// skip traversing this schema element but traverse all it's child elements
|
|
624
|
+
return undefined;
|
|
625
|
+
}
|
|
626
|
+
// ignore resolving external Schema Objects
|
|
627
|
+
if (!this.options.resolve.external && isExternalReference) {
|
|
628
|
+
// skip traversing this schema element but traverse all it's child elements
|
|
629
|
+
return undefined;
|
|
630
|
+
}
|
|
631
|
+
reference = await this.toReference(url.unsanitize($refBaseURI));
|
|
632
|
+
const selector = (0, _$anchor.uriToAnchor)($refBaseURI);
|
|
633
|
+
const referenceAsSchema = (0, _util.maybeRefractToSchemaElement)(reference.value.result);
|
|
634
|
+
referencedElement = (0, _$anchor.evaluate)(selector, referenceAsSchema);
|
|
635
|
+
referencedElement = (0, _util.maybeRefractToSchemaElement)(referencedElement);
|
|
636
|
+
referencedElement.id = identityManager.identify(referencedElement);
|
|
637
|
+
} else {
|
|
638
|
+
// we're assuming here that we're dealing with JSON Pointer here
|
|
639
|
+
retrievalURI = this.toBaseURI($refBaseURI);
|
|
640
|
+
isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
|
|
641
|
+
isExternalReference = !isInternalReference;
|
|
642
|
+
|
|
643
|
+
// ignore resolving internal Schema Objects
|
|
644
|
+
if (!this.options.resolve.internal && isInternalReference) {
|
|
645
|
+
// skip traversing this schema element but traverse all it's child elements
|
|
646
|
+
return undefined;
|
|
647
|
+
}
|
|
648
|
+
// ignore resolving external Schema Objects
|
|
649
|
+
if (!this.options.resolve.external && isExternalReference) {
|
|
650
|
+
// skip traversing this schema element but traverse all it's child elements
|
|
651
|
+
return undefined;
|
|
652
|
+
}
|
|
653
|
+
reference = await this.toReference(url.unsanitize($refBaseURI));
|
|
654
|
+
const selector = _apidomJsonPointer.URIFragmentIdentifier.fromURIReference($refBaseURI);
|
|
655
|
+
const referenceAsSchema = (0, _util.maybeRefractToSchemaElement)(reference.value.result);
|
|
656
|
+
referencedElement = (0, _apidomJsonPointer.evaluate)(referenceAsSchema, selector);
|
|
657
|
+
referencedElement = (0, _util.maybeRefractToSchemaElement)(referencedElement);
|
|
658
|
+
referencedElement.id = identityManager.identify(referencedElement);
|
|
659
|
+
}
|
|
660
|
+
} else {
|
|
661
|
+
throw error;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// detect direct or indirect reference
|
|
666
|
+
if (referencingElement === referencedElement) {
|
|
667
|
+
throw new _apidomError.ApiDOMError('Recursive Schema Object reference detected');
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// detect maximum depth of dereferencing
|
|
671
|
+
if (this.indirections.length > this.options.dereference.maxDepth) {
|
|
672
|
+
throw new _MaximumDereferenceDepthError.default(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// detect second deep dive into the same fragment and avoid it
|
|
676
|
+
if (ancestorsLineage.includes(referencedElement)) {
|
|
677
|
+
reference.refSet.circular = true;
|
|
678
|
+
if (this.options.dereference.circular === 'error') {
|
|
679
|
+
throw new _apidomError.ApiDOMError('Circular reference detected');
|
|
680
|
+
} else if (this.options.dereference.circular === 'replace') {
|
|
681
|
+
const refElement = new _apidomCore.RefElement(referencedElement.id, {
|
|
682
|
+
type: 'json-schema',
|
|
683
|
+
uri: reference.uri,
|
|
684
|
+
$ref: (0, _apidomCore.toValue)(referencingElement.$ref)
|
|
685
|
+
});
|
|
686
|
+
const replacer = this.options.dereference.strategyOpts['openapi-3-1']?.circularReplacer ?? this.options.dereference.circularReplacer;
|
|
687
|
+
const replacement = replacer(refElement);
|
|
688
|
+
link.replaceWith(replacement, mutationReplacer);
|
|
689
|
+
return !parent ? replacement : false;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Dive deep into the fragment.
|
|
695
|
+
*
|
|
696
|
+
* Cases to consider:
|
|
697
|
+
* 1. We're crossing document boundary
|
|
698
|
+
* 2. Fragment is from non-root document
|
|
699
|
+
* 3. Fragment is a Schema Object with $ref field. We need to follow it to get the eventual value
|
|
700
|
+
* 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
|
|
701
|
+
*/
|
|
702
|
+
const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri;
|
|
703
|
+
const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
|
|
704
|
+
if ((isExternalReference || isNonRootDocument || (0, _apidomNsOpenapi.isSchemaElement)(referencedElement) && (0, _apidomCore.isStringElement)(referencedElement.$ref) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
|
|
705
|
+
// append referencing reference to ancestors lineage
|
|
706
|
+
directAncestors.add(referencingElement);
|
|
707
|
+
const visitor = new OpenAPI3_1DereferenceVisitor({
|
|
708
|
+
reference,
|
|
709
|
+
namespace: this.namespace,
|
|
710
|
+
indirections: [...this.indirections],
|
|
711
|
+
options: this.options,
|
|
712
|
+
refractCache: this.refractCache,
|
|
713
|
+
ancestors: ancestorsLineage
|
|
714
|
+
});
|
|
715
|
+
referencedElement = await visitAsync(referencedElement, visitor, {
|
|
716
|
+
keyMap: _apidomNsOpenapi.keyMap,
|
|
717
|
+
nodeTypeGetter: _apidomNsOpenapi.getNodeType
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
// remove referencing reference from ancestors lineage
|
|
721
|
+
directAncestors.delete(referencingElement);
|
|
722
|
+
}
|
|
723
|
+
this.indirections.pop();
|
|
724
|
+
|
|
725
|
+
// Boolean JSON Schemas
|
|
726
|
+
if ((0, _apidomNsOpenapi.isBooleanJsonSchemaElement)(referencedElement)) {
|
|
727
|
+
const booleanJsonSchemaElement = (0, _apidomCore.cloneDeep)(referencedElement);
|
|
728
|
+
// assign unique id to merged element
|
|
729
|
+
booleanJsonSchemaElement.setMetaProperty('id', identityManager.generateId());
|
|
730
|
+
// annotate referenced element with info about original referencing element
|
|
731
|
+
booleanJsonSchemaElement.setMetaProperty('ref-fields', {
|
|
732
|
+
$ref: (0, _apidomCore.toValue)(referencingElement.$ref)
|
|
733
|
+
});
|
|
734
|
+
// annotate referenced element with info about origin
|
|
735
|
+
booleanJsonSchemaElement.setMetaProperty('ref-origin', reference.uri);
|
|
736
|
+
// annotate fragment with info about referencing element
|
|
737
|
+
booleanJsonSchemaElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
|
|
738
|
+
link.replaceWith(booleanJsonSchemaElement, mutationReplacer);
|
|
739
|
+
return !parent ? booleanJsonSchemaElement : false;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Creating a new version of Schema Object by merging fields from referenced Schema Object with referencing one.
|
|
744
|
+
*/
|
|
745
|
+
if ((0, _apidomNsOpenapi.isSchemaElement)(referencedElement)) {
|
|
746
|
+
const mergedElement = new _apidomNsOpenapi.SchemaElement([...referencedElement.content], (0, _apidomCore.cloneDeep)(referencedElement.meta), (0, _apidomCore.cloneDeep)(referencedElement.attributes));
|
|
747
|
+
// assign unique id to merged element
|
|
748
|
+
mergedElement.setMetaProperty('id', identityManager.generateId());
|
|
749
|
+
// existing keywords from referencing schema overrides ones from referenced schema
|
|
750
|
+
referencingElement.forEach((value, keyElement, item) => {
|
|
751
|
+
mergedElement.remove((0, _apidomCore.toValue)(keyElement));
|
|
752
|
+
mergedElement.content.push(item);
|
|
753
|
+
});
|
|
754
|
+
mergedElement.remove('$ref');
|
|
755
|
+
// annotate referenced element with info about original referencing element
|
|
756
|
+
mergedElement.setMetaProperty('ref-fields', {
|
|
757
|
+
$ref: (0, _apidomCore.toValue)(referencingElement.$ref)
|
|
758
|
+
});
|
|
759
|
+
// annotate fragment with info about origin
|
|
760
|
+
mergedElement.setMetaProperty('ref-origin', reference.uri);
|
|
761
|
+
// annotate fragment with info about referencing element
|
|
762
|
+
mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
|
|
763
|
+
referencedElement = mergedElement;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Transclude referencing element with merged referenced element.
|
|
767
|
+
*/
|
|
768
|
+
link.replaceWith(referencedElement, mutationReplacer);
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* We're at the root of the tree, so we're just replacing the entire tree.
|
|
772
|
+
*/
|
|
773
|
+
return !parent ? referencedElement : undefined;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
var _default = exports.default = OpenAPI3_1DereferenceVisitor;
|