@speclynx/apidom-reference 4.0.3 → 4.0.4

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.
Files changed (95) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/apidom-reference.browser.js +15 -15
  3. package/dist/apidom-reference.browser.min.js +1 -1
  4. package/package.json +27 -26
  5. package/src/File.ts +0 -63
  6. package/src/Reference.ts +0 -38
  7. package/src/ReferenceSet.ts +0 -73
  8. package/src/bundle/index.ts +0 -57
  9. package/src/bundle/strategies/BundleStrategy.ts +0 -27
  10. package/src/bundle/strategies/openapi-3-1/index.ts +0 -57
  11. package/src/configuration/empty.ts +0 -1
  12. package/src/configuration/saturated.ts +0 -72
  13. package/src/dereference/index.ts +0 -96
  14. package/src/dereference/strategies/DereferenceStrategy.ts +0 -27
  15. package/src/dereference/strategies/apidom/index.ts +0 -128
  16. package/src/dereference/strategies/apidom/selectors/element-id.ts +0 -48
  17. package/src/dereference/strategies/apidom/visitor.ts +0 -316
  18. package/src/dereference/strategies/arazzo-1/index.ts +0 -158
  19. package/src/dereference/strategies/arazzo-1/selectors/$anchor.ts +0 -9
  20. package/src/dereference/strategies/arazzo-1/selectors/uri.ts +0 -5
  21. package/src/dereference/strategies/arazzo-1/source-descriptions.ts +0 -317
  22. package/src/dereference/strategies/arazzo-1/util.ts +0 -33
  23. package/src/dereference/strategies/arazzo-1/visitor.ts +0 -574
  24. package/src/dereference/strategies/asyncapi-2/index.ts +0 -133
  25. package/src/dereference/strategies/asyncapi-2/visitor.ts +0 -589
  26. package/src/dereference/strategies/openapi-2/index.ts +0 -136
  27. package/src/dereference/strategies/openapi-2/visitor.ts +0 -745
  28. package/src/dereference/strategies/openapi-3-0/index.ts +0 -134
  29. package/src/dereference/strategies/openapi-3-0/visitor.ts +0 -760
  30. package/src/dereference/strategies/openapi-3-1/index.ts +0 -141
  31. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.ts +0 -64
  32. package/src/dereference/strategies/openapi-3-1/selectors/uri.ts +0 -54
  33. package/src/dereference/strategies/openapi-3-1/util.ts +0 -83
  34. package/src/dereference/strategies/openapi-3-1/visitor.ts +0 -1053
  35. package/src/dereference/util.ts +0 -29
  36. package/src/errors/BundleError.ts +0 -8
  37. package/src/errors/DereferenceError.ts +0 -8
  38. package/src/errors/EvaluationElementIdError.ts +0 -8
  39. package/src/errors/EvaluationJsonSchema$anchorError.ts +0 -8
  40. package/src/errors/EvaluationJsonSchemaUriError.ts +0 -8
  41. package/src/errors/InvalidJsonSchema$anchorError.ts +0 -12
  42. package/src/errors/JsonSchema$anchorError.ts +0 -8
  43. package/src/errors/JsonSchemaUriError.ts +0 -8
  44. package/src/errors/MaximumBundleDepthError.ts +0 -8
  45. package/src/errors/MaximumDereferenceDepthError.ts +0 -8
  46. package/src/errors/MaximumResolveDepthError.ts +0 -8
  47. package/src/errors/ParseError.ts +0 -8
  48. package/src/errors/ParserError.ts +0 -8
  49. package/src/errors/PluginError.ts +0 -15
  50. package/src/errors/ResolveError.ts +0 -8
  51. package/src/errors/ResolverError.ts +0 -8
  52. package/src/errors/UnmatchedBundleStrategyError.ts +0 -8
  53. package/src/errors/UnmatchedDereferenceStrategyError.ts +0 -8
  54. package/src/errors/UnmatchedParserError.ts +0 -8
  55. package/src/errors/UnmatchedResolveStrategyError.ts +0 -8
  56. package/src/errors/UnmatchedResolverError.ts +0 -8
  57. package/src/errors/UnresolvableReferenceError.ts +0 -8
  58. package/src/index.ts +0 -135
  59. package/src/options/index.ts +0 -239
  60. package/src/options/util.ts +0 -22
  61. package/src/parse/index.ts +0 -67
  62. package/src/parse/parsers/Parser.ts +0 -80
  63. package/src/parse/parsers/apidom-json/index.ts +0 -78
  64. package/src/parse/parsers/arazzo-json-1/index.ts +0 -76
  65. package/src/parse/parsers/arazzo-json-1/source-descriptions.ts +0 -280
  66. package/src/parse/parsers/arazzo-yaml-1/index.ts +0 -77
  67. package/src/parse/parsers/arazzo-yaml-1/source-descriptions.ts +0 -16
  68. package/src/parse/parsers/asyncapi-json-2/index.ts +0 -58
  69. package/src/parse/parsers/asyncapi-yaml-2/index.ts +0 -58
  70. package/src/parse/parsers/binary/index-browser.ts +0 -60
  71. package/src/parse/parsers/binary/index-node.ts +0 -57
  72. package/src/parse/parsers/json/index.ts +0 -52
  73. package/src/parse/parsers/openapi-json-2/index.ts +0 -58
  74. package/src/parse/parsers/openapi-json-3-0/index.ts +0 -59
  75. package/src/parse/parsers/openapi-json-3-1/index.ts +0 -59
  76. package/src/parse/parsers/openapi-yaml-2/index.ts +0 -58
  77. package/src/parse/parsers/openapi-yaml-3-0/index.ts +0 -59
  78. package/src/parse/parsers/openapi-yaml-3-1/index.ts +0 -59
  79. package/src/parse/parsers/yaml-1-2/index.ts +0 -60
  80. package/src/resolve/index.ts +0 -75
  81. package/src/resolve/resolvers/HTTPResolver.ts +0 -58
  82. package/src/resolve/resolvers/Resolver.ts +0 -25
  83. package/src/resolve/resolvers/file/index-browser.ts +0 -24
  84. package/src/resolve/resolvers/file/index-node.ts +0 -55
  85. package/src/resolve/resolvers/http-axios/cache/MemoryCache.ts +0 -46
  86. package/src/resolve/resolvers/http-axios/index.ts +0 -130
  87. package/src/resolve/strategies/ResolveStrategy.ts +0 -26
  88. package/src/resolve/strategies/apidom/index.ts +0 -78
  89. package/src/resolve/strategies/asyncapi-2/index.ts +0 -78
  90. package/src/resolve/strategies/openapi-2/index.ts +0 -78
  91. package/src/resolve/strategies/openapi-3-0/index.ts +0 -78
  92. package/src/resolve/strategies/openapi-3-1/index.ts +0 -78
  93. package/src/resolve/util.ts +0 -39
  94. package/src/util/plugins.ts +0 -37
  95. package/src/util/url.ts +0 -285
