@speclynx/apidom-reference 4.0.3 → 4.0.5

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 +10 -0
  2. package/dist/apidom-reference.browser.js +43 -19
  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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speclynx/apidom-reference",
3
- "version": "4.0.3",
3
+ "version": "4.0.5",
4
4
  "description": "Advanced algorithms for semantic ApiDOM manipulations like dereferencing or resolution.",
5
5
  "keywords": [
6
6
  "apidom",
@@ -254,29 +254,29 @@
254
254
  "license": "Apache-2.0",
255
255
  "dependencies": {
256
256
  "@babel/runtime-corejs3": "^7.28.4",
257
- "@speclynx/apidom-core": "4.0.3",
258
- "@speclynx/apidom-datamodel": "4.0.3",
259
- "@speclynx/apidom-error": "4.0.3",
260
- "@speclynx/apidom-json-pointer": "4.0.3",
261
- "@speclynx/apidom-ns-arazzo-1": "4.0.3",
262
- "@speclynx/apidom-ns-asyncapi-2": "4.0.3",
263
- "@speclynx/apidom-ns-json-schema-2020-12": "4.0.3",
264
- "@speclynx/apidom-ns-openapi-2": "4.0.3",
265
- "@speclynx/apidom-ns-openapi-3-0": "4.0.3",
266
- "@speclynx/apidom-ns-openapi-3-1": "4.0.3",
267
- "@speclynx/apidom-parser-adapter-arazzo-json-1": "4.0.3",
268
- "@speclynx/apidom-parser-adapter-arazzo-yaml-1": "4.0.3",
269
- "@speclynx/apidom-parser-adapter-asyncapi-json-2": "4.0.3",
270
- "@speclynx/apidom-parser-adapter-asyncapi-yaml-2": "4.0.3",
271
- "@speclynx/apidom-parser-adapter-json": "4.0.3",
272
- "@speclynx/apidom-parser-adapter-openapi-json-2": "4.0.3",
273
- "@speclynx/apidom-parser-adapter-openapi-json-3-0": "4.0.3",
274
- "@speclynx/apidom-parser-adapter-openapi-json-3-1": "4.0.3",
275
- "@speclynx/apidom-parser-adapter-openapi-yaml-2": "4.0.3",
276
- "@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "4.0.3",
277
- "@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "4.0.3",
278
- "@speclynx/apidom-parser-adapter-yaml-1-2": "4.0.3",
279
- "@speclynx/apidom-traverse": "4.0.3",
257
+ "@speclynx/apidom-core": "4.0.5",
258
+ "@speclynx/apidom-datamodel": "4.0.5",
259
+ "@speclynx/apidom-error": "4.0.5",
260
+ "@speclynx/apidom-json-pointer": "4.0.5",
261
+ "@speclynx/apidom-ns-arazzo-1": "4.0.5",
262
+ "@speclynx/apidom-ns-asyncapi-2": "4.0.5",
263
+ "@speclynx/apidom-ns-json-schema-2020-12": "4.0.5",
264
+ "@speclynx/apidom-ns-openapi-2": "4.0.5",
265
+ "@speclynx/apidom-ns-openapi-3-0": "4.0.5",
266
+ "@speclynx/apidom-ns-openapi-3-1": "4.0.5",
267
+ "@speclynx/apidom-parser-adapter-arazzo-json-1": "4.0.5",
268
+ "@speclynx/apidom-parser-adapter-arazzo-yaml-1": "4.0.5",
269
+ "@speclynx/apidom-parser-adapter-asyncapi-json-2": "4.0.5",
270
+ "@speclynx/apidom-parser-adapter-asyncapi-yaml-2": "4.0.5",
271
+ "@speclynx/apidom-parser-adapter-json": "4.0.5",
272
+ "@speclynx/apidom-parser-adapter-openapi-json-2": "4.0.5",
273
+ "@speclynx/apidom-parser-adapter-openapi-json-3-0": "4.0.5",
274
+ "@speclynx/apidom-parser-adapter-openapi-json-3-1": "4.0.5",
275
+ "@speclynx/apidom-parser-adapter-openapi-yaml-2": "4.0.5",
276
+ "@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "4.0.5",
277
+ "@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "4.0.5",
278
+ "@speclynx/apidom-parser-adapter-yaml-1-2": "4.0.5",
279
+ "@speclynx/apidom-traverse": "4.0.5",
280
280
  "@swaggerexpert/arazzo-runtime-expression": "^2.0.3",
281
281
  "axios": "^1.13.5",
282
282
  "picomatch": "^4.0.3",
@@ -289,7 +289,8 @@
289
289
  "axios-mock-adapter": "^2.0.0"
290
290
  },
291
291
  "files": [
292
- "src/",
292
+ "src/**/*.mjs",
293
+ "src/**/*.cjs",
293
294
  "dist/",
294
295
  "types/",
295
296
  "LICENSES",
@@ -297,5 +298,5 @@
297
298
  "README.md",
298
299
  "CHANGELOG.md"
299
300
  ],
300
- "gitHead": "6ccfa09c02232516215e7de3ead276641957e626"
301
+ "gitHead": "5a85d2a832eeefb07d03760faa391b457447e966"
301
302
  }
