@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,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _ramda = require("ramda");
|
|
7
|
+
var _apidomParserAdapterOpenapiJson = require("@speclynx/apidom-parser-adapter-openapi-json-3-1");
|
|
8
|
+
var _ParserError = _interopRequireDefault(require("../../../errors/ParserError.cjs"));
|
|
9
|
+
var _Parser = _interopRequireDefault(require("../Parser.cjs"));
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class OpenAPIJSON3_1Parser extends _Parser.default {
|
|
18
|
+
syntacticAnalysis;
|
|
19
|
+
refractorOpts;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
const {
|
|
22
|
+
fileExtensions = [],
|
|
23
|
+
mediaTypes = _apidomParserAdapterOpenapiJson.mediaTypes,
|
|
24
|
+
...rest
|
|
25
|
+
} = options ?? {};
|
|
26
|
+
super({
|
|
27
|
+
...rest,
|
|
28
|
+
name: 'openapi-json-3-1',
|
|
29
|
+
fileExtensions,
|
|
30
|
+
mediaTypes
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async canParse(file) {
|
|
34
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
35
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
36
|
+
if (!hasSupportedFileExtension) return false;
|
|
37
|
+
if (hasSupportedMediaType) return true;
|
|
38
|
+
if (!hasSupportedMediaType) {
|
|
39
|
+
return (0, _apidomParserAdapterOpenapiJson.detect)(file.toString());
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
async parse(file) {
|
|
44
|
+
const source = file.toString();
|
|
45
|
+
try {
|
|
46
|
+
const parserOpts = (0, _ramda.pick)(['sourceMap', 'syntacticAnalysis', 'refractorOpts'], this);
|
|
47
|
+
return await (0, _apidomParserAdapterOpenapiJson.parse)(source, parserOpts);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw new _ParserError.default(`Error parsing "${file.uri}"`, {
|
|
50
|
+
cause: error
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
var _default = exports.default = OpenAPIJSON3_1Parser;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { pick } from 'ramda';
|
|
2
|
+
import { parse, mediaTypes as OpenAPI3_1MediaTypes, detect } from '@speclynx/apidom-parser-adapter-openapi-json-3-1';
|
|
3
|
+
import ParserError from "../../../errors/ParserError.mjs";
|
|
4
|
+
import Parser from "../Parser.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class OpenAPIJSON3_1Parser extends Parser {
|
|
12
|
+
syntacticAnalysis;
|
|
13
|
+
refractorOpts;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
const {
|
|
16
|
+
fileExtensions = [],
|
|
17
|
+
mediaTypes = OpenAPI3_1MediaTypes,
|
|
18
|
+
...rest
|
|
19
|
+
} = options ?? {};
|
|
20
|
+
super({
|
|
21
|
+
...rest,
|
|
22
|
+
name: 'openapi-json-3-1',
|
|
23
|
+
fileExtensions,
|
|
24
|
+
mediaTypes
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async canParse(file) {
|
|
28
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
29
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
30
|
+
if (!hasSupportedFileExtension) return false;
|
|
31
|
+
if (hasSupportedMediaType) return true;
|
|
32
|
+
if (!hasSupportedMediaType) {
|
|
33
|
+
return detect(file.toString());
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
async parse(file) {
|
|
38
|
+
const source = file.toString();
|
|
39
|
+
try {
|
|
40
|
+
const parserOpts = pick(['sourceMap', 'syntacticAnalysis', 'refractorOpts'], this);
|
|
41
|
+
return await parse(source, parserOpts);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw new ParserError(`Error parsing "${file.uri}"`, {
|
|
44
|
+
cause: error
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export default OpenAPIJSON3_1Parser;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _ramda = require("ramda");
|
|
7
|
+
var _apidomParserAdapterOpenapiYaml = require("@speclynx/apidom-parser-adapter-openapi-yaml-2");
|
|
8
|
+
var _ParserError = _interopRequireDefault(require("../../../errors/ParserError.cjs"));
|
|
9
|
+
var _Parser = _interopRequireDefault(require("../Parser.cjs"));
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class OpenAPIYAML2Parser extends _Parser.default {
|
|
18
|
+
refractorOpts;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
const {
|
|
21
|
+
fileExtensions = [],
|
|
22
|
+
mediaTypes = _apidomParserAdapterOpenapiYaml.mediaTypes,
|
|
23
|
+
...rest
|
|
24
|
+
} = options ?? {};
|
|
25
|
+
super({
|
|
26
|
+
...rest,
|
|
27
|
+
name: 'openapi-yaml-2',
|
|
28
|
+
fileExtensions,
|
|
29
|
+
mediaTypes
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async canParse(file) {
|
|
33
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
34
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
35
|
+
if (!hasSupportedFileExtension) return false;
|
|
36
|
+
if (hasSupportedMediaType) return true;
|
|
37
|
+
if (!hasSupportedMediaType) {
|
|
38
|
+
return (0, _apidomParserAdapterOpenapiYaml.detect)(file.toString());
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
async parse(file) {
|
|
43
|
+
const source = file.toString();
|
|
44
|
+
try {
|
|
45
|
+
const parserOpts = (0, _ramda.pick)(['sourceMap', 'refractorOpts'], this);
|
|
46
|
+
return await (0, _apidomParserAdapterOpenapiYaml.parse)(source, parserOpts);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new _ParserError.default(`Error parsing "${file.uri}"`, {
|
|
49
|
+
cause: error
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
var _default = exports.default = OpenAPIYAML2Parser;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { pick } from 'ramda';
|
|
2
|
+
import { parse, mediaTypes as OpenAPIYAML2MediaTypes, detect } from '@speclynx/apidom-parser-adapter-openapi-yaml-2';
|
|
3
|
+
import ParserError from "../../../errors/ParserError.mjs";
|
|
4
|
+
import Parser from "../Parser.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class OpenAPIYAML2Parser extends Parser {
|
|
12
|
+
refractorOpts;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
const {
|
|
15
|
+
fileExtensions = [],
|
|
16
|
+
mediaTypes = OpenAPIYAML2MediaTypes,
|
|
17
|
+
...rest
|
|
18
|
+
} = options ?? {};
|
|
19
|
+
super({
|
|
20
|
+
...rest,
|
|
21
|
+
name: 'openapi-yaml-2',
|
|
22
|
+
fileExtensions,
|
|
23
|
+
mediaTypes
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async canParse(file) {
|
|
27
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
28
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
29
|
+
if (!hasSupportedFileExtension) return false;
|
|
30
|
+
if (hasSupportedMediaType) return true;
|
|
31
|
+
if (!hasSupportedMediaType) {
|
|
32
|
+
return detect(file.toString());
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
async parse(file) {
|
|
37
|
+
const source = file.toString();
|
|
38
|
+
try {
|
|
39
|
+
const parserOpts = pick(['sourceMap', 'refractorOpts'], this);
|
|
40
|
+
return await parse(source, parserOpts);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new ParserError(`Error parsing "${file.uri}"`, {
|
|
43
|
+
cause: error
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export default OpenAPIYAML2Parser;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _ramda = require("ramda");
|
|
7
|
+
var _apidomParserAdapterOpenapiYaml = require("@speclynx/apidom-parser-adapter-openapi-yaml-3-0");
|
|
8
|
+
var _ParserError = _interopRequireDefault(require("../../../errors/ParserError.cjs"));
|
|
9
|
+
var _Parser = _interopRequireDefault(require("../Parser.cjs"));
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class OpenAPIYAML3_0Parser extends _Parser.default {
|
|
18
|
+
refractorOpts;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
const {
|
|
21
|
+
fileExtensions = [],
|
|
22
|
+
mediaTypes = _apidomParserAdapterOpenapiYaml.mediaTypes,
|
|
23
|
+
...rest
|
|
24
|
+
} = options ?? {};
|
|
25
|
+
super({
|
|
26
|
+
...rest,
|
|
27
|
+
name: 'openapi-yaml-3-0',
|
|
28
|
+
fileExtensions,
|
|
29
|
+
mediaTypes
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async canParse(file) {
|
|
33
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
34
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
35
|
+
if (!hasSupportedFileExtension) return false;
|
|
36
|
+
if (hasSupportedMediaType) return true;
|
|
37
|
+
if (!hasSupportedMediaType) {
|
|
38
|
+
return (0, _apidomParserAdapterOpenapiYaml.detect)(file.toString());
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
async parse(file) {
|
|
43
|
+
const source = file.toString();
|
|
44
|
+
try {
|
|
45
|
+
const parserOpts = (0, _ramda.pick)(['sourceMap', 'refractorOpts'], this);
|
|
46
|
+
return await (0, _apidomParserAdapterOpenapiYaml.parse)(source, parserOpts);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new _ParserError.default(`Error parsing "${file.uri}"`, {
|
|
49
|
+
cause: error
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
var _default = exports.default = OpenAPIYAML3_0Parser;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { pick } from 'ramda';
|
|
2
|
+
import { parse, mediaTypes as OpenAPIYAML3_0MediaTypes, detect } from '@speclynx/apidom-parser-adapter-openapi-yaml-3-0';
|
|
3
|
+
import ParserError from "../../../errors/ParserError.mjs";
|
|
4
|
+
import Parser from "../Parser.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class OpenAPIYAML3_0Parser extends Parser {
|
|
12
|
+
refractorOpts;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
const {
|
|
15
|
+
fileExtensions = [],
|
|
16
|
+
mediaTypes = OpenAPIYAML3_0MediaTypes,
|
|
17
|
+
...rest
|
|
18
|
+
} = options ?? {};
|
|
19
|
+
super({
|
|
20
|
+
...rest,
|
|
21
|
+
name: 'openapi-yaml-3-0',
|
|
22
|
+
fileExtensions,
|
|
23
|
+
mediaTypes
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async canParse(file) {
|
|
27
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
28
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
29
|
+
if (!hasSupportedFileExtension) return false;
|
|
30
|
+
if (hasSupportedMediaType) return true;
|
|
31
|
+
if (!hasSupportedMediaType) {
|
|
32
|
+
return detect(file.toString());
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
async parse(file) {
|
|
37
|
+
const source = file.toString();
|
|
38
|
+
try {
|
|
39
|
+
const parserOpts = pick(['sourceMap', 'refractorOpts'], this);
|
|
40
|
+
return await parse(source, parserOpts);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new ParserError(`Error parsing "${file.uri}"`, {
|
|
43
|
+
cause: error
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export default OpenAPIYAML3_0Parser;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _ramda = require("ramda");
|
|
7
|
+
var _apidomParserAdapterOpenapiYaml = require("@speclynx/apidom-parser-adapter-openapi-yaml-3-1");
|
|
8
|
+
var _ParserError = _interopRequireDefault(require("../../../errors/ParserError.cjs"));
|
|
9
|
+
var _Parser = _interopRequireDefault(require("../Parser.cjs"));
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class OpenAPIYAML3_1Parser extends _Parser.default {
|
|
18
|
+
refractorOpts;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
const {
|
|
21
|
+
fileExtensions = [],
|
|
22
|
+
mediaTypes = _apidomParserAdapterOpenapiYaml.mediaTypes,
|
|
23
|
+
...rest
|
|
24
|
+
} = options ?? {};
|
|
25
|
+
super({
|
|
26
|
+
...rest,
|
|
27
|
+
name: 'openapi-yaml-3-1',
|
|
28
|
+
fileExtensions,
|
|
29
|
+
mediaTypes
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async canParse(file) {
|
|
33
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
34
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
35
|
+
if (!hasSupportedFileExtension) return false;
|
|
36
|
+
if (hasSupportedMediaType) return true;
|
|
37
|
+
if (!hasSupportedMediaType) {
|
|
38
|
+
return (0, _apidomParserAdapterOpenapiYaml.detect)(file.toString());
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
async parse(file) {
|
|
43
|
+
const source = file.toString();
|
|
44
|
+
try {
|
|
45
|
+
const parserOpts = (0, _ramda.pick)(['sourceMap', 'refractorOpts'], this);
|
|
46
|
+
return await (0, _apidomParserAdapterOpenapiYaml.parse)(source, parserOpts);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new _ParserError.default(`Error parsing "${file.uri}"`, {
|
|
49
|
+
cause: error
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
var _default = exports.default = OpenAPIYAML3_1Parser;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { pick } from 'ramda';
|
|
2
|
+
import { parse, mediaTypes as OpenAPIYAML3_1MediaTypes, detect } from '@speclynx/apidom-parser-adapter-openapi-yaml-3-1';
|
|
3
|
+
import ParserError from "../../../errors/ParserError.mjs";
|
|
4
|
+
import Parser from "../Parser.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class OpenAPIYAML3_1Parser extends Parser {
|
|
12
|
+
refractorOpts;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
const {
|
|
15
|
+
fileExtensions = [],
|
|
16
|
+
mediaTypes = OpenAPIYAML3_1MediaTypes,
|
|
17
|
+
...rest
|
|
18
|
+
} = options ?? {};
|
|
19
|
+
super({
|
|
20
|
+
...rest,
|
|
21
|
+
name: 'openapi-yaml-3-1',
|
|
22
|
+
fileExtensions,
|
|
23
|
+
mediaTypes
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async canParse(file) {
|
|
27
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
28
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
29
|
+
if (!hasSupportedFileExtension) return false;
|
|
30
|
+
if (hasSupportedMediaType) return true;
|
|
31
|
+
if (!hasSupportedMediaType) {
|
|
32
|
+
return detect(file.toString());
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
async parse(file) {
|
|
37
|
+
const source = file.toString();
|
|
38
|
+
try {
|
|
39
|
+
const parserOpts = pick(['sourceMap', 'refractorOpts'], this);
|
|
40
|
+
return await parse(source, parserOpts);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new ParserError(`Error parsing "${file.uri}"`, {
|
|
43
|
+
cause: error
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export default OpenAPIYAML3_1Parser;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _apidomParserAdapterYaml = require("@speclynx/apidom-parser-adapter-yaml-1-2");
|
|
7
|
+
var _ParserError = _interopRequireDefault(require("../../../errors/ParserError.cjs"));
|
|
8
|
+
var _Parser = _interopRequireDefault(require("../Parser.cjs"));
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
class YAML1Parser extends _Parser.default {
|
|
17
|
+
refractorOpts;
|
|
18
|
+
constructor(options) {
|
|
19
|
+
const {
|
|
20
|
+
fileExtensions = [],
|
|
21
|
+
mediaTypes = _apidomParserAdapterYaml.mediaTypes,
|
|
22
|
+
...rest
|
|
23
|
+
} = options ?? {};
|
|
24
|
+
super({
|
|
25
|
+
...rest,
|
|
26
|
+
name: 'yaml-1-2',
|
|
27
|
+
fileExtensions,
|
|
28
|
+
mediaTypes
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async canParse(file) {
|
|
32
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
33
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
34
|
+
if (!hasSupportedFileExtension) return false;
|
|
35
|
+
if (hasSupportedMediaType) return true;
|
|
36
|
+
if (!hasSupportedMediaType) {
|
|
37
|
+
return (0, _apidomParserAdapterYaml.detect)(file.toString());
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
async parse(file) {
|
|
42
|
+
const source = file.toString();
|
|
43
|
+
try {
|
|
44
|
+
return await (0, _apidomParserAdapterYaml.parse)(source, {
|
|
45
|
+
sourceMap: this.sourceMap
|
|
46
|
+
});
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new _ParserError.default(`Error parsing "${file.uri}"`, {
|
|
49
|
+
cause: error
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
var _default = exports.default = YAML1Parser;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { parse, mediaTypes as YAMLMediaTypes, detect } from '@speclynx/apidom-parser-adapter-yaml-1-2';
|
|
2
|
+
import ParserError from "../../../errors/ParserError.mjs";
|
|
3
|
+
import Parser from "../Parser.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
class YAML1Parser extends Parser {
|
|
11
|
+
refractorOpts;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
const {
|
|
14
|
+
fileExtensions = [],
|
|
15
|
+
mediaTypes = YAMLMediaTypes,
|
|
16
|
+
...rest
|
|
17
|
+
} = options ?? {};
|
|
18
|
+
super({
|
|
19
|
+
...rest,
|
|
20
|
+
name: 'yaml-1-2',
|
|
21
|
+
fileExtensions,
|
|
22
|
+
mediaTypes
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async canParse(file) {
|
|
26
|
+
const hasSupportedFileExtension = this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
27
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
28
|
+
if (!hasSupportedFileExtension) return false;
|
|
29
|
+
if (hasSupportedMediaType) return true;
|
|
30
|
+
if (!hasSupportedMediaType) {
|
|
31
|
+
return detect(file.toString());
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
async parse(file) {
|
|
36
|
+
const source = file.toString();
|
|
37
|
+
try {
|
|
38
|
+
return await parse(source, {
|
|
39
|
+
sourceMap: this.sourceMap
|
|
40
|
+
});
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new ParserError(`Error parsing "${file.uri}"`, {
|
|
43
|
+
cause: error
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export default YAML1Parser;
|
|
@@ -0,0 +1,67 @@
|
|
|
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.resolveApiDOM = exports.default = void 0;
|
|
7
|
+
var _ramda = require("ramda");
|
|
8
|
+
var _apidomCore = require("@speclynx/apidom-core");
|
|
9
|
+
var _util = require("../options/util.cjs");
|
|
10
|
+
var _index = _interopRequireDefault(require("../parse/index.cjs"));
|
|
11
|
+
var plugins = _interopRequireWildcard(require("../util/plugins.cjs"));
|
|
12
|
+
var _File = _interopRequireDefault(require("../File.cjs"));
|
|
13
|
+
var _ResolverError = _interopRequireDefault(require("../errors/ResolverError.cjs"));
|
|
14
|
+
var _UnmatchedResolveStrategyError = _interopRequireDefault(require("../errors/UnmatchedResolveStrategyError.cjs"));
|
|
15
|
+
var url = _interopRequireWildcard(require("../util/url.cjs"));
|
|
16
|
+
/**
|
|
17
|
+
* Resolves ApiDOM with all its external references.
|
|
18
|
+
*/
|
|
19
|
+
const resolveApiDOM = async (element, options) => {
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
let parseResult = element;
|
|
22
|
+
|
|
23
|
+
// wrap element into parse result
|
|
24
|
+
if (!(0, _apidomCore.isParseResultElement)(element)) {
|
|
25
|
+
// shallow clone of the element
|
|
26
|
+
const elementClone = (0, _apidomCore.cloneShallow)(element);
|
|
27
|
+
elementClone.classes.push('result');
|
|
28
|
+
parseResult = new _apidomCore.ParseResultElement([elementClone]);
|
|
29
|
+
}
|
|
30
|
+
const sanitizedURI = url.sanitize(url.stripHash(options.resolve.baseURI));
|
|
31
|
+
const file = new _File.default({
|
|
32
|
+
uri: sanitizedURI,
|
|
33
|
+
parseResult,
|
|
34
|
+
mediaType: options.parse.mediaType
|
|
35
|
+
});
|
|
36
|
+
const resolveStrategies = await plugins.filter('canResolve', [file, options], options.resolve.strategies);
|
|
37
|
+
|
|
38
|
+
// we couldn't find any resolver for this File
|
|
39
|
+
if ((0, _ramda.isEmpty)(resolveStrategies)) {
|
|
40
|
+
throw new _UnmatchedResolveStrategyError.default(file.uri);
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const {
|
|
44
|
+
result
|
|
45
|
+
} = await plugins.run('resolve', [file, options], resolveStrategies);
|
|
46
|
+
return result;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new _ResolverError.default(`Error while resolving file "${file.uri}"`, {
|
|
49
|
+
cause: error
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Resolves a file with all its external references.
|
|
56
|
+
*/
|
|
57
|
+
exports.resolveApiDOM = resolveApiDOM;
|
|
58
|
+
const resolve = async (uri, options) => {
|
|
59
|
+
const parseResult = await (0, _index.default)(uri, options);
|
|
60
|
+
const mergedOptions = (0, _util.merge)(options, {
|
|
61
|
+
resolve: {
|
|
62
|
+
baseURI: url.sanitize(uri)
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return resolveApiDOM(parseResult, mergedOptions);
|
|
66
|
+
};
|
|
67
|
+
var _default = exports.default = resolve;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isEmpty } from 'ramda';
|
|
2
|
+
import { isParseResultElement, ParseResultElement, cloneShallow } from '@speclynx/apidom-core';
|
|
3
|
+
import { merge as mergeOptions } from "../options/util.mjs";
|
|
4
|
+
import parse from "../parse/index.mjs";
|
|
5
|
+
import * as plugins from "../util/plugins.mjs";
|
|
6
|
+
import File from "../File.mjs";
|
|
7
|
+
import ResolveError from "../errors/ResolverError.mjs";
|
|
8
|
+
import UnmatchedResolveStrategyError from "../errors/UnmatchedResolveStrategyError.mjs";
|
|
9
|
+
import * as url from "../util/url.mjs";
|
|
10
|
+
/**
|
|
11
|
+
* Resolves ApiDOM with all its external references.
|
|
12
|
+
*/
|
|
13
|
+
export const resolveApiDOM = async (element, options) => {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
let parseResult = element;
|
|
16
|
+
|
|
17
|
+
// wrap element into parse result
|
|
18
|
+
if (!isParseResultElement(element)) {
|
|
19
|
+
// shallow clone of the element
|
|
20
|
+
const elementClone = cloneShallow(element);
|
|
21
|
+
elementClone.classes.push('result');
|
|
22
|
+
parseResult = new ParseResultElement([elementClone]);
|
|
23
|
+
}
|
|
24
|
+
const sanitizedURI = url.sanitize(url.stripHash(options.resolve.baseURI));
|
|
25
|
+
const file = new File({
|
|
26
|
+
uri: sanitizedURI,
|
|
27
|
+
parseResult,
|
|
28
|
+
mediaType: options.parse.mediaType
|
|
29
|
+
});
|
|
30
|
+
const resolveStrategies = await plugins.filter('canResolve', [file, options], options.resolve.strategies);
|
|
31
|
+
|
|
32
|
+
// we couldn't find any resolver for this File
|
|
33
|
+
if (isEmpty(resolveStrategies)) {
|
|
34
|
+
throw new UnmatchedResolveStrategyError(file.uri);
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const {
|
|
38
|
+
result
|
|
39
|
+
} = await plugins.run('resolve', [file, options], resolveStrategies);
|
|
40
|
+
return result;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new ResolveError(`Error while resolving file "${file.uri}"`, {
|
|
43
|
+
cause: error
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Resolves a file with all its external references.
|
|
50
|
+
*/
|
|
51
|
+
const resolve = async (uri, options) => {
|
|
52
|
+
const parseResult = await parse(uri, options);
|
|
53
|
+
const mergedOptions = mergeOptions(options, {
|
|
54
|
+
resolve: {
|
|
55
|
+
baseURI: url.sanitize(uri)
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return resolveApiDOM(parseResult, mergedOptions);
|
|
59
|
+
};
|
|
60
|
+
export default resolve;
|
|
@@ -0,0 +1,38 @@
|
|
|
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.default = void 0;
|
|
7
|
+
var _Resolver = _interopRequireDefault(require("./Resolver.cjs"));
|
|
8
|
+
var url = _interopRequireWildcard(require("../../util/url.cjs"));
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
class HTTPResolver extends _Resolver.default {
|
|
17
|
+
timeout;
|
|
18
|
+
redirects;
|
|
19
|
+
withCredentials;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
const {
|
|
22
|
+
name = 'http-resolver',
|
|
23
|
+
timeout = 5000,
|
|
24
|
+
redirects = 5,
|
|
25
|
+
withCredentials = false
|
|
26
|
+
} = options ?? {};
|
|
27
|
+
super({
|
|
28
|
+
name
|
|
29
|
+
});
|
|
30
|
+
this.timeout = timeout;
|
|
31
|
+
this.redirects = redirects;
|
|
32
|
+
this.withCredentials = withCredentials;
|
|
33
|
+
}
|
|
34
|
+
canRead(file) {
|
|
35
|
+
return url.isHttpUrl(file.uri);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
var _default = exports.default = HTTPResolver;
|