@@ -1,58 +0,0 @@
1
- import { pick } from 'ramda';
2
- import { ParseResultElement } from '@speclynx/apidom-datamodel';
3
- import {
4
- parse,
5
- mediaTypes as AsyncAPI2MediaTypes,
6
- detect,
7
- } from '@speclynx/apidom-parser-adapter-asyncapi-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 AsyncAPIJSON2ParserOptions extends Omit<ParserOptions, 'name'> {}
20
-
21
- /**
22
- * @public
23
- */
24
- class AsyncAPIJSON2Parser extends Parser {
25
- public refractorOpts!: object;
26
-
27
- constructor(options?: AsyncAPIJSON2ParserOptions) {
28
- const { fileExtensions = [], mediaTypes = AsyncAPI2MediaTypes, ...rest } = options ?? {};
29
-
30
- super({ ...rest, name: 'asyncapi-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 AsyncAPIJSON2Parser;
@@ -1,58 +0,0 @@
1
- import { pick } from 'ramda';
2
- import { ParseResultElement } from '@speclynx/apidom-datamodel';
3
- import {
4
- parse,
5
- mediaTypes as AsyncAPI2MediaTypes,
6
- detect,
7
- } from '@speclynx/apidom-parser-adapter-asyncapi-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 AsyncAPIYAML2ParserOptions extends Omit<ParserOptions, 'name'> {}
20
-
21
- /**
22
- * @public
23
- */
24
- class AsyncAPIYAML2Parser extends Parser {
25
- public refractorOpts!: object;
26
-
27
- constructor(options?: AsyncAPIYAML2ParserOptions) {
28
- const { fileExtensions = [], mediaTypes = AsyncAPI2MediaTypes, ...rest } = options ?? {};
29
-
30
- super({ ...rest, name: 'asyncapi-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 AsyncAPIYAML2Parser;
@@ -1,60 +0,0 @@
1
- import { ParseResultElement, StringElement } from '@speclynx/apidom-datamodel';
2
-
3
- import ParserError from '../../../errors/ParserError.ts';
4
- import Parser, { ParserOptions } from '../Parser.ts';
5
- import File from '../../../File.ts';
6
-
7
- export type { default as Parser, ParserOptions } from '../Parser.ts';
8
- export type { default as File, FileOptions } from '../../../File.ts';
9
-
10
- /**
11
- * Everything that is not recognized by other parsers will be considered by this parser
12
- * as a binary data and will be encoded to Base64 format.
13
- * @public
14
- */
15
-
16
- export interface BinaryParserOptions extends Omit<ParserOptions, 'name'> {}
17
-
18
- /**
19
- * @public
20
- */
21
- class BinaryParser extends Parser {
22
- constructor(options?: BinaryParserOptions) {
23
- super({ ...(options ?? {}), name: 'binary' });
24
- }
25
-
26
- canParse(file: File): boolean {
27
- return this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
28
- }
29
-
30
- parse(file: File): ParseResultElement {
31
- try {
32
- /**
33
- * More information about binary strings and btoa function in following link:
34
- * https://developer.mozilla.org/en-US/docs/Web/API/btoa
35
- *
36
- * @example
37
- * ArrayBuffer to base64 conversion:
38
- *
39
- * const binaryString = String.fromCharCode.apply(null, file.data);
40
- * base64String = btoa(binaryString);
41
- */
42
- const binaryString = unescape(encodeURIComponent(file.toString()));
43
- const base64String = btoa(binaryString);
44
-
45
- const parseResultElement = new ParseResultElement();
46
-
47
- if (base64String.length !== 0) {
48
- const base64StringElement = new StringElement(base64String);
49
- base64StringElement.classes.push('result');
50
- parseResultElement.push(base64StringElement);
51
- }
52
-
53
- return parseResultElement;
54
- } catch (error: unknown) {
55
- throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
56
- }
57
- }
58
- }
59
-
60
- export default BinaryParser;
@@ -1,57 +0,0 @@
1
- import { Buffer } from 'node:buffer';
2
- import { ParseResultElement, StringElement } from '@speclynx/apidom-datamodel';
3
-
4
- import ParserError from '../../../errors/ParserError.ts';
5
- import Parser, { ParserOptions } from '../Parser.ts';
6
- import File from '../../../File.ts';
7
-
8
- export type { default as Parser, ParserOptions } from '../Parser.ts';
9
- export type { default as File, FileOptions } from '../../../File.ts';
10
-
11
- /**
12
- * Everything that is not recognized by other parsers will be considered by this parser
13
- * as a binary data and will be encoded to Base64 format.
14
- * @public
15
- */
16
-
17
- export interface BinaryParserOptions extends Omit<ParserOptions, 'name'> {}
18
-
19
- /**
20
- * @public
21
- */
22
- class BinaryParser extends Parser {
23
- constructor(options?: BinaryParserOptions) {
24
- super({ ...(options ?? {}), name: 'binary' });
25
- }
26
-
27
- canParse(file: File): boolean {
28
- return this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
29
- }
30
-
31
- parse(file: File): ParseResultElement {
32
- let base64String: string;
33
-
34
- try {
35
- type BufferData = Parameters<typeof Buffer.from>[0];
36
- base64String = Buffer.from(file.data as BufferData).toString('base64');
37
- } catch {
38
- base64String = Buffer.from(file.toString()).toString('base64');
39
- }
40
-
41
- try {
42
- const parseResultElement = new ParseResultElement();
43
-
44
- if (base64String.length !== 0) {
45
- const base64StringElement = new StringElement(base64String);
46
- base64StringElement.classes.push('result');
47
- parseResultElement.push(base64StringElement);
48
- }
49
-
50
- return parseResultElement;
51
- } catch (error: unknown) {
52
- throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
53
- }
54
- }
55
- }
56
-
57
- export default BinaryParser;
@@ -1,52 +0,0 @@
1
- import { pick } from 'ramda';
2
- import { ParseResultElement } from '@speclynx/apidom-datamodel';
3
- import { parse, mediaTypes as JSONMediaTypes, detect } from '@speclynx/apidom-parser-adapter-json';
4
-
5
- import ParserError from '../../../errors/ParserError.ts';
6
- import Parser, { ParserOptions } from '../Parser.ts';
7
- import File from '../../../File.ts';
8
-
9
- export type { default as Parser, ParserOptions } from '../Parser.ts';
10
- export type { default as File, FileOptions } from '../../../File.ts';
11
-
12
- /**
13
- * @public
14
- */
15
- export interface JSONParserOptions extends Omit<ParserOptions, 'name'> {}
16
-
17
- /**
18
- * @public
19
- */
20
- class JSONParser extends Parser {
21
- constructor(options?: JSONParserOptions) {
22
- const { fileExtensions = [], mediaTypes = JSONMediaTypes, ...rest } = options ?? {};
23
-
24
- super({ ...rest, name: 'json', fileExtensions, mediaTypes });
25
- }
26
-
27
- async canParse(file: File): Promise<boolean> {
28
- const hasSupportedFileExtension =
29
- this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
30
- const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);
31
-
32
- if (!hasSupportedFileExtension) return false;
33
- if (hasSupportedMediaType) return true;
34
- if (!hasSupportedMediaType) {
35
- return detect(file.toString());
36
- }
37
- return false;
38
- }
39
-
40
- async parse(file: File): Promise<ParseResultElement> {
41
- const source = file.toString();
42
-
43
- try {
44
- const parserOpts = pick(['sourceMap', 'style', 'strict'], this);
45
- return await parse(source, parserOpts);
46
- } catch (error: unknown) {
47
- throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
48
- }
49
- }
50
- }
51
-
52
- export default JSONParser;
@@ -1,58 +0,0 @@
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;
@@ -1,59 +0,0 @@
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;
@@ -1,59 +0,0 @@
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;
@@ -1,58 +0,0 @@
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;
@@ -1,59 +0,0 @@
1
- import { pick } from 'ramda';
2
- import { ParseResultElement } from '@speclynx/apidom-datamodel';
3
- import {
4
- parse,
5
- mediaTypes as OpenAPIYAML3_0MediaTypes,
6
- detect,
7
- } from '@speclynx/apidom-parser-adapter-openapi-yaml-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 OpenAPIYAML3_0ParserOptions extends Omit<ParserOptions, 'name'> {}
21
-
22
- /**
23
- * @public
24
- */
25
- class OpenAPIYAML3_0Parser extends Parser {
26
- public refractorOpts!: object;
27
-
28
- constructor(options?: OpenAPIYAML3_0ParserOptions) {
29
- const { fileExtensions = [], mediaTypes = OpenAPIYAML3_0MediaTypes, ...rest } = options ?? {};
30
-
31
- super({ ...rest, name: 'openapi-yaml-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 OpenAPIYAML3_0Parser;
@@ -1,59 +0,0 @@
1
- import { pick } from 'ramda';
2
- import { ParseResultElement } from '@speclynx/apidom-datamodel';
3
- import {
4
- parse,
5
- mediaTypes as OpenAPIYAML3_1MediaTypes,
6
- detect,
7
- } from '@speclynx/apidom-parser-adapter-openapi-yaml-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 OpenAPIYAML3_1ParserOptions extends Omit<ParserOptions, 'name'> {}
21
-
22
- /**
23
- * @public
24
- */
25
- class OpenAPIYAML3_1Parser extends Parser {
26
- public refractorOpts!: object;
27
-
28
- constructor(options?: OpenAPIYAML3_1ParserOptions) {
29
- const { fileExtensions = [], mediaTypes = OpenAPIYAML3_1MediaTypes, ...rest } = options ?? {};
30
-
31
- super({ ...rest, name: 'openapi-yaml-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 OpenAPIYAML3_1Parser;