package/src/File.ts DELETED
@@ -1,63 +0,0 @@
1
- import { type } from 'ramda';
2
- import { isString } from 'ramda-adjunct';
3
- import { ParseResultElement } from '@speclynx/apidom-datamodel';
4
-
5
- import * as url from './util/url.ts';
6
-
7
- /**
8
- * This class represents a File object with url and data.
9
- * @public
10
- */
11
-
12
- export interface FileOptions {
13
- readonly uri: string;
14
- readonly mediaType?: string;
15
- readonly data?: Buffer | DataView | ArrayBuffer | Uint8Array | string;
16
- readonly parseResult?: ParseResultElement;
17
- }
18
-
19
- /**
20
- * @public
21
- */
22
- class File {
23
- public uri: string;
24
-
25
- public mediaType: string;
26
-
27
- public data?: Buffer | DataView | ArrayBuffer | Uint8Array | string;
28
-
29
- public parseResult?: ParseResultElement;
30
-
31
- constructor({ uri, mediaType = 'text/plain', data, parseResult }: FileOptions) {
32
- this.uri = uri;
33
- this.mediaType = mediaType;
34
- this.data = data;
35
- this.parseResult = parseResult;
36
- }
37
-
38
- get extension(): string {
39
- if (isString(this.uri)) {
40
- return url.getExtension(this.uri);
41
- }
42
- return '';
43
- }
44
-
45
- toString(): string {
46
- if (typeof this.data === 'string') {
47
- return this.data;
48
- }
49
-
50
- if (
51
- this.data instanceof ArrayBuffer ||
52
- ['ArrayBuffer'].includes(type(this.data)) ||
53
- ArrayBuffer.isView(this.data)
54
- ) {
55
- const textDecoder = new TextDecoder('utf-8');
56
- return textDecoder.decode(this.data as Buffer | DataView | ArrayBuffer);
57
- }
58
-
59
- return String(this.data);
60
- }
61
- }
62
-
63
- export default File;
package/src/Reference.ts DELETED
@@ -1,38 +0,0 @@
1
- import { Element } from '@speclynx/apidom-datamodel';
2
-
3
- import ReferenceSet from './ReferenceSet.ts';
4
-
5
- /**
6
- * @public
7
- */
8
- export interface ReferenceOptions<T = Element> {
9
- readonly uri: string;
10
- readonly depth?: number;
11
- readonly refSet?: ReferenceSet;
12
- readonly value: T;
13
- }
14
-
15
- /**
16
- * @public
17
- */
18
- class Reference<T = Element> {
19
- public readonly uri: string;
20
-
21
- public readonly depth: number;
22
-
23
- public readonly value: T;
24
-
25
- public refSet?: ReferenceSet;
26
-
27
- public readonly errors: Array<Error>;
28
-
29
- constructor({ uri, depth = 0, refSet, value }: ReferenceOptions<T>) {
30
- this.uri = uri;
31
- this.value = value;
32
- this.depth = depth;
33
- this.refSet = refSet;
34
- this.errors = [];
35
- }
36
- }
37
-
38
- export default Reference;
@@ -1,73 +0,0 @@
1
- import { isNotUndefined, isString } from 'ramda-adjunct';
2
-
3
- import type Reference from './Reference.ts';
4
-
5
- /**
6
- * @public
7
- */
8
- export interface ReferenceSetOptions {
9
- readonly refs?: Reference[];
10
- readonly circular?: boolean;
11
- }
12
-
13
- /**
14
- * @public
15
- */
16
- class ReferenceSet {
17
- public rootRef?: Reference;
18
-
19
- public readonly refs: Reference[];
20
-
21
- public circular: boolean;
22
-
23
- constructor({ refs = [], circular = false }: ReferenceSetOptions = {}) {
24
- this.refs = [];
25
- this.circular = circular;
26
- refs.forEach(this.add.bind(this));
27
- }
28
-
29
- get size(): number {
30
- return this.refs.length;
31
- }
32
-
33
- add(reference: Reference): this {
34
- if (!this.has(reference)) {
35
- this.refs.push(reference);
36
- this.rootRef = this.rootRef === undefined ? reference : this.rootRef;
37
- reference.refSet = this;
38
- }
39
- return this;
40
- }
41
-
42
- merge(anotherRefSet: this): this {
43
- for (const reference of anotherRefSet.values()) {
44
- this.add(reference);
45
- }
46
- return this;
47
- }
48
-
49
- has(thing: string | Reference): boolean {
50
- const uri = isString(thing) ? thing : thing.uri;
51
- return isNotUndefined(this.find((ref: Reference) => ref.uri === uri));
52
- }
53
-
54
- find(
55
- predicate: (value: Reference, index: number, obj: Reference[]) => boolean,
56
- ): Reference | undefined {
57
- return this.refs.find(predicate);
58
- }
59
-
60
- *values() {
61
- yield* this.refs;
62
- }
63
-
64
- clean() {
65
- this.refs.forEach((ref: Reference) => {
66
- ref.refSet = undefined;
67
- });
68
- this.rootRef = undefined;
69
- this.refs.length = 0;
70
- }
71
- }
72
-
73
- export default ReferenceSet;
@@ -1,57 +0,0 @@
1
- import { isEmpty, propEq } from 'ramda';
2
- import { ParseResultElement } from '@speclynx/apidom-datamodel';
3
-
4
- import File from '../File.ts';
5
- import * as plugins from '../util/plugins.ts';
6
- import UnmatchedBundleStrategyError from '../errors/UnmatchedBundleStrategyError.ts';
7
- import BundleError from '../errors/BundleError.ts';
8
- import parse from '../parse/index.ts';
9
- import { merge as mergeOptions } from '../options/util.ts';
10
- import * as url from '../util/url.ts';
11
- import type { ReferenceOptions } from '../options/index.ts';
12
-
13
- /**
14
- * Bundle a file with all its external references to a compound document.
15
- */
16
- const bundle = async (uri: string, options: ReferenceOptions): Promise<ParseResultElement> => {
17
- const { refSet } = options.bundle;
18
- const sanitizedURI = url.sanitize(uri);
19
- const mergedOptions = mergeOptions(options, { resolve: { baseURI: sanitizedURI } });
20
- let parseResult;
21
-
22
- // if refSet was provided, use it to avoid unnecessary parsing
23
- if (refSet !== null && refSet.has(sanitizedURI)) {
24
- // @ts-ignore
25
- ({ value: parseResult } = refSet.find(propEq(sanitizedURI, 'uri')));
26
- } else {
27
- parseResult = await parse(uri, mergedOptions);
28
- }
29
-
30
- const file = new File({
31
- uri: mergedOptions.resolve.baseURI,
32
- parseResult,
33
- mediaType: mergedOptions.parse.mediaType,
34
- });
35
-
36
- const bundleStrategies = await plugins.filter(
37
- 'canBundle',
38
- [file, mergedOptions],
39
- mergedOptions.bundle.strategies,
40
- );
41
-
42
- // we couldn't find any bundle strategy for this File
43
- if (isEmpty(bundleStrategies)) {
44
- throw new UnmatchedBundleStrategyError(
45
- `Could not find a bundle strategy that can bundle the file "${file.uri}"`,
46
- );
47
- }
48
-
49
- try {
50
- const { result } = await plugins.run('bundle', [file, mergedOptions], bundleStrategies);
51
- return result;
52
- } catch (error: any) {
53
- throw new BundleError(`Error while bundling file "${file.uri}"`, { cause: error });
54
- }
55
- };
56
-
57
- export default bundle;
@@ -1,27 +0,0 @@
1
- import { ParseResultElement } from '@speclynx/apidom-datamodel';
2
-
3
- import File from '../../File.ts';
4
- import type { ReferenceOptions } from '../../options/index.ts';
5
-
6
- /**
7
- * @public
8
- */
9
- export interface BundleStrategyOptions {
10
- readonly name: string;
11
- }
12
-
13
- /**
14
- * @public
15
- */
16
- abstract class BundleStrategy {
17
- public readonly name: string;
18
-
19
- constructor({ name }: BundleStrategyOptions) {
20
- this.name = name;
21
- }
22
-
23
- abstract canBundle(file: File, options: ReferenceOptions): boolean;
24
- abstract bundle(file: File, options: ReferenceOptions): Promise<ParseResultElement>;
25
- }
26
-
27
- export default BundleStrategy;
@@ -1,57 +0,0 @@
1
- import { ParseResultElement } from '@speclynx/apidom-datamodel';
2
- import { mediaTypes, isOpenApi3_1Element } from '@speclynx/apidom-ns-openapi-3-1';
3
-
4
- import File from '../../../File.ts';
5
- import BundleStrategy, { BundleStrategyOptions } from '../BundleStrategy.ts';
6
-
7
- export type {
8
- default as DereferenceStrategy,
9
- DereferenceStrategyOptions,
10
- } from '../../../dereference/strategies/DereferenceStrategy.ts';
11
- export type { default as File, FileOptions } from '../../../File.ts';
12
- export type { default as Reference, ReferenceOptions } from '../../../Reference.ts';
13
- export type { default as ReferenceSet, ReferenceSetOptions } from '../../../ReferenceSet.ts';
14
- export type {
15
- ReferenceOptions as ApiDOMReferenceOptions,
16
- ReferenceBundleOptions as ApiDOMReferenceBundleOptions,
17
- ReferenceDereferenceOptions as ApiDOMReferenceDereferenceOptions,
18
- ReferenceParseOptions as ApiDOMReferenceParseOptions,
19
- ReferenceResolveOptions as ApiDOMReferenceResolveOptions,
20
- } from '../../../options/index.ts';
21
- export type { default as Parser, ParserOptions } from '../../../parse/parsers/Parser.ts';
22
- export type { default as Resolver, ResolverOptions } from '../../../resolve/resolvers/Resolver.ts';
23
- export type {
24
- default as ResolveStrategy,
25
- ResolveStrategyOptions,
26
- } from '../../../resolve/strategies/ResolveStrategy.ts';
27
- export type { default as BundleStrategy, BundleStrategyOptions } from '../BundleStrategy.ts';
28
-
29
- /**
30
- * @public
31
- */
32
- export interface OpenAPI3_1BundleStrategyOptions extends Omit<BundleStrategyOptions, 'name'> {}
33
-
34
- /**
35
- * @public
36
- */
37
- class OpenAPI3_1BundleStrategy extends BundleStrategy {
38
- constructor(options?: OpenAPI3_1BundleStrategyOptions) {
39
- super({ ...(options ?? {}), name: 'openapi-3-1' });
40
- }
41
-
42
- canBundle(file: File): boolean {
43
- // assert by media type
44
- if (file.mediaType !== 'text/plain') {
45
- return mediaTypes.includes(file.mediaType);
46
- }
47
-
48
- // assert by inspecting ApiDOM
49
- return isOpenApi3_1Element(file.parseResult?.result);
50
- }
51
-
52
- async bundle(file: File): Promise<ParseResultElement> {
53
- return file.parseResult!;
54
- }
55
- }
56
-
57
- export default OpenAPI3_1BundleStrategy;
@@ -1 +0,0 @@
1
- export * from '../index.ts';
@@ -1,72 +0,0 @@
1
- import FileResolver from '../resolve/resolvers/file/index-node.ts';
2
- import HTTPResolverAxios from '../resolve/resolvers/http-axios/index.ts';
3
- import OpenAPI2ResolveStrategy from '../resolve/strategies/openapi-2/index.ts';
4
- import OpenAPI3_0ResolveStrategy from '../resolve/strategies/openapi-3-0/index.ts';
5
- import OpenAPI3_1ResolveStrategy from '../resolve/strategies/openapi-3-1/index.ts';
6
- import AsyncAPI2ResolveStrategy from '../resolve/strategies/asyncapi-2/index.ts';
7
- import ApiDOMResolveStrategy from '../resolve/strategies/apidom/index.ts';
8
- import OpenAPIJSON2Parser from '../parse/parsers/openapi-json-2/index.ts';
9
- import OpenAPIYAML2Parser from '../parse/parsers/openapi-yaml-2/index.ts';
10
- import OpenAPIJSON3_0Parser from '../parse/parsers/openapi-json-3-0/index.ts';
11
- import OpenAPIYAML3_0Parser from '../parse/parsers/openapi-yaml-3-0/index.ts';
12
- import OpenAPIJSON3_1Parser from '../parse/parsers/openapi-json-3-1/index.ts';
13
- import OpenAPIYAML3_1Parser from '../parse/parsers/openapi-yaml-3-1/index.ts';
14
- import AsyncAPIJSON2Parser from '../parse/parsers/asyncapi-json-2/index.ts';
15
- import AsyncAPIYAML2Parser from '../parse/parsers/asyncapi-yaml-2/index.ts';
16
- import ArazzoJSON1Parser from '../parse/parsers/arazzo-json-1/index.ts';
17
- import ArazzoYAML1Parser from '../parse/parsers/arazzo-yaml-1/index.ts';
18
- import APIDOMJSONParser from '../parse/parsers/apidom-json/index.ts';
19
- import JSONParser from '../parse/parsers/json/index.ts';
20
- import YAMLParser from '../parse/parsers/yaml-1-2/index.ts';
21
- import BinaryParser from '../parse/parsers/binary/index-node.ts';
22
- import ApiDOMDereferenceStrategy from '../dereference/strategies/apidom/index.ts';
23
- import OpenAPI2DereferenceStrategy from '../dereference/strategies/openapi-2/index.ts';
24
- import OpenAPI3_0DereferenceStrategy from '../dereference/strategies/openapi-3-0/index.ts';
25
- import OpenAPI3_1DereferenceStrategy from '../dereference/strategies/openapi-3-1/index.ts';
26
- import AsyncAPI2DereferenceStrategy from '../dereference/strategies/asyncapi-2/index.ts';
27
- import Arazzo1DereferenceStrategy from '../dereference/strategies/arazzo-1/index.ts';
28
- import OpenAPI3_1BundleStrategy from '../bundle/strategies/openapi-3-1/index.ts';
29
- import { options } from '../index.ts';
30
-
31
- options.parse.parsers = [
32
- new OpenAPIJSON2Parser({ allowEmpty: true, sourceMap: false }),
33
- new OpenAPIYAML2Parser({ allowEmpty: true, sourceMap: false }),
34
- new OpenAPIJSON3_0Parser({ allowEmpty: true, sourceMap: false }),
35
- new OpenAPIYAML3_0Parser({ allowEmpty: true, sourceMap: false }),
36
- new OpenAPIJSON3_1Parser({ allowEmpty: true, sourceMap: false }),
37
- new OpenAPIYAML3_1Parser({ allowEmpty: true, sourceMap: false }),
38
- new AsyncAPIJSON2Parser({ allowEmpty: true, sourceMap: false }),
39
- new AsyncAPIYAML2Parser({ allowEmpty: true, sourceMap: false }),
40
- new ArazzoJSON1Parser({ allowEmpty: true, sourceMap: false }),
41
- new ArazzoYAML1Parser({ allowEmpty: true, sourceMap: false }),
42
- new APIDOMJSONParser({ allowEmpty: true, sourceMap: false }),
43
- new JSONParser({ allowEmpty: true, sourceMap: false }),
44
- new YAMLParser({ allowEmpty: true, sourceMap: false }),
45
- new BinaryParser({ allowEmpty: true }),
46
- ];
47
-
48
- options.resolve.resolvers = [
49
- new FileResolver(),
50
- new HTTPResolverAxios({ timeout: 5000, redirects: 5, withCredentials: false }),
51
- ];
52
-
53
- options.resolve.strategies = [
54
- new OpenAPI2ResolveStrategy(),
55
- new OpenAPI3_0ResolveStrategy(),
56
- new OpenAPI3_1ResolveStrategy(),
57
- new AsyncAPI2ResolveStrategy(),
58
- new ApiDOMResolveStrategy(),
59
- ];
60
-
61
- options.dereference.strategies = [
62
- new OpenAPI2DereferenceStrategy(),
63
- new OpenAPI3_0DereferenceStrategy(),
64
- new OpenAPI3_1DereferenceStrategy(),
65
- new AsyncAPI2DereferenceStrategy(),
66
- new Arazzo1DereferenceStrategy(),
67
- new ApiDOMDereferenceStrategy(),
68
- ];
69
-
70
- options.bundle.strategies = [new OpenAPI3_1BundleStrategy()];
71
-
72
- export * from '../index.ts';
@@ -1,96 +0,0 @@
1
- import { isEmpty, propEq } from 'ramda';
2
- import {
3
- Element,
4
- isParseResultElement,
5
- ParseResultElement,
6
- cloneShallow,
7
- } from '@speclynx/apidom-datamodel';
8
-
9
- import File from '../File.ts';
10
- import * as plugins from '../util/plugins.ts';
11
- import UnmatchedDereferenceStrategyError from '../errors/UnmatchedDereferenceStrategyError.ts';
12
- import DereferenceError from '../errors/DereferenceError.ts';
13
- import UnresolvableReferenceError from '../errors/UnresolvableReferenceError.ts';
14
- import parse from '../parse/index.ts';
15
- import { merge as mergeOptions } from '../options/util.ts';
16
- import * as url from '../util/url.ts';
17
- import type { ReferenceOptions } from '../options/index.ts';
18
-
19
- /**
20
- * Dereferences ApiDOM with all its external references.
21
- */
22
- export const dereferenceApiDOM = async <T extends Element>(
23
- element: T,
24
- options: ReferenceOptions,
25
- ): Promise<T> => {
26
- // @ts-ignore
27
- let parseResult: ParseResultElement = element;
28
- let surrogateWrapping = false;
29
-
30
- // wrap element into parse result
31
- if (!isParseResultElement(element)) {
32
- const elementClone = cloneShallow(element);
33
- elementClone.classes.push('result');
34
- parseResult = new ParseResultElement([elementClone]);
35
- surrogateWrapping = true;
36
- }
37
-
38
- const file = new File({
39
- uri: options.resolve.baseURI,
40
- parseResult,
41
- mediaType: options.parse.mediaType,
42
- });
43
-
44
- const dereferenceStrategies = await plugins.filter(
45
- 'canDereference',
46
- [file, options],
47
- options.dereference.strategies,
48
- );
49
-
50
- // we couldn't find any dereference strategy for this File
51
- if (isEmpty(dereferenceStrategies)) {
52
- throw new UnmatchedDereferenceStrategyError(
53
- `Could not find a dereference strategy that can dereference the file "${file.uri}"`,
54
- );
55
- }
56
-
57
- try {
58
- const { result } = await plugins.run('dereference', [file, options], dereferenceStrategies);
59
- // unwrap the element from ParseResult assuming first element is the actual result
60
- return surrogateWrapping ? result.get(0) : result;
61
- } catch (error: any) {
62
- if (error instanceof UnresolvableReferenceError) {
63
- throw error;
64
- }
65
- throw new DereferenceError(`Error while dereferencing file "${file.uri}"`, { cause: error });
66
- }
67
- };
68
-
69
- /**
70
- * Dereferences a file with all its external references.
71
- */
72
- const dereference = async (uri: string, options: ReferenceOptions): Promise<ParseResultElement> => {
73
- const { refSet } = options.dereference;
74
- const sanitizedURI = url.sanitize(uri);
75
- let parseResult;
76
-
77
- // if refSet was provided, use it to avoid unnecessary parsing
78
- if (refSet !== null && refSet.has(sanitizedURI)) {
79
- // @ts-ignore
80
- ({ value: parseResult } = refSet.find(propEq(sanitizedURI, 'uri')));
81
- } else {
82
- parseResult = await parse(uri, options);
83
- }
84
-
85
- const mergedOptions = mergeOptions(options, {
86
- resolve: { baseURI: sanitizedURI },
87
- dereference: {
88
- // if refSet was not provided, then we can work in mutable mode
89
- immutable: options.dereference.immutable && refSet !== null,
90
- },
91
- });
92
-
93
- return dereferenceApiDOM(parseResult, mergedOptions);
94
- };
95
-
96
- export default dereference;
@@ -1,27 +0,0 @@
1
- import { Element } from '@speclynx/apidom-datamodel';
2
-
3
- import File from '../../File.ts';
4
- import type { ReferenceOptions } from '../../options/index.ts';
5
-
6
- /**
7
- * @public
8
- */
9
- export interface DereferenceStrategyOptions {
10
- readonly name: string;
11
- }
12
-
13
- /**
14
- * @public
15
- */
16
- abstract class DereferenceStrategy {
17
- public readonly name: string;
18
-
19
- constructor({ name }: DereferenceStrategyOptions) {
20
- this.name = name;
21
- }
22
-
23
- abstract canDereference(file: File, options: ReferenceOptions): boolean;
24
- abstract dereference(file: File, options: ReferenceOptions): Promise<Element>;
25
- }
26
-
27
- export default DereferenceStrategy;