@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,96 @@
|
|
|
1
|
+
import { propEq } from 'ramda';
|
|
2
|
+
import { createNamespace, visit, cloneDeep } from '@speclynx/apidom-core';
|
|
3
|
+
import openApi3_1Namespace, { getNodeType, isOpenApi3_1Element, keyMap, mediaTypes } from '@speclynx/apidom-ns-openapi-3-1';
|
|
4
|
+
import DereferenceStrategy from "../DereferenceStrategy.mjs";
|
|
5
|
+
import Reference from "../../../Reference.mjs";
|
|
6
|
+
import ReferenceSet from "../../../ReferenceSet.mjs";
|
|
7
|
+
import OpenAPI3_1DereferenceVisitor from "./visitor.mjs";
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const visitAsync = visit[Symbol.for('nodejs.util.promisify.custom')];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
class OpenAPI3_1DereferenceStrategy extends DereferenceStrategy {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
super({
|
|
21
|
+
...(options ?? {}),
|
|
22
|
+
name: 'openapi-3-1'
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
canDereference(file) {
|
|
26
|
+
// assert by media type
|
|
27
|
+
if (file.mediaType !== 'text/plain') {
|
|
28
|
+
return mediaTypes.includes(file.mediaType);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// assert by inspecting ApiDOM
|
|
32
|
+
return isOpenApi3_1Element(file.parseResult?.result);
|
|
33
|
+
}
|
|
34
|
+
async dereference(file, options) {
|
|
35
|
+
const namespace = createNamespace(openApi3_1Namespace);
|
|
36
|
+
const immutableRefSet = options.dereference.refSet ?? new ReferenceSet();
|
|
37
|
+
const mutableRefSet = new ReferenceSet();
|
|
38
|
+
let refSet = immutableRefSet;
|
|
39
|
+
let reference;
|
|
40
|
+
if (!immutableRefSet.has(file.uri)) {
|
|
41
|
+
reference = new Reference({
|
|
42
|
+
uri: file.uri,
|
|
43
|
+
value: file.parseResult
|
|
44
|
+
});
|
|
45
|
+
immutableRefSet.add(reference);
|
|
46
|
+
} else {
|
|
47
|
+
// pre-computed refSet was provided as configuration option
|
|
48
|
+
reference = immutableRefSet.find(propEq(file.uri, 'uri'));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Clone refSet due the dereferencing process being mutable.
|
|
53
|
+
* We don't want to mutate the original refSet and the references.
|
|
54
|
+
*/
|
|
55
|
+
if (options.dereference.immutable) {
|
|
56
|
+
immutableRefSet.refs.map(ref => new Reference({
|
|
57
|
+
...ref,
|
|
58
|
+
value: cloneDeep(ref.value)
|
|
59
|
+
})).forEach(ref => mutableRefSet.add(ref));
|
|
60
|
+
reference = mutableRefSet.find(ref => ref.uri === file.uri);
|
|
61
|
+
refSet = mutableRefSet;
|
|
62
|
+
}
|
|
63
|
+
const visitor = new OpenAPI3_1DereferenceVisitor({
|
|
64
|
+
reference: reference,
|
|
65
|
+
namespace,
|
|
66
|
+
options
|
|
67
|
+
});
|
|
68
|
+
const dereferencedElement = await visitAsync(refSet.rootRef.value, visitor, {
|
|
69
|
+
keyMap,
|
|
70
|
+
nodeTypeGetter: getNodeType
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* If immutable option is set, replay refs from the refSet.
|
|
75
|
+
*/
|
|
76
|
+
if (options.dereference.immutable) {
|
|
77
|
+
mutableRefSet.refs.filter(ref => ref.uri.startsWith('immutable://')).map(ref => new Reference({
|
|
78
|
+
...ref,
|
|
79
|
+
uri: ref.uri.replace(/^immutable:\/\//, '')
|
|
80
|
+
})).forEach(ref => immutableRefSet.add(ref));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Release all memory if this refSet was not provided as an configuration option.
|
|
85
|
+
* If provided as configuration option, then provider is responsible for cleanup.
|
|
86
|
+
*/
|
|
87
|
+
if (options.dereference.refSet === null) {
|
|
88
|
+
immutableRefSet.clean();
|
|
89
|
+
}
|
|
90
|
+
mutableRefSet.clean();
|
|
91
|
+
return dereferencedElement;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export { OpenAPI3_1DereferenceVisitor };
|
|
95
|
+
export { resolveSchema$refField, resolveSchema$idField, maybeRefractToSchemaElement } from "./util.mjs";
|
|
96
|
+
export default OpenAPI3_1DereferenceStrategy;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.uriToAnchor = exports.parse = exports.isAnchor = exports.evaluate = exports.JsonSchema$anchorError = void 0;
|
|
6
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
7
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
8
|
+
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-1");
|
|
9
|
+
var _url = require("../../../../util/url.cjs");
|
|
10
|
+
var _EvaluationJsonSchema$anchorError = _interopRequireDefault(require("../../../../errors/EvaluationJsonSchema$anchorError.cjs"));
|
|
11
|
+
exports.EvaluationJsonSchema$anchorError = _EvaluationJsonSchema$anchorError.default;
|
|
12
|
+
var _InvalidJsonSchema$anchorError = _interopRequireDefault(require("../../../../errors/InvalidJsonSchema$anchorError.cjs"));
|
|
13
|
+
exports.InvalidJsonSchema$anchorError = _InvalidJsonSchema$anchorError.default;
|
|
14
|
+
var _JsonSchema$anchorError = _interopRequireDefault(require("../../../../errors/JsonSchema$anchorError.cjs"));
|
|
15
|
+
exports.JsonSchema$anchorError = _JsonSchema$anchorError.default;
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
const isAnchor = uri => {
|
|
20
|
+
/**
|
|
21
|
+
* MUST start with a letter ([A-Za-z]) or underscore ("_"), followed by any number of letters,
|
|
22
|
+
* digits ([0-9]), hyphens ("-"), underscores ("_"), and periods (".").
|
|
23
|
+
*
|
|
24
|
+
* https://json-schema.org/draft/2020-12/json-schema-core.html#rfc.section.8.2.2
|
|
25
|
+
*/
|
|
26
|
+
return /^[A-Za-z_][A-Za-z_0-9.-]*$/.test(uri);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
exports.isAnchor = isAnchor;
|
|
33
|
+
const uriToAnchor = uri => {
|
|
34
|
+
const hash = (0, _url.getHash)(uri);
|
|
35
|
+
return (0, _ramdaAdjunct.trimCharsStart)('#', hash);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
exports.uriToAnchor = uriToAnchor;
|
|
42
|
+
const parse = anchor => {
|
|
43
|
+
if (!isAnchor(anchor)) {
|
|
44
|
+
throw new _InvalidJsonSchema$anchorError.default(anchor);
|
|
45
|
+
}
|
|
46
|
+
return anchor;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Evaluates JSON Schema $anchor against ApiDOM fragment.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
exports.parse = parse;
|
|
54
|
+
const evaluate = (anchor, element) => {
|
|
55
|
+
const token = parse(anchor);
|
|
56
|
+
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
const result = (0, _apidomCore.find)(e => (0, _apidomNsOpenapi.isSchemaElement)(e) && (0, _apidomCore.toValue)(e.$anchor) === token, element);
|
|
59
|
+
if ((0, _ramdaAdjunct.isUndefined)(result)) {
|
|
60
|
+
throw new _EvaluationJsonSchema$anchorError.default(`Evaluation failed on token: "${token}"`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
return result;
|
|
65
|
+
};
|
|
66
|
+
exports.evaluate = evaluate;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { trimCharsStart, isUndefined } from 'ramda-adjunct';
|
|
2
|
+
import { find, toValue } from '@speclynx/apidom-core';
|
|
3
|
+
import { isSchemaElement } from '@speclynx/apidom-ns-openapi-3-1';
|
|
4
|
+
import { getHash } from "../../../../util/url.mjs";
|
|
5
|
+
import EvaluationJsonSchema$anchorError from "../../../../errors/EvaluationJsonSchema$anchorError.mjs";
|
|
6
|
+
import InvalidJsonSchema$anchorError from "../../../../errors/InvalidJsonSchema$anchorError.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export const isAnchor = uri => {
|
|
11
|
+
/**
|
|
12
|
+
* MUST start with a letter ([A-Za-z]) or underscore ("_"), followed by any number of letters,
|
|
13
|
+
* digits ([0-9]), hyphens ("-"), underscores ("_"), and periods (".").
|
|
14
|
+
*
|
|
15
|
+
* https://json-schema.org/draft/2020-12/json-schema-core.html#rfc.section.8.2.2
|
|
16
|
+
*/
|
|
17
|
+
return /^[A-Za-z_][A-Za-z_0-9.-]*$/.test(uri);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export const uriToAnchor = uri => {
|
|
24
|
+
const hash = getHash(uri);
|
|
25
|
+
return trimCharsStart('#', hash);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export const parse = anchor => {
|
|
32
|
+
if (!isAnchor(anchor)) {
|
|
33
|
+
throw new InvalidJsonSchema$anchorError(anchor);
|
|
34
|
+
}
|
|
35
|
+
return anchor;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Evaluates JSON Schema $anchor against ApiDOM fragment.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export const evaluate = (anchor, element) => {
|
|
43
|
+
const token = parse(anchor);
|
|
44
|
+
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
const result = find(e => isSchemaElement(e) && toValue(e.$anchor) === token, element);
|
|
47
|
+
if (isUndefined(result)) {
|
|
48
|
+
throw new EvaluationJsonSchema$anchorError(`Evaluation failed on token: "${token}"`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
export { EvaluationJsonSchema$anchorError, InvalidJsonSchema$anchorError };
|
|
55
|
+
export { default as JsonSchema$anchorError } from "../../../../errors/JsonSchema$anchorError.mjs";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.evaluate = exports.JsonSchemaUriError = void 0;
|
|
7
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
8
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
9
|
+
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-1");
|
|
10
|
+
var _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
|
|
11
|
+
var url = _interopRequireWildcard(require("../../../../util/url.cjs"));
|
|
12
|
+
var _EvaluationJsonSchemaUriError = _interopRequireDefault(require("../../../../errors/EvaluationJsonSchemaUriError.cjs"));
|
|
13
|
+
exports.EvaluationJsonSchemaUriError = _EvaluationJsonSchemaUriError.default;
|
|
14
|
+
var _$anchor = require("./$anchor.cjs");
|
|
15
|
+
var _util = require("../util.cjs");
|
|
16
|
+
var _JsonSchemaUriError = _interopRequireDefault(require("../../../../errors/JsonSchemaUriError.cjs"));
|
|
17
|
+
exports.JsonSchemaUriError = _JsonSchemaUriError.default;
|
|
18
|
+
/**
|
|
19
|
+
* Evaluates JSON Schema $ref containing unknown URI against ApiDOM fragment.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
const evaluate = (uri, element) => {
|
|
23
|
+
const {
|
|
24
|
+
cache
|
|
25
|
+
} = evaluate;
|
|
26
|
+
const uriStrippedHash = url.stripHash(uri);
|
|
27
|
+
const isSchemaElementWith$id = e => (0, _apidomNsOpenapi.isSchemaElement)(e) && typeof e.$id !== 'undefined';
|
|
28
|
+
|
|
29
|
+
// warm the cache
|
|
30
|
+
if (!cache.has(element)) {
|
|
31
|
+
const schemaObjectElements = (0, _apidomCore.filter)(isSchemaElementWith$id, element);
|
|
32
|
+
cache.set(element, Array.from(schemaObjectElements));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// search for the matching schema
|
|
36
|
+
const result = cache.get(element).find(e => {
|
|
37
|
+
const $idBaseURI = (0, _util.resolveSchema$idField)(uriStrippedHash, e);
|
|
38
|
+
return $idBaseURI === uriStrippedHash;
|
|
39
|
+
});
|
|
40
|
+
if ((0, _ramdaAdjunct.isUndefined)(result)) {
|
|
41
|
+
throw new _EvaluationJsonSchemaUriError.default(`Evaluation failed on URI: "${uri}"`);
|
|
42
|
+
}
|
|
43
|
+
if ((0, _$anchor.isAnchor)((0, _$anchor.uriToAnchor)(uri))) {
|
|
44
|
+
// we're dealing with JSON Schema $anchor here
|
|
45
|
+
return (0, _$anchor.evaluate)((0, _$anchor.uriToAnchor)(uri), result);
|
|
46
|
+
}
|
|
47
|
+
return (0, _apidomJsonPointer.evaluate)(result, _apidomJsonPointer.URIFragmentIdentifier.fromURIReference(uri));
|
|
48
|
+
};
|
|
49
|
+
exports.evaluate = evaluate;
|
|
50
|
+
evaluate.cache = new WeakMap();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isUndefined } from 'ramda-adjunct';
|
|
2
|
+
import { filter } from '@speclynx/apidom-core';
|
|
3
|
+
import { isSchemaElement } from '@speclynx/apidom-ns-openapi-3-1';
|
|
4
|
+
import { URIFragmentIdentifier, evaluate as jsonPointerEvaluate } from '@speclynx/apidom-json-pointer';
|
|
5
|
+
import * as url from "../../../../util/url.mjs";
|
|
6
|
+
import EvaluationJsonSchemaUriError from "../../../../errors/EvaluationJsonSchemaUriError.mjs";
|
|
7
|
+
import { isAnchor, uriToAnchor, evaluate as $anchorEvaluate } from "./$anchor.mjs";
|
|
8
|
+
import { resolveSchema$idField } from "../util.mjs";
|
|
9
|
+
/**
|
|
10
|
+
* Evaluates JSON Schema $ref containing unknown URI against ApiDOM fragment.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export const evaluate = (uri, element) => {
|
|
14
|
+
const {
|
|
15
|
+
cache
|
|
16
|
+
} = evaluate;
|
|
17
|
+
const uriStrippedHash = url.stripHash(uri);
|
|
18
|
+
const isSchemaElementWith$id = e => isSchemaElement(e) && typeof e.$id !== 'undefined';
|
|
19
|
+
|
|
20
|
+
// warm the cache
|
|
21
|
+
if (!cache.has(element)) {
|
|
22
|
+
const schemaObjectElements = filter(isSchemaElementWith$id, element);
|
|
23
|
+
cache.set(element, Array.from(schemaObjectElements));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// search for the matching schema
|
|
27
|
+
const result = cache.get(element).find(e => {
|
|
28
|
+
const $idBaseURI = resolveSchema$idField(uriStrippedHash, e);
|
|
29
|
+
return $idBaseURI === uriStrippedHash;
|
|
30
|
+
});
|
|
31
|
+
if (isUndefined(result)) {
|
|
32
|
+
throw new EvaluationJsonSchemaUriError(`Evaluation failed on URI: "${uri}"`);
|
|
33
|
+
}
|
|
34
|
+
if (isAnchor(uriToAnchor(uri))) {
|
|
35
|
+
// we're dealing with JSON Schema $anchor here
|
|
36
|
+
return $anchorEvaluate(uriToAnchor(uri), result);
|
|
37
|
+
}
|
|
38
|
+
return jsonPointerEvaluate(result, URIFragmentIdentifier.fromURIReference(uri));
|
|
39
|
+
};
|
|
40
|
+
evaluate.cache = new WeakMap();
|
|
41
|
+
export { EvaluationJsonSchemaUriError };
|
|
42
|
+
export { default as JsonSchemaUriError } from "../../../../errors/JsonSchemaUriError.mjs";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.resolveSchema$refField = exports.resolveSchema$idField = exports.refractToSchemaElement = exports.maybeRefractToSchemaElement = void 0;
|
|
6
|
+
var _ramda = require("ramda");
|
|
7
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
8
|
+
var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-1");
|
|
9
|
+
var url = _interopRequireWildcard(require("../../../util/url.cjs"));
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
const resolveSchema$refField = (retrievalURI, schemaElement) => {
|
|
14
|
+
if (typeof schemaElement.$ref === 'undefined') {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const hash = url.getHash((0, _apidomCore.toValue)(schemaElement.$ref));
|
|
18
|
+
const ancestorsSchemaIdentifiers = (0, _apidomCore.toValue)(schemaElement.meta.get('ancestorsSchemaIdentifiers'));
|
|
19
|
+
const $refBaseURI = (0, _ramda.reduce)((acc, uri) => {
|
|
20
|
+
return url.resolve(acc, url.sanitize(url.stripHash(uri)));
|
|
21
|
+
}, retrievalURI, [...ancestorsSchemaIdentifiers, (0, _apidomCore.toValue)(schemaElement.$ref)]);
|
|
22
|
+
return `${$refBaseURI}${hash === '#' ? '' : hash}`;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
exports.resolveSchema$refField = resolveSchema$refField;
|
|
29
|
+
const resolveSchema$idField = (retrievalURI, schemaElement) => {
|
|
30
|
+
if (typeof schemaElement.$id === 'undefined') {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const ancestorsSchemaIdentifiers = (0, _apidomCore.toValue)(schemaElement.meta.get('ancestorsSchemaIdentifiers'));
|
|
34
|
+
return (0, _ramda.reduce)((acc, $id) => {
|
|
35
|
+
return url.resolve(acc, url.sanitize(url.stripHash($id)));
|
|
36
|
+
}, retrievalURI, ancestorsSchemaIdentifiers);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Cached version of SchemaElement.refract.
|
|
41
|
+
*/
|
|
42
|
+
exports.resolveSchema$idField = resolveSchema$idField;
|
|
43
|
+
const refractToSchemaElement = element => {
|
|
44
|
+
if (refractToSchemaElement.cache.has(element)) {
|
|
45
|
+
return refractToSchemaElement.cache.get(element);
|
|
46
|
+
}
|
|
47
|
+
const refracted = _apidomNsOpenapi.SchemaElement.refract(element);
|
|
48
|
+
refractToSchemaElement.cache.set(element, refracted);
|
|
49
|
+
return refracted;
|
|
50
|
+
};
|
|
51
|
+
exports.refractToSchemaElement = refractToSchemaElement;
|
|
52
|
+
refractToSchemaElement.cache = new WeakMap();
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
const maybeRefractToSchemaElement = element => {
|
|
58
|
+
/**
|
|
59
|
+
* Conditional version of refractToSchemaElement, that acts as an identity
|
|
60
|
+
* function for all non-primitive Element instances.
|
|
61
|
+
*/
|
|
62
|
+
if ((0, _apidomCore.isPrimitiveElement)(element)) {
|
|
63
|
+
return refractToSchemaElement(element);
|
|
64
|
+
}
|
|
65
|
+
return element;
|
|
66
|
+
};
|
|
67
|
+
exports.maybeRefractToSchemaElement = maybeRefractToSchemaElement;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { reduce } from 'ramda';
|
|
2
|
+
import { isPrimitiveElement, toValue } from '@speclynx/apidom-core';
|
|
3
|
+
import { SchemaElement } from '@speclynx/apidom-ns-openapi-3-1';
|
|
4
|
+
import * as url from "../../../util/url.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export const resolveSchema$refField = (retrievalURI, schemaElement) => {
|
|
9
|
+
if (typeof schemaElement.$ref === 'undefined') {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const hash = url.getHash(toValue(schemaElement.$ref));
|
|
13
|
+
const ancestorsSchemaIdentifiers = toValue(schemaElement.meta.get('ancestorsSchemaIdentifiers'));
|
|
14
|
+
const $refBaseURI = reduce((acc, uri) => {
|
|
15
|
+
return url.resolve(acc, url.sanitize(url.stripHash(uri)));
|
|
16
|
+
}, retrievalURI, [...ancestorsSchemaIdentifiers, toValue(schemaElement.$ref)]);
|
|
17
|
+
return `${$refBaseURI}${hash === '#' ? '' : hash}`;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export const resolveSchema$idField = (retrievalURI, schemaElement) => {
|
|
24
|
+
if (typeof schemaElement.$id === 'undefined') {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const ancestorsSchemaIdentifiers = toValue(schemaElement.meta.get('ancestorsSchemaIdentifiers'));
|
|
28
|
+
return reduce((acc, $id) => {
|
|
29
|
+
return url.resolve(acc, url.sanitize(url.stripHash($id)));
|
|
30
|
+
}, retrievalURI, ancestorsSchemaIdentifiers);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Cached version of SchemaElement.refract.
|
|
35
|
+
*/
|
|
36
|
+
export const refractToSchemaElement = element => {
|
|
37
|
+
if (refractToSchemaElement.cache.has(element)) {
|
|
38
|
+
return refractToSchemaElement.cache.get(element);
|
|
39
|
+
}
|
|
40
|
+
const refracted = SchemaElement.refract(element);
|
|
41
|
+
refractToSchemaElement.cache.set(element, refracted);
|
|
42
|
+
return refracted;
|
|
43
|
+
};
|
|
44
|
+
refractToSchemaElement.cache = new WeakMap();
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export const maybeRefractToSchemaElement = element => {
|
|
50
|
+
/**
|
|
51
|
+
* Conditional version of refractToSchemaElement, that acts as an identity
|
|
52
|
+
* function for all non-primitive Element instances.
|
|
53
|
+
*/
|
|
54
|
+
if (isPrimitiveElement(element)) {
|
|
55
|
+
return refractToSchemaElement(element);
|
|
56
|
+
}
|
|
57
|
+
return element;
|
|
58
|
+
};
|