@speclynx/apidom-reference 4.12.1 → 4.13.0
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/README.md +54 -1
- package/dist/apidom-reference.browser.js +945 -51
- package/dist/apidom-reference.browser.min.js +1 -1
- package/package.json +33 -28
- package/src/bundle/strategies/openapi-2/index.cjs +94 -0
- package/src/bundle/strategies/openapi-2/index.mjs +81 -0
- package/src/bundle/strategies/openapi-2/visitor.cjs +567 -0
- package/src/bundle/strategies/openapi-2/visitor.mjs +559 -0
- package/src/configuration/saturated.cjs +12 -11
- package/src/configuration/saturated.mjs +2 -1
- package/types/bundle/strategies/openapi-2/index.d.ts +31 -0
- package/types/bundle/strategies/openapi-2/visitor.d.ts +131 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Element, ObjectElement, ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
2
|
+
import { type Path } from '@speclynx/apidom-traverse';
|
|
3
|
+
import { ReferenceElement, JSONReferenceElement, SwaggerElement } from '@speclynx/apidom-ns-openapi-2';
|
|
4
|
+
import Reference from '../../../Reference.ts';
|
|
5
|
+
import type { ReferenceOptions } from '../../../options/index.ts';
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface OpenAPI2BundleVisitorOptions {
|
|
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 OpenAPI2BundleVisitor {
|
|
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
|
+
* top-level definition fields. The `canBundle` guard guarantees it is a
|
|
36
|
+
* SwaggerElement.
|
|
37
|
+
*/
|
|
38
|
+
protected get entryResult(): SwaggerElement;
|
|
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 definition field. Reserved before
|
|
47
|
+
* 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 a top-level definition field in OpenAPI 2.0, so the `assignments`
|
|
61
|
+
* map can't break their cycles. This stack guards against circular external
|
|
62
|
+
* Path Item references.
|
|
63
|
+
*/
|
|
64
|
+
protected readonly inlineStack: Set<string>;
|
|
65
|
+
constructor({ reference, options, assignments, reservedNames, refractCache, inlineStack, }: OpenAPI2BundleVisitorOptions);
|
|
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#/definitions/Pet`)
|
|
72
|
+
* to a bare fragment (`#/definitions/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 requested top-level definition field on the entry
|
|
89
|
+
* document, returning the field where a fragment is hoisted.
|
|
90
|
+
*/
|
|
91
|
+
protected ensureField(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 the field or reserved by a component that
|
|
105
|
+
* is still being bundled (reserved before recursion).
|
|
106
|
+
*/
|
|
107
|
+
protected uniqueName(candidate: string, field: string): string;
|
|
108
|
+
/**
|
|
109
|
+
* Bundles a Reference Object (parameters/responses) or a JSON Reference
|
|
110
|
+
* Object (schemas). The two reference flavors differ only in their predicate
|
|
111
|
+
* and refraction helpers, so the shared logic is parameterized here.
|
|
112
|
+
*/
|
|
113
|
+
protected bundleReference(path: Path<Element>, referencingElement: ReferenceElement | JSONReferenceElement, isSemanticReference: (element: Element) => boolean, isReferenceLike: (element: Element) => boolean, refractReferenceFn: (element: Element) => Element, label: string): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Reference Object covers reusable Parameter and Response Objects, which are
|
|
116
|
+
* hoisted into the top-level `parameters` and `responses` fields.
|
|
117
|
+
*/
|
|
118
|
+
ReferenceElement(path: Path<Element>): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* JSON Reference Object covers reusable Schema Objects, which are hoisted
|
|
121
|
+
* into the top-level `definitions` field.
|
|
122
|
+
*/
|
|
123
|
+
JSONReferenceElement(path: Path<Element>): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Path Item Object is not a top-level definition field in OpenAPI 2.0, so an
|
|
126
|
+
* external Path Item reference cannot be hoisted; it is inlined in place
|
|
127
|
+
* instead, after bundling its own external references.
|
|
128
|
+
*/
|
|
129
|
+
PathItemElement(path: Path<Element>): Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
export default OpenAPI2BundleVisitor;
|