@speclynx/apidom-reference 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +26 -27
- package/src/File.cjs +50 -0
- package/src/File.mjs +44 -0
- package/src/File.ts +63 -0
- package/src/Reference.cjs +31 -0
- package/src/Reference.mjs +27 -0
- package/src/Reference.ts +38 -0
- package/src/ReferenceSet.cjs +60 -0
- package/src/ReferenceSet.mjs +57 -0
- package/src/ReferenceSet.ts +73 -0
- package/src/bundle/index.cjs +61 -0
- package/src/bundle/index.mjs +55 -0
- package/src/bundle/index.ts +57 -0
- package/src/bundle/strategies/BundleStrategy.cjs +20 -0
- package/src/bundle/strategies/BundleStrategy.mjs +16 -0
- package/src/bundle/strategies/BundleStrategy.ts +27 -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/bundle/strategies/openapi-3-1/index.ts +57 -0
- package/src/configuration/empty.cjs +9 -0
- package/src/configuration/empty.mjs +1 -0
- package/src/configuration/empty.ts +1 -0
- package/src/configuration/saturated.cjs +88 -0
- package/src/configuration/saturated.mjs +80 -0
- package/src/configuration/saturated.ts +72 -0
- package/src/dereference/index.cjs +90 -0
- package/src/dereference/index.mjs +83 -0
- package/src/dereference/index.ts +96 -0
- package/src/dereference/strategies/DereferenceStrategy.cjs +20 -0
- package/src/dereference/strategies/DereferenceStrategy.mjs +16 -0
- package/src/dereference/strategies/DereferenceStrategy.ts +27 -0
- package/src/dereference/strategies/apidom/index.cjs +89 -0
- package/src/dereference/strategies/apidom/index.mjs +83 -0
- package/src/dereference/strategies/apidom/index.ts +128 -0
- package/src/dereference/strategies/apidom/selectors/element-id.cjs +47 -0
- package/src/dereference/strategies/apidom/selectors/element-id.mjs +41 -0
- package/src/dereference/strategies/apidom/selectors/element-id.ts +48 -0
- package/src/dereference/strategies/apidom/visitor.cjs +266 -0
- package/src/dereference/strategies/apidom/visitor.mjs +259 -0
- package/src/dereference/strategies/apidom/visitor.ts +316 -0
- package/src/dereference/strategies/arazzo-1/index.cjs +109 -0
- package/src/dereference/strategies/arazzo-1/index.mjs +100 -0
- package/src/dereference/strategies/arazzo-1/index.ts +158 -0
- package/src/dereference/strategies/arazzo-1/selectors/$anchor.cjs +12 -0
- package/src/dereference/strategies/arazzo-1/selectors/$anchor.mjs +1 -0
- package/src/dereference/strategies/arazzo-1/selectors/$anchor.ts +9 -0
- package/src/dereference/strategies/arazzo-1/selectors/uri.cjs +8 -0
- package/src/dereference/strategies/arazzo-1/selectors/uri.mjs +1 -0
- package/src/dereference/strategies/arazzo-1/selectors/uri.ts +5 -0
- package/src/dereference/strategies/arazzo-1/source-descriptions.cjs +248 -0
- package/src/dereference/strategies/arazzo-1/source-descriptions.mjs +243 -0
- package/src/dereference/strategies/arazzo-1/source-descriptions.ts +317 -0
- package/src/dereference/strategies/arazzo-1/util.cjs +37 -0
- package/src/dereference/strategies/arazzo-1/util.mjs +29 -0
- package/src/dereference/strategies/arazzo-1/util.ts +33 -0
- package/src/dereference/strategies/arazzo-1/visitor.cjs +507 -0
- package/src/dereference/strategies/arazzo-1/visitor.mjs +500 -0
- package/src/dereference/strategies/arazzo-1/visitor.ts +574 -0
- package/src/dereference/strategies/asyncapi-2/index.cjs +94 -0
- package/src/dereference/strategies/asyncapi-2/index.mjs +88 -0
- package/src/dereference/strategies/asyncapi-2/index.ts +133 -0
- package/src/dereference/strategies/asyncapi-2/visitor.cjs +501 -0
- package/src/dereference/strategies/asyncapi-2/visitor.mjs +494 -0
- package/src/dereference/strategies/asyncapi-2/visitor.ts +589 -0
- package/src/dereference/strategies/openapi-2/index.cjs +96 -0
- package/src/dereference/strategies/openapi-2/index.mjs +90 -0
- package/src/dereference/strategies/openapi-2/index.ts +136 -0
- package/src/dereference/strategies/openapi-2/visitor.cjs +629 -0
- package/src/dereference/strategies/openapi-2/visitor.mjs +622 -0
- package/src/dereference/strategies/openapi-2/visitor.ts +745 -0
- package/src/dereference/strategies/openapi-3-0/index.cjs +96 -0
- package/src/dereference/strategies/openapi-3-0/index.mjs +90 -0
- package/src/dereference/strategies/openapi-3-0/index.ts +134 -0
- package/src/dereference/strategies/openapi-3-0/visitor.cjs +622 -0
- package/src/dereference/strategies/openapi-3-0/visitor.mjs +615 -0
- package/src/dereference/strategies/openapi-3-0/visitor.ts +760 -0
- package/src/dereference/strategies/openapi-3-1/index.cjs +99 -0
- package/src/dereference/strategies/openapi-3-1/index.mjs +90 -0
- package/src/dereference/strategies/openapi-3-1/index.ts +141 -0
- package/src/dereference/strategies/openapi-3-1/selectors/$anchor.cjs +65 -0
- package/src/dereference/strategies/openapi-3-1/selectors/$anchor.mjs +54 -0
- package/src/dereference/strategies/openapi-3-1/selectors/$anchor.ts +64 -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/selectors/uri.ts +54 -0
- package/src/dereference/strategies/openapi-3-1/util.cjs +68 -0
- package/src/dereference/strategies/openapi-3-1/util.mjs +59 -0
- package/src/dereference/strategies/openapi-3-1/util.ts +83 -0
- package/src/dereference/strategies/openapi-3-1/visitor.cjs +874 -0
- package/src/dereference/strategies/openapi-3-1/visitor.mjs +867 -0
- package/src/dereference/strategies/openapi-3-1/visitor.ts +1053 -0
- package/src/dereference/util.cjs +31 -0
- package/src/dereference/util.mjs +27 -0
- package/src/dereference/util.ts +29 -0
- package/src/errors/BundleError.cjs +10 -0
- package/src/errors/BundleError.mjs +7 -0
- package/src/errors/BundleError.ts +8 -0
- package/src/errors/DereferenceError.cjs +10 -0
- package/src/errors/DereferenceError.mjs +7 -0
- package/src/errors/DereferenceError.ts +8 -0
- package/src/errors/EvaluationElementIdError.cjs +10 -0
- package/src/errors/EvaluationElementIdError.mjs +7 -0
- package/src/errors/EvaluationElementIdError.ts +8 -0
- package/src/errors/EvaluationJsonSchema$anchorError.cjs +11 -0
- package/src/errors/EvaluationJsonSchema$anchorError.mjs +6 -0
- package/src/errors/EvaluationJsonSchema$anchorError.ts +8 -0
- package/src/errors/EvaluationJsonSchemaUriError.cjs +11 -0
- package/src/errors/EvaluationJsonSchemaUriError.mjs +6 -0
- package/src/errors/EvaluationJsonSchemaUriError.ts +8 -0
- package/src/errors/InvalidJsonSchema$anchorError.cjs +15 -0
- package/src/errors/InvalidJsonSchema$anchorError.mjs +10 -0
- package/src/errors/InvalidJsonSchema$anchorError.ts +12 -0
- package/src/errors/JsonSchema$anchorError.cjs +10 -0
- package/src/errors/JsonSchema$anchorError.mjs +7 -0
- package/src/errors/JsonSchema$anchorError.ts +8 -0
- package/src/errors/JsonSchemaUriError.cjs +10 -0
- package/src/errors/JsonSchemaUriError.mjs +7 -0
- package/src/errors/JsonSchemaUriError.ts +8 -0
- package/src/errors/MaximumBundleDepthError.cjs +11 -0
- package/src/errors/MaximumBundleDepthError.mjs +6 -0
- package/src/errors/MaximumBundleDepthError.ts +8 -0
- package/src/errors/MaximumDereferenceDepthError.cjs +11 -0
- package/src/errors/MaximumDereferenceDepthError.mjs +6 -0
- package/src/errors/MaximumDereferenceDepthError.ts +8 -0
- package/src/errors/MaximumResolveDepthError.cjs +11 -0
- package/src/errors/MaximumResolveDepthError.mjs +6 -0
- package/src/errors/MaximumResolveDepthError.ts +8 -0
- package/src/errors/ParseError.cjs +10 -0
- package/src/errors/ParseError.mjs +7 -0
- package/src/errors/ParseError.ts +8 -0
- package/src/errors/ParserError.cjs +11 -0
- package/src/errors/ParserError.mjs +6 -0
- package/src/errors/ParserError.ts +8 -0
- package/src/errors/PluginError.cjs +18 -0
- package/src/errors/PluginError.mjs +15 -0
- package/src/errors/PluginError.ts +15 -0
- package/src/errors/ResolveError.cjs +10 -0
- package/src/errors/ResolveError.mjs +7 -0
- package/src/errors/ResolveError.ts +8 -0
- package/src/errors/ResolverError.cjs +11 -0
- package/src/errors/ResolverError.mjs +6 -0
- package/src/errors/ResolverError.ts +8 -0
- package/src/errors/UnmatchedBundleStrategyError.cjs +11 -0
- package/src/errors/UnmatchedBundleStrategyError.mjs +6 -0
- package/src/errors/UnmatchedBundleStrategyError.ts +8 -0
- package/src/errors/UnmatchedDereferenceStrategyError.cjs +11 -0
- package/src/errors/UnmatchedDereferenceStrategyError.mjs +6 -0
- package/src/errors/UnmatchedDereferenceStrategyError.ts +8 -0
- package/src/errors/UnmatchedParserError.cjs +11 -0
- package/src/errors/UnmatchedParserError.mjs +6 -0
- package/src/errors/UnmatchedParserError.ts +8 -0
- package/src/errors/UnmatchedResolveStrategyError.cjs +11 -0
- package/src/errors/UnmatchedResolveStrategyError.mjs +6 -0
- package/src/errors/UnmatchedResolveStrategyError.ts +8 -0
- package/src/errors/UnmatchedResolverError.cjs +11 -0
- package/src/errors/UnmatchedResolverError.mjs +6 -0
- package/src/errors/UnmatchedResolverError.ts +8 -0
- package/src/errors/UnresolvableReferenceError.cjs +11 -0
- package/src/errors/UnresolvableReferenceError.mjs +6 -0
- package/src/errors/UnresolvableReferenceError.ts +8 -0
- package/src/index.cjs +146 -0
- package/src/index.mjs +103 -0
- package/src/index.ts +135 -0
- package/src/options/index.cjs +194 -0
- package/src/options/index.mjs +191 -0
- package/src/options/index.ts +239 -0
- package/src/options/util.cjs +24 -0
- package/src/options/util.mjs +19 -0
- package/src/options/util.ts +22 -0
- package/src/parse/index.cjs +69 -0
- package/src/parse/index.mjs +63 -0
- package/src/parse/index.ts +67 -0
- package/src/parse/parsers/Parser.cjs +62 -0
- package/src/parse/parsers/Parser.mjs +58 -0
- package/src/parse/parsers/Parser.ts +80 -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/apidom-json/index.ts +78 -0
- package/src/parse/parsers/arazzo-json-1/index.cjs +62 -0
- package/src/parse/parsers/arazzo-json-1/index.mjs +56 -0
- package/src/parse/parsers/arazzo-json-1/index.ts +76 -0
- package/src/parse/parsers/arazzo-json-1/source-descriptions.cjs +221 -0
- package/src/parse/parsers/arazzo-json-1/source-descriptions.mjs +214 -0
- package/src/parse/parsers/arazzo-json-1/source-descriptions.ts +280 -0
- package/src/parse/parsers/arazzo-yaml-1/index.cjs +62 -0
- package/src/parse/parsers/arazzo-yaml-1/index.mjs +56 -0
- package/src/parse/parsers/arazzo-yaml-1/index.ts +77 -0
- package/src/parse/parsers/arazzo-yaml-1/source-descriptions.cjs +12 -0
- package/src/parse/parsers/arazzo-yaml-1/source-descriptions.mjs +7 -0
- package/src/parse/parsers/arazzo-yaml-1/source-descriptions.ts +16 -0
- package/src/parse/parsers/asyncapi-json-2/index.cjs +54 -0
- package/src/parse/parsers/asyncapi-json-2/index.mjs +48 -0
- package/src/parse/parsers/asyncapi-json-2/index.ts +58 -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/asyncapi-yaml-2/index.ts +58 -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-browser.ts +60 -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/binary/index-node.ts +57 -0
- package/src/parse/parsers/json/index.cjs +53 -0
- package/src/parse/parsers/json/index.mjs +47 -0
- package/src/parse/parsers/json/index.ts +52 -0
- package/src/parse/parsers/openapi-json-2/index.cjs +54 -0
- package/src/parse/parsers/openapi-json-2/index.mjs +48 -0
- package/src/parse/parsers/openapi-json-2/index.ts +58 -0
- package/src/parse/parsers/openapi-json-3-0/index.cjs +54 -0
- package/src/parse/parsers/openapi-json-3-0/index.mjs +48 -0
- package/src/parse/parsers/openapi-json-3-0/index.ts +59 -0
- package/src/parse/parsers/openapi-json-3-1/index.cjs +54 -0
- package/src/parse/parsers/openapi-json-3-1/index.mjs +48 -0
- package/src/parse/parsers/openapi-json-3-1/index.ts +59 -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-2/index.ts +58 -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-0/index.ts +59 -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/openapi-yaml-3-1/index.ts +59 -0
- package/src/parse/parsers/yaml-1-2/index.cjs +56 -0
- package/src/parse/parsers/yaml-1-2/index.mjs +50 -0
- package/src/parse/parsers/yaml-1-2/index.ts +60 -0
- package/src/resolve/index.cjs +67 -0
- package/src/resolve/index.mjs +60 -0
- package/src/resolve/index.ts +75 -0
- package/src/resolve/resolvers/HTTPResolver.cjs +45 -0
- package/src/resolve/resolvers/HTTPResolver.mjs +37 -0
- package/src/resolve/resolvers/HTTPResolver.ts +58 -0
- package/src/resolve/resolvers/Resolver.cjs +20 -0
- package/src/resolve/resolvers/Resolver.mjs +16 -0
- package/src/resolve/resolvers/Resolver.ts +25 -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-browser.ts +24 -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/file/index-node.ts +55 -0
- package/src/resolve/resolvers/http-axios/cache/MemoryCache.cjs +41 -0
- package/src/resolve/resolvers/http-axios/cache/MemoryCache.mjs +37 -0
- package/src/resolve/resolvers/http-axios/cache/MemoryCache.ts +46 -0
- package/src/resolve/resolvers/http-axios/index.cjs +113 -0
- package/src/resolve/resolvers/http-axios/index.mjs +105 -0
- package/src/resolve/resolvers/http-axios/index.ts +130 -0
- package/src/resolve/strategies/ResolveStrategy.cjs +20 -0
- package/src/resolve/strategies/ResolveStrategy.mjs +16 -0
- package/src/resolve/strategies/ResolveStrategy.ts +26 -0
- package/src/resolve/strategies/apidom/index.cjs +49 -0
- package/src/resolve/strategies/apidom/index.mjs +43 -0
- package/src/resolve/strategies/apidom/index.ts +78 -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/asyncapi-2/index.ts +78 -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-2/index.ts +78 -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-0/index.ts +78 -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/strategies/openapi-3-1/index.ts +78 -0
- package/src/resolve/util.cjs +37 -0
- package/src/resolve/util.mjs +30 -0
- package/src/resolve/util.ts +39 -0
- package/src/util/plugins.cjs +39 -0
- package/src/util/plugins.mjs +34 -0
- package/src/util/plugins.ts +37 -0
- package/src/util/url.cjs +288 -0
- package/src/util/url.mjs +274 -0
- package/src/util/url.ts +285 -0
|
@@ -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 _apidomParserAdapterOpenapiJson = require("@speclynx/apidom-parser-adapter-openapi-json-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 OpenAPIJSON2Parser extends _Parser.default {
|
|
18
|
+
refractorOpts;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
const {
|
|
21
|
+
fileExtensions = [],
|
|
22
|
+
mediaTypes = _apidomParserAdapterOpenapiJson.mediaTypes,
|
|
23
|
+
...rest
|
|
24
|
+
} = options ?? {};
|
|
25
|
+
super({
|
|
26
|
+
...rest,
|
|
27
|
+
name: 'openapi-json-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, _apidomParserAdapterOpenapiJson.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', 'style', 'strict', 'refractorOpts'], this);
|
|
46
|
+
return await (0, _apidomParserAdapterOpenapiJson.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 = OpenAPIJSON2Parser;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { pick } from 'ramda';
|
|
2
|
+
import { parse, mediaTypes as OpenAPI2MediaTypes, detect } from '@speclynx/apidom-parser-adapter-openapi-json-2';
|
|
3
|
+
import ParserError from "../../../errors/ParserError.mjs";
|
|
4
|
+
import Parser from "../Parser.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
class OpenAPIJSON2Parser extends Parser {
|
|
12
|
+
refractorOpts;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
const {
|
|
15
|
+
fileExtensions = [],
|
|
16
|
+
mediaTypes = OpenAPI2MediaTypes,
|
|
17
|
+
...rest
|
|
18
|
+
} = options ?? {};
|
|
19
|
+
super({
|
|
20
|
+
...rest,
|
|
21
|
+
name: 'openapi-json-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', 'style', 'strict', '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 OpenAPIJSON2Parser;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { pick } from 'ramda';
|
|
2
|
+
import { ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
3
|
+
import {
|
|
4
|
+
parse,
|
|
5
|
+
mediaTypes as OpenAPI2MediaTypes,
|
|
6
|
+
detect,
|
|
7
|
+
} from '@speclynx/apidom-parser-adapter-openapi-json-2';
|
|
8
|
+
|
|
9
|
+
import ParserError from '../../../errors/ParserError.ts';
|
|
10
|
+
import Parser, { ParserOptions } from '../Parser.ts';
|
|
11
|
+
import File from '../../../File.ts';
|
|
12
|
+
|
|
13
|
+
export type { default as Parser, ParserOptions } from '../Parser.ts';
|
|
14
|
+
export type { default as File, FileOptions } from '../../../File.ts';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export interface OpenAPIJSON2ParserOptions extends Omit<ParserOptions, 'name'> {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
class OpenAPIJSON2Parser extends Parser {
|
|
25
|
+
public refractorOpts!: object;
|
|
26
|
+
|
|
27
|
+
constructor(options?: OpenAPIJSON2ParserOptions) {
|
|
28
|
+
const { fileExtensions = [], mediaTypes = OpenAPI2MediaTypes, ...rest } = options ?? {};
|
|
29
|
+
|
|
30
|
+
super({ ...rest, name: 'openapi-json-2', fileExtensions, mediaTypes });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async canParse(file: File): Promise<boolean> {
|
|
34
|
+
const hasSupportedFileExtension =
|
|
35
|
+
this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
36
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
37
|
+
|
|
38
|
+
if (!hasSupportedFileExtension) return false;
|
|
39
|
+
if (hasSupportedMediaType) return true;
|
|
40
|
+
if (!hasSupportedMediaType) {
|
|
41
|
+
return detect(file.toString());
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async parse(file: File): Promise<ParseResultElement> {
|
|
47
|
+
const source = file.toString();
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const parserOpts = pick(['sourceMap', 'style', 'strict', 'refractorOpts'], this);
|
|
51
|
+
return await parse(source, parserOpts);
|
|
52
|
+
} catch (error: unknown) {
|
|
53
|
+
throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default OpenAPIJSON2Parser;
|
|
@@ -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 _apidomParserAdapterOpenapiJson = require("@speclynx/apidom-parser-adapter-openapi-json-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 OpenAPIJSON3_0Parser extends _Parser.default {
|
|
18
|
+
refractorOpts;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
const {
|
|
21
|
+
fileExtensions = [],
|
|
22
|
+
mediaTypes = _apidomParserAdapterOpenapiJson.mediaTypes,
|
|
23
|
+
...rest
|
|
24
|
+
} = options ?? {};
|
|
25
|
+
super({
|
|
26
|
+
...rest,
|
|
27
|
+
name: 'openapi-json-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, _apidomParserAdapterOpenapiJson.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', 'style', 'strict', 'refractorOpts'], this);
|
|
46
|
+
return await (0, _apidomParserAdapterOpenapiJson.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 = OpenAPIJSON3_0Parser;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { pick } from 'ramda';
|
|
2
|
+
import { parse, mediaTypes as OpenAPI3_0MediaTypes, detect } from '@speclynx/apidom-parser-adapter-openapi-json-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 OpenAPIJSON3_0Parser extends Parser {
|
|
12
|
+
refractorOpts;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
const {
|
|
15
|
+
fileExtensions = [],
|
|
16
|
+
mediaTypes = OpenAPI3_0MediaTypes,
|
|
17
|
+
...rest
|
|
18
|
+
} = options ?? {};
|
|
19
|
+
super({
|
|
20
|
+
...rest,
|
|
21
|
+
name: 'openapi-json-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', 'style', 'strict', '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 OpenAPIJSON3_0Parser;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { pick } from 'ramda';
|
|
2
|
+
import { ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
3
|
+
import {
|
|
4
|
+
parse,
|
|
5
|
+
mediaTypes as OpenAPI3_0MediaTypes,
|
|
6
|
+
detect,
|
|
7
|
+
} from '@speclynx/apidom-parser-adapter-openapi-json-3-0';
|
|
8
|
+
|
|
9
|
+
import ParserError from '../../../errors/ParserError.ts';
|
|
10
|
+
import Parser, { ParserOptions } from '../Parser.ts';
|
|
11
|
+
import File from '../../../File.ts';
|
|
12
|
+
|
|
13
|
+
export type { default as Parser, ParserOptions } from '../Parser.ts';
|
|
14
|
+
export type { default as File, FileOptions } from '../../../File.ts';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export interface OpenAPIJSON3_0ParserOptions extends Omit<ParserOptions, 'name'> {}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
class OpenAPIJSON3_0Parser extends Parser {
|
|
26
|
+
public refractorOpts!: object;
|
|
27
|
+
|
|
28
|
+
constructor(options?: OpenAPIJSON3_0ParserOptions) {
|
|
29
|
+
const { fileExtensions = [], mediaTypes = OpenAPI3_0MediaTypes, ...rest } = options ?? {};
|
|
30
|
+
|
|
31
|
+
super({ ...rest, name: 'openapi-json-3-0', fileExtensions, mediaTypes });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async canParse(file: File): Promise<boolean> {
|
|
35
|
+
const hasSupportedFileExtension =
|
|
36
|
+
this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
37
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
38
|
+
|
|
39
|
+
if (!hasSupportedFileExtension) return false;
|
|
40
|
+
if (hasSupportedMediaType) return true;
|
|
41
|
+
if (!hasSupportedMediaType) {
|
|
42
|
+
return detect(file.toString());
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async parse(file: File): Promise<ParseResultElement> {
|
|
48
|
+
const source = file.toString();
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const parserOpts = pick(['sourceMap', 'style', 'strict', 'refractorOpts'], this);
|
|
52
|
+
return await parse(source, parserOpts);
|
|
53
|
+
} catch (error: unknown) {
|
|
54
|
+
throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default OpenAPIJSON3_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 _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
|
+
refractorOpts;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
const {
|
|
21
|
+
fileExtensions = [],
|
|
22
|
+
mediaTypes = _apidomParserAdapterOpenapiJson.mediaTypes,
|
|
23
|
+
...rest
|
|
24
|
+
} = options ?? {};
|
|
25
|
+
super({
|
|
26
|
+
...rest,
|
|
27
|
+
name: 'openapi-json-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, _apidomParserAdapterOpenapiJson.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', 'style', 'strict', 'refractorOpts'], this);
|
|
46
|
+
return await (0, _apidomParserAdapterOpenapiJson.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 = OpenAPIJSON3_1Parser;
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
refractorOpts;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
const {
|
|
15
|
+
fileExtensions = [],
|
|
16
|
+
mediaTypes = OpenAPI3_1MediaTypes,
|
|
17
|
+
...rest
|
|
18
|
+
} = options ?? {};
|
|
19
|
+
super({
|
|
20
|
+
...rest,
|
|
21
|
+
name: 'openapi-json-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', 'style', 'strict', '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 OpenAPIJSON3_1Parser;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { pick } from 'ramda';
|
|
2
|
+
import { ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
3
|
+
import {
|
|
4
|
+
parse,
|
|
5
|
+
mediaTypes as OpenAPI3_1MediaTypes,
|
|
6
|
+
detect,
|
|
7
|
+
} from '@speclynx/apidom-parser-adapter-openapi-json-3-1';
|
|
8
|
+
|
|
9
|
+
import ParserError from '../../../errors/ParserError.ts';
|
|
10
|
+
import Parser, { ParserOptions } from '../Parser.ts';
|
|
11
|
+
import File from '../../../File.ts';
|
|
12
|
+
|
|
13
|
+
export type { default as Parser, ParserOptions } from '../Parser.ts';
|
|
14
|
+
export type { default as File, FileOptions } from '../../../File.ts';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export interface OpenAPIJSON3_1ParserOptions extends Omit<ParserOptions, 'name'> {}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
class OpenAPIJSON3_1Parser extends Parser {
|
|
26
|
+
public refractorOpts!: object;
|
|
27
|
+
|
|
28
|
+
constructor(options?: OpenAPIJSON3_1ParserOptions) {
|
|
29
|
+
const { fileExtensions = [], mediaTypes = OpenAPI3_1MediaTypes, ...rest } = options ?? {};
|
|
30
|
+
|
|
31
|
+
super({ ...rest, name: 'openapi-json-3-1', fileExtensions, mediaTypes });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async canParse(file: File): Promise<boolean> {
|
|
35
|
+
const hasSupportedFileExtension =
|
|
36
|
+
this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
37
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
38
|
+
|
|
39
|
+
if (!hasSupportedFileExtension) return false;
|
|
40
|
+
if (hasSupportedMediaType) return true;
|
|
41
|
+
if (!hasSupportedMediaType) {
|
|
42
|
+
return detect(file.toString());
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async parse(file: File): Promise<ParseResultElement> {
|
|
48
|
+
const source = file.toString();
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const parserOpts = pick(['sourceMap', 'style', 'strict', 'refractorOpts'], this);
|
|
52
|
+
return await parse(source, parserOpts);
|
|
53
|
+
} catch (error: unknown) {
|
|
54
|
+
throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
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', 'style', 'strict', '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', 'style', 'strict', '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,58 @@
|
|
|
1
|
+
import { pick } from 'ramda';
|
|
2
|
+
import { ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
3
|
+
import {
|
|
4
|
+
parse,
|
|
5
|
+
mediaTypes as OpenAPIYAML2MediaTypes,
|
|
6
|
+
detect,
|
|
7
|
+
} from '@speclynx/apidom-parser-adapter-openapi-yaml-2';
|
|
8
|
+
|
|
9
|
+
import ParserError from '../../../errors/ParserError.ts';
|
|
10
|
+
import Parser, { ParserOptions } from '../Parser.ts';
|
|
11
|
+
import File from '../../../File.ts';
|
|
12
|
+
|
|
13
|
+
export type { default as Parser, ParserOptions } from '../Parser.ts';
|
|
14
|
+
export type { default as File, FileOptions } from '../../../File.ts';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export interface OpenAPIYAML2ParserOptions extends Omit<ParserOptions, 'name'> {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
class OpenAPIYAML2Parser extends Parser {
|
|
25
|
+
public refractorOpts!: object;
|
|
26
|
+
|
|
27
|
+
constructor(options?: OpenAPIYAML2ParserOptions) {
|
|
28
|
+
const { fileExtensions = [], mediaTypes = OpenAPIYAML2MediaTypes, ...rest } = options ?? {};
|
|
29
|
+
|
|
30
|
+
super({ ...rest, name: 'openapi-yaml-2', fileExtensions, mediaTypes });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async canParse(file: File): Promise<boolean> {
|
|
34
|
+
const hasSupportedFileExtension =
|
|
35
|
+
this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
|
|
36
|
+
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
|
|
37
|
+
|
|
38
|
+
if (!hasSupportedFileExtension) return false;
|
|
39
|
+
if (hasSupportedMediaType) return true;
|
|
40
|
+
if (!hasSupportedMediaType) {
|
|
41
|
+
return detect(file.toString());
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async parse(file: File): Promise<ParseResultElement> {
|
|
47
|
+
const source = file.toString();
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const parserOpts = pick(['sourceMap', 'style', 'strict', 'refractorOpts'], this);
|
|
51
|
+
return await parse(source, parserOpts);
|
|
52
|
+
} catch (error: unknown) {
|
|
53
|
+
throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default OpenAPIYAML2Parser;
|