@speclynx/apidom-reference 4.11.1 → 4.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +215 -3
- package/dist/apidom-reference.browser.js +1346 -157
- package/dist/apidom-reference.browser.min.js +1 -1
- package/package.json +35 -30
- package/src/File.cjs +3 -1
- package/src/Reference.cjs +3 -1
- package/src/ReferenceSet.cjs +3 -1
- package/src/bundle/index.cjs +9 -1
- package/src/bundle/index.mjs +6 -0
- package/src/bundle/strategies/BundleStrategy.cjs +3 -1
- package/src/bundle/strategies/openapi-3-0/index.cjs +94 -0
- package/src/bundle/strategies/openapi-3-0/index.mjs +81 -0
- package/src/bundle/strategies/openapi-3-0/visitor.cjs +650 -0
- package/src/bundle/strategies/openapi-3-0/visitor.mjs +642 -0
- package/src/bundle/strategies/openapi-3-1/index.cjs +3 -1
- package/src/bundle/util.cjs +42 -0
- package/src/bundle/util.mjs +33 -0
- package/src/configuration/empty.cjs +9 -2
- package/src/configuration/saturated.cjs +19 -11
- package/src/configuration/saturated.mjs +2 -1
- package/src/dereference/index.cjs +3 -1
- package/src/dereference/strategies/DereferenceStrategy.cjs +3 -1
- package/src/dereference/strategies/apidom/index.cjs +9 -2
- package/src/dereference/strategies/apidom/selectors/element-id.cjs +9 -2
- package/src/dereference/strategies/apidom/visitor.cjs +3 -1
- package/src/dereference/strategies/arazzo-1/index.cjs +34 -7
- package/src/dereference/strategies/arazzo-1/selectors/$anchor.cjs +46 -10
- package/src/dereference/strategies/arazzo-1/selectors/uri.cjs +22 -6
- package/src/dereference/strategies/arazzo-1/source-descriptions.cjs +3 -1
- package/src/dereference/strategies/arazzo-1/util.cjs +16 -4
- package/src/dereference/strategies/arazzo-1/visitor.cjs +3 -1
- package/src/dereference/strategies/asyncapi-2/index.cjs +9 -2
- package/src/dereference/strategies/asyncapi-2/visitor.cjs +3 -1
- package/src/dereference/strategies/openapi-2/index.cjs +9 -2
- package/src/dereference/strategies/openapi-2/visitor.cjs +3 -1
- package/src/dereference/strategies/openapi-3-0/index.cjs +9 -2
- package/src/dereference/strategies/openapi-3-0/visitor.cjs +3 -1
- package/src/dereference/strategies/openapi-3-1/index.cjs +28 -6
- package/src/dereference/strategies/openapi-3-1/selectors/$anchor.cjs +22 -5
- package/src/dereference/strategies/openapi-3-1/selectors/uri.cjs +16 -4
- package/src/dereference/strategies/openapi-3-1/util.cjs +3 -1
- package/src/dereference/strategies/openapi-3-1/visitor.cjs +3 -1
- package/src/dereference/strategies/overlay-1/extends.cjs +3 -1
- package/src/dereference/strategies/overlay-1/index.cjs +9 -2
- package/src/dereference/util.cjs +3 -1
- package/src/errors/BundleError.cjs +4 -2
- package/src/errors/BundleError.mjs +2 -2
- package/src/errors/DereferenceError.cjs +3 -1
- package/src/errors/EvaluationElementIdError.cjs +3 -1
- package/src/errors/EvaluationJsonSchema$anchorError.cjs +3 -1
- package/src/errors/EvaluationJsonSchemaUriError.cjs +3 -1
- package/src/errors/InvalidJsonSchema$anchorError.cjs +3 -1
- package/src/errors/JsonSchema$anchorError.cjs +3 -1
- package/src/errors/JsonSchemaUriError.cjs +3 -1
- package/src/errors/MaximumBundleDepthError.cjs +3 -1
- package/src/errors/MaximumDereferenceDepthError.cjs +3 -1
- package/src/errors/MaximumResolveDepthError.cjs +3 -1
- package/src/errors/ParseError.cjs +3 -1
- package/src/errors/ParserError.cjs +3 -1
- package/src/errors/PluginError.cjs +3 -1
- package/src/errors/ResolveError.cjs +3 -1
- package/src/errors/ResolverError.cjs +3 -1
- package/src/errors/UnmatchedBundleStrategyError.cjs +3 -1
- package/src/errors/UnmatchedDereferenceStrategyError.cjs +3 -1
- package/src/errors/UnmatchedParserError.cjs +3 -1
- package/src/errors/UnmatchedResolveStrategyError.cjs +3 -1
- package/src/errors/UnmatchedResolverError.cjs +3 -1
- package/src/errors/UnresolvableReferenceError.cjs +8 -3
- package/src/errors/UnresolvableReferenceError.mjs +5 -2
- package/src/index.cjs +209 -36
- package/src/options/index.cjs +71 -2
- package/src/options/index.mjs +68 -1
- package/src/options/util.cjs +3 -1
- package/src/parse/index.cjs +3 -1
- package/src/parse/parsers/Parser.cjs +3 -1
- package/src/parse/parsers/apidom-json/index.cjs +3 -1
- package/src/parse/parsers/arazzo-json-1/index.cjs +9 -2
- package/src/parse/parsers/arazzo-json-1/source-descriptions.cjs +3 -1
- package/src/parse/parsers/arazzo-yaml-1/index.cjs +9 -2
- package/src/parse/parsers/arazzo-yaml-1/source-descriptions.cjs +3 -1
- package/src/parse/parsers/asyncapi-json-2/index.cjs +3 -1
- package/src/parse/parsers/asyncapi-yaml-2/index.cjs +3 -1
- package/src/parse/parsers/binary/index-browser.cjs +3 -1
- package/src/parse/parsers/binary/index-node.cjs +3 -1
- package/src/parse/parsers/json/index.cjs +3 -1
- package/src/parse/parsers/openapi-json-2/index.cjs +3 -1
- package/src/parse/parsers/openapi-json-3-0/index.cjs +3 -1
- package/src/parse/parsers/openapi-json-3-1/index.cjs +3 -1
- package/src/parse/parsers/openapi-yaml-2/index.cjs +3 -1
- package/src/parse/parsers/openapi-yaml-3-0/index.cjs +3 -1
- package/src/parse/parsers/openapi-yaml-3-1/index.cjs +3 -1
- package/src/parse/parsers/overlay-json-1/extends.cjs +3 -1
- package/src/parse/parsers/overlay-json-1/index.cjs +9 -2
- package/src/parse/parsers/overlay-yaml-1/extends.cjs +10 -4
- package/src/parse/parsers/overlay-yaml-1/index.cjs +9 -2
- package/src/parse/parsers/yaml-1-2/index.cjs +3 -1
- package/src/resolve/index.cjs +3 -1
- package/src/resolve/resolvers/HTTPResolver.cjs +3 -1
- package/src/resolve/resolvers/Resolver.cjs +3 -1
- package/src/resolve/resolvers/file/index-browser.cjs +3 -1
- package/src/resolve/resolvers/file/index-node.cjs +3 -1
- package/src/resolve/resolvers/http-axios/cache/MemoryCache.cjs +3 -1
- package/src/resolve/resolvers/http-axios/index.cjs +3 -1
- package/src/resolve/strategies/ResolveStrategy.cjs +3 -1
- package/src/resolve/strategies/apidom/index.cjs +3 -1
- package/src/resolve/strategies/arazzo-1/index.cjs +3 -1
- package/src/resolve/strategies/asyncapi-2/index.cjs +3 -1
- package/src/resolve/strategies/openapi-2/index.cjs +3 -1
- package/src/resolve/strategies/openapi-3-0/index.cjs +3 -1
- package/src/resolve/strategies/openapi-3-1/index.cjs +3 -1
- package/src/resolve/strategies/overlay-1/index.cjs +3 -1
- package/src/resolve/util.cjs +3 -1
- package/src/util/plugins.cjs +3 -1
- package/src/util/url.cjs +3 -1
- package/types/apidom-reference.d.ts +41 -2
- package/types/bundle/strategies/openapi-3-0/index.d.ts +31 -0
- package/types/bundle/strategies/openapi-3-0/visitor.d.ts +131 -0
- package/types/bundle/util.d.ts +22 -0
- package/types/errors/BundleError.d.ts +2 -2
- package/types/errors/UnresolvableReferenceError.d.ts +5 -2
- package/types/index.d.ts +1 -0
- package/types/options/index.d.ts +33 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
-
exports
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
5
7
|
exports.default = void 0;
|
|
6
8
|
var _ResolveStrategy = _interopRequireDefault(require("../ResolveStrategy.cjs"));
|
|
7
9
|
var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
-
exports
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
5
7
|
exports.default = void 0;
|
|
6
8
|
var _ResolveStrategy = _interopRequireDefault(require("../ResolveStrategy.cjs"));
|
|
7
9
|
var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
-
exports
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
5
7
|
exports.default = void 0;
|
|
6
8
|
var _ResolveStrategy = _interopRequireDefault(require("../ResolveStrategy.cjs"));
|
|
7
9
|
var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
-
exports
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
5
7
|
exports.default = void 0;
|
|
6
8
|
var _ResolveStrategy = _interopRequireDefault(require("../ResolveStrategy.cjs"));
|
|
7
9
|
var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
-
exports
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
5
7
|
exports.default = void 0;
|
|
6
8
|
var _ResolveStrategy = _interopRequireDefault(require("../ResolveStrategy.cjs"));
|
|
7
9
|
var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
|
package/src/resolve/util.cjs
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
4
|
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
5
|
-
exports
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
6
8
|
exports.readFile = void 0;
|
|
7
9
|
var _ramda = require("ramda");
|
|
8
10
|
var plugins = _interopRequireWildcard(require("../util/plugins.cjs"));
|
package/src/util/plugins.cjs
CHANGED
package/src/util/url.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
-
exports
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
5
7
|
exports.unsanitize = exports.toFileSystemPath = exports.stripHash = exports.sanitize = exports.resolve = exports.isURI = exports.isHttpUrl = exports.isFileSystemPath = exports.hasProtocol = exports.getProtocol = exports.getHash = exports.getExtension = exports.fromFileSystemPath = exports.cwd = void 0;
|
|
6
8
|
var _process = _interopRequireDefault(require("process"));
|
|
7
9
|
var _ramda = require("ramda");
|
|
@@ -9,8 +9,13 @@ import type { RefElement } from '@speclynx/apidom-datamodel';
|
|
|
9
9
|
*/
|
|
10
10
|
export declare interface ApiDOMReferenceBundleOptions {
|
|
11
11
|
strategies: Array<BundleStrategy>;
|
|
12
|
+
strategyOpts: Record<string, any>;
|
|
12
13
|
refSet: null | ReferenceSet;
|
|
13
14
|
maxDepth: number;
|
|
15
|
+
immutable: boolean;
|
|
16
|
+
componentNamesStrategy: ComponentNamesStrategy;
|
|
17
|
+
onComponentNameCollision: ComponentNameCollisionSeverity;
|
|
18
|
+
continueOnError: boolean | ((error: UnresolvableReferenceError) => void);
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
/**
|
|
@@ -68,7 +73,7 @@ export declare const bundle: (uri: string, options?: {}) => Promise<ParseResultE
|
|
|
68
73
|
/**
|
|
69
74
|
* @public
|
|
70
75
|
*/
|
|
71
|
-
export declare class BundleError extends
|
|
76
|
+
export declare class BundleError extends ApiDOMStructuredError {
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
/**
|
|
@@ -96,6 +101,37 @@ export declare interface CacheOptions {
|
|
|
96
101
|
readonly maxStaleAge?: number | false;
|
|
97
102
|
}
|
|
98
103
|
|
|
104
|
+
/**
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
107
|
+
export declare type ComponentNameCollisionSeverity = 'off' | 'warn' | 'error';
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
export declare type ComponentNameResolver = (args: ComponentNameResolverArgs) => string;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Context passed to a custom component-name resolver.
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
export declare interface ComponentNameResolverArgs {
|
|
120
|
+
/** The refracted element being hoisted. */
|
|
121
|
+
readonly element: Element_2;
|
|
122
|
+
/** The Components Object field the element is hoisted into (e.g. `schemas`). */
|
|
123
|
+
readonly field: string;
|
|
124
|
+
/** The JSON Pointer of the referenced fragment within its document. */
|
|
125
|
+
readonly jsonPointer: string;
|
|
126
|
+
/** The base URI (without hash) of the referenced document. */
|
|
127
|
+
readonly baseURI: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
export declare type ComponentNamesStrategy = 'basename' | 'title' | ComponentNameResolver;
|
|
134
|
+
|
|
99
135
|
/**
|
|
100
136
|
* Returns the current working directory (in Node) or the current page URL (in browsers).
|
|
101
137
|
* @public
|
|
@@ -569,9 +605,12 @@ export declare class UnmatchedResolveStrategyError extends ResolveError {
|
|
|
569
605
|
}
|
|
570
606
|
|
|
571
607
|
/**
|
|
608
|
+
* Thrown when a reference cannot be resolved. Resolution is shared by the
|
|
609
|
+
* dereference and bundle components, so this error lives under `ResolveError`.
|
|
610
|
+
*
|
|
572
611
|
* @public
|
|
573
612
|
*/
|
|
574
|
-
export declare class UnresolvableReferenceError extends
|
|
613
|
+
export declare class UnresolvableReferenceError extends ResolveError {
|
|
575
614
|
}
|
|
576
615
|
|
|
577
616
|
/**
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import File from '../../../File.ts';
|
|
3
|
+
import BundleStrategy, { BundleStrategyOptions } from '../BundleStrategy.ts';
|
|
4
|
+
import OpenAPI3_0BundleVisitor from './visitor.ts';
|
|
5
|
+
import type { ReferenceOptions } from '../../../options/index.ts';
|
|
6
|
+
export type { default as DereferenceStrategy, DereferenceStrategyOptions, } from '../../../dereference/strategies/DereferenceStrategy.ts';
|
|
7
|
+
export type { default as File, FileOptions } from '../../../File.ts';
|
|
8
|
+
export type { default as Reference, ReferenceOptions } from '../../../Reference.ts';
|
|
9
|
+
export type { default as ReferenceSet, ReferenceSetOptions } from '../../../ReferenceSet.ts';
|
|
10
|
+
export type { OpenAPI3_0BundleVisitorOptions } from './visitor.ts';
|
|
11
|
+
export type { ReferenceOptions as ApiDOMReferenceOptions, ReferenceBundleOptions as ApiDOMReferenceBundleOptions, ReferenceDereferenceOptions as ApiDOMReferenceDereferenceOptions, ReferenceParseOptions as ApiDOMReferenceParseOptions, ReferenceResolveOptions as ApiDOMReferenceResolveOptions, } from '../../../options/index.ts';
|
|
12
|
+
export type { default as Parser, ParserOptions } from '../../../parse/parsers/Parser.ts';
|
|
13
|
+
export type { default as Resolver, ResolverOptions } from '../../../resolve/resolvers/Resolver.ts';
|
|
14
|
+
export type { default as ResolveStrategy, ResolveStrategyOptions, } from '../../../resolve/strategies/ResolveStrategy.ts';
|
|
15
|
+
export type { default as BundleStrategy, BundleStrategyOptions } from '../BundleStrategy.ts';
|
|
16
|
+
export type { ComponentNamesStrategy, ComponentNameResolver, ComponentNameResolverArgs, ComponentNameCollisionSeverity, } from '../../../options/index.ts';
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export interface OpenAPI3_0BundleStrategyOptions extends Omit<BundleStrategyOptions, 'name'> {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
declare class OpenAPI3_0BundleStrategy extends BundleStrategy {
|
|
26
|
+
constructor(options?: OpenAPI3_0BundleStrategyOptions);
|
|
27
|
+
canBundle(file: File): boolean;
|
|
28
|
+
bundle(file: File, options: ReferenceOptions): Promise<ParseResultElement>;
|
|
29
|
+
}
|
|
30
|
+
export { OpenAPI3_0BundleVisitor };
|
|
31
|
+
export default OpenAPI3_0BundleStrategy;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Element, ObjectElement, ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import { type Path } from '@speclynx/apidom-traverse';
|
|
3
|
+
import { OpenApi3_0Element } from '@speclynx/apidom-ns-openapi-3-0';
|
|
4
|
+
import Reference from '../../../Reference.ts';
|
|
5
|
+
import type { ReferenceOptions } from '../../../options/index.ts';
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface OpenAPI3_0BundleVisitorOptions {
|
|
10
|
+
readonly reference: Reference;
|
|
11
|
+
readonly options: ReferenceOptions;
|
|
12
|
+
readonly assignments?: Map<string, string>;
|
|
13
|
+
readonly reservedNames?: Map<string, Set<string>>;
|
|
14
|
+
readonly refractCache?: WeakMap<Element, Map<string, Element>>;
|
|
15
|
+
readonly inlineStack?: Set<string>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
declare class OpenAPI3_0BundleVisitor {
|
|
21
|
+
protected readonly reference: Reference;
|
|
22
|
+
protected readonly options: ReferenceOptions;
|
|
23
|
+
/**
|
|
24
|
+
* The base URI (without hash) of the entry document. A reference is
|
|
25
|
+
* considered internal when it resolves to this URI and external otherwise.
|
|
26
|
+
* Derived from the shared refSet's root reference.
|
|
27
|
+
*/
|
|
28
|
+
protected get entryURI(): string;
|
|
29
|
+
/**
|
|
30
|
+
* The entry parse result. Derived from the shared refSet's root reference.
|
|
31
|
+
*/
|
|
32
|
+
protected get entryParseResult(): ParseResultElement;
|
|
33
|
+
/**
|
|
34
|
+
* The entry document element. Hoisted external fragments are placed into its
|
|
35
|
+
* `components` object. The `canBundle` guard guarantees it is an
|
|
36
|
+
* OpenApi3_0Element.
|
|
37
|
+
*/
|
|
38
|
+
protected get entryResult(): OpenApi3_0Element;
|
|
39
|
+
/**
|
|
40
|
+
* Shared across the entry document and every external document visitor.
|
|
41
|
+
* Guarantees each external fragment is hoisted exactly once and gives us a
|
|
42
|
+
* stable internal pointer to rewrite every referencing element to.
|
|
43
|
+
*/
|
|
44
|
+
protected readonly assignments: Map<string, string>;
|
|
45
|
+
/**
|
|
46
|
+
* Component names already reserved per Components Object field. Reserved
|
|
47
|
+
* before recursion so collision suffixing (`Pet`, `Pet-2`, ...) accounts for
|
|
48
|
+
* components that are still being bundled.
|
|
49
|
+
*/
|
|
50
|
+
protected readonly reservedNames: Map<string, Set<string>>;
|
|
51
|
+
/**
|
|
52
|
+
* Caches refracted fragments keyed by source element and target element type.
|
|
53
|
+
* The type is part of the key because the same source can be refracted into
|
|
54
|
+
* different semantic elements depending on the referencing context (e.g. a
|
|
55
|
+
* generic object referenced once as a Parameter and once as a Response).
|
|
56
|
+
*/
|
|
57
|
+
protected readonly refractCache: WeakMap<Element, Map<string, Element>>;
|
|
58
|
+
/**
|
|
59
|
+
* Canonical URIs of Path Item Objects currently being inlined. Path Items
|
|
60
|
+
* are not hoisted into Components Object (no `components.pathItems` in
|
|
61
|
+
* OpenAPI 3.0), so the `assignments` map can't break their cycles. This
|
|
62
|
+
* stack guards against circular external Path Item references.
|
|
63
|
+
*/
|
|
64
|
+
protected readonly inlineStack: Set<string>;
|
|
65
|
+
constructor({ reference, options, assignments, reservedNames, refractCache, inlineStack, }: OpenAPI3_0BundleVisitorOptions);
|
|
66
|
+
protected getRefracted(source: Element, type: string): Element | undefined;
|
|
67
|
+
protected setRefracted(source: Element, type: string, refracted: Element): void;
|
|
68
|
+
protected toBaseURI(uri: string): string;
|
|
69
|
+
protected toReference(uri: string): Promise<Reference>;
|
|
70
|
+
/**
|
|
71
|
+
* Normalizes a self-file reference (e.g. `./root.json#/components/schemas/Pet`)
|
|
72
|
+
* to a bare fragment (`#/components/schemas/Pet`) so the bundled document stays
|
|
73
|
+
* transferable. Bare fragments are returned unchanged.
|
|
74
|
+
*/
|
|
75
|
+
protected normalizeSelfFileRef(ref: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Handles an error according to the `bundle.continueOnError` option.
|
|
78
|
+
*
|
|
79
|
+
* For new errors: wraps in UnresolvableReferenceError with structured
|
|
80
|
+
* context. For errors already wrapped by a nested visitor: prepends the
|
|
81
|
+
* current hop to the trace.
|
|
82
|
+
*
|
|
83
|
+
* Inner/intermediate visitors always throw to let the trace accumulate. Only
|
|
84
|
+
* the entry document visitor respects continueOnError (callback/swallow/throw).
|
|
85
|
+
*/
|
|
86
|
+
protected handleError(message: string, error: Error, referencingElement: Element, refFieldName: string, refFieldValue: string, visitorPath: Path<Element>): void;
|
|
87
|
+
/**
|
|
88
|
+
* Lazily creates the Components Object (and the requested field within it)
|
|
89
|
+
* on the entry document, returning the field where a fragment is hoisted.
|
|
90
|
+
*/
|
|
91
|
+
protected ensureComponentsField(field: string): ObjectElement;
|
|
92
|
+
/**
|
|
93
|
+
* Derives a component name from the referenced JSON Pointer's last token,
|
|
94
|
+
* falling back to the referenced file's basename.
|
|
95
|
+
*/
|
|
96
|
+
protected basenameOf(jsonPointer: string, baseURI: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Computes the base component name (before collision suffixing) according to
|
|
99
|
+
* the configured naming strategy.
|
|
100
|
+
*/
|
|
101
|
+
protected baseName(element: Element, field: string, jsonPointer: string, baseURI: string): string;
|
|
102
|
+
/**
|
|
103
|
+
* Computes a collision-free component name within the target field. A name is
|
|
104
|
+
* taken if it's already placed in components or reserved by a component that
|
|
105
|
+
* is still being bundled (reserved before recursion).
|
|
106
|
+
*/
|
|
107
|
+
protected uniqueName(candidate: string, field: string): string;
|
|
108
|
+
ReferenceElement(path: Path<Element>): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Path Item Object is not a Components Object field in OpenAPI 3.0
|
|
111
|
+
* (unlike 3.1 which has `components.pathItems`). An external Path Item
|
|
112
|
+
* reference therefore cannot be hoisted; it is inlined in place instead,
|
|
113
|
+
* after bundling its own external references.
|
|
114
|
+
*/
|
|
115
|
+
PathItemElement(path: Path<Element>): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Example Object `externalValue` points at arbitrary external content that
|
|
118
|
+
* has no place in the Components Object. The referenced value is inlined into
|
|
119
|
+
* the Example's `value` field.
|
|
120
|
+
*/
|
|
121
|
+
ExampleElement(path: Path<Element>): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Link Object `operationRef` points at an Operation Object, which has no
|
|
124
|
+
* Components Object field in OpenAPI 3.0 and therefore cannot be hoisted or
|
|
125
|
+
* inlined. To keep the link resolvable from the bundled document, an external
|
|
126
|
+
* `operationRef` is rewritten to its absolute URI. Internal `operationRef`
|
|
127
|
+
* values and `operationId` links are left untouched.
|
|
128
|
+
*/
|
|
129
|
+
LinkElement(path: Path<Element>): Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
export default OpenAPI3_0BundleVisitor;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upper-cases the first letter of each whitespace-separated word and joins
|
|
3
|
+
* them, e.g. `pet model` -> `PetModel`.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare const toPascalCase: (value: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Replaces characters that are invalid in a Components Object name with `-`,
|
|
10
|
+
* then collapses repeated separators and trims leading/trailing ones.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare const sanitizeComponentName: (value: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Returns a collision-free name by suffixing `-2`, `-3`, ... onto `candidate`
|
|
17
|
+
* until `isTaken` reports it free. `isTaken` decides what counts as taken
|
|
18
|
+
* (e.g. names already placed in or reserved for a Components Object field).
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare const uniqueName: (candidate: string, isTaken: (name: string) => boolean) => string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiDOMStructuredError } from '@speclynx/apidom-error';
|
|
2
2
|
/**
|
|
3
3
|
* @public
|
|
4
4
|
*/
|
|
5
|
-
declare class BundleError extends
|
|
5
|
+
declare class BundleError extends ApiDOMStructuredError {
|
|
6
6
|
}
|
|
7
7
|
export default BundleError;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ResolveError from './ResolveError.ts';
|
|
2
2
|
/**
|
|
3
|
+
* Thrown when a reference cannot be resolved. Resolution is shared by the
|
|
4
|
+
* dereference and bundle components, so this error lives under `ResolveError`.
|
|
5
|
+
*
|
|
3
6
|
* @public
|
|
4
7
|
*/
|
|
5
|
-
declare class UnresolvableReferenceError extends
|
|
8
|
+
declare class UnresolvableReferenceError extends ResolveError {
|
|
6
9
|
}
|
|
7
10
|
export default UnresolvableReferenceError;
|
package/types/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type { DereferenceStrategyOptions } from './dereference/strategies/Derefe
|
|
|
16
16
|
export { AncestorLineage as DereferenceAncestorLineage } from './dereference/util.ts';
|
|
17
17
|
export { default as BundleStrategy } from './bundle/strategies/BundleStrategy.ts';
|
|
18
18
|
export type { BundleStrategyOptions } from './bundle/strategies/BundleStrategy.ts';
|
|
19
|
+
export type { ComponentNamesStrategy, ComponentNameResolver, ComponentNameResolverArgs, ComponentNameCollisionSeverity, } from './options/index.ts';
|
|
19
20
|
export { default as options } from './options/index.ts';
|
|
20
21
|
export { merge as mergeOptions } from './options/util.ts';
|
|
21
22
|
export type { ReferenceOptions as ApiDOMReferenceOptions, ReferenceBundleOptions as ApiDOMReferenceBundleOptions, ReferenceDereferenceOptions as ApiDOMReferenceDereferenceOptions, ReferenceParseOptions as ApiDOMReferenceParseOptions, ReferenceResolveOptions as ApiDOMReferenceResolveOptions, } from './options/index.ts';
|
package/types/options/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RefElement } from '@speclynx/apidom-datamodel';
|
|
1
|
+
import type { RefElement, Element } from '@speclynx/apidom-datamodel';
|
|
2
2
|
import type Parser from '../parse/parsers/Parser.ts';
|
|
3
3
|
import type Resolver from '../resolve/resolvers/Resolver.ts';
|
|
4
4
|
import type ResolveStrategy from '../resolve/strategies/ResolveStrategy.ts';
|
|
@@ -40,13 +40,45 @@ export interface ReferenceDereferenceOptions {
|
|
|
40
40
|
immutable: boolean;
|
|
41
41
|
continueOnError: boolean | ((error: UnresolvableReferenceError) => void);
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Context passed to a custom component-name resolver.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export interface ComponentNameResolverArgs {
|
|
49
|
+
/** The refracted element being hoisted. */
|
|
50
|
+
readonly element: Element;
|
|
51
|
+
/** The Components Object field the element is hoisted into (e.g. `schemas`). */
|
|
52
|
+
readonly field: string;
|
|
53
|
+
/** The JSON Pointer of the referenced fragment within its document. */
|
|
54
|
+
readonly jsonPointer: string;
|
|
55
|
+
/** The base URI (without hash) of the referenced document. */
|
|
56
|
+
readonly baseURI: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
export type ComponentNameResolver = (args: ComponentNameResolverArgs) => string;
|
|
62
|
+
/**
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export type ComponentNamesStrategy = 'basename' | 'title' | ComponentNameResolver;
|
|
66
|
+
/**
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export type ComponentNameCollisionSeverity = 'off' | 'warn' | 'error';
|
|
43
70
|
/**
|
|
44
71
|
* @public
|
|
45
72
|
*/
|
|
46
73
|
export interface ReferenceBundleOptions {
|
|
47
74
|
strategies: Array<BundleStrategy>;
|
|
75
|
+
strategyOpts: Record<string, any>;
|
|
48
76
|
refSet: null | ReferenceSet;
|
|
49
77
|
maxDepth: number;
|
|
78
|
+
immutable: boolean;
|
|
79
|
+
componentNamesStrategy: ComponentNamesStrategy;
|
|
80
|
+
onComponentNameCollision: ComponentNameCollisionSeverity;
|
|
81
|
+
continueOnError: boolean | ((error: UnresolvableReferenceError) => void);
|
|
50
82
|
}
|
|
51
83
|
/**
|
|
52
84
|
* @public
|