@usearazzo/resolver 1.0.1-alpha.10
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 +47 -0
- package/LICENSE +202 -0
- package/NOTICE +20 -0
- package/README.md +102 -0
- package/dist/arazzo-resolver.browser.js +93172 -0
- package/dist/arazzo-resolver.browser.min.js +1 -0
- package/package.json +81 -0
- package/src/bundle/arazzo.cjs +92 -0
- package/src/bundle/arazzo.mjs +83 -0
- package/src/bundle/openapi.cjs +101 -0
- package/src/bundle/openapi.mjs +92 -0
- package/src/dereference/arazzo.cjs +246 -0
- package/src/dereference/arazzo.mjs +236 -0
- package/src/dereference/openapi.cjs +239 -0
- package/src/dereference/openapi.mjs +229 -0
- package/src/errors/BundleError.cjs +17 -0
- package/src/errors/BundleError.mjs +12 -0
- package/src/errors/DereferenceError.cjs +17 -0
- package/src/errors/DereferenceError.mjs +12 -0
- package/src/errors/ResolveError.cjs +17 -0
- package/src/errors/ResolveError.mjs +12 -0
- package/src/index.cjs +129 -0
- package/src/index.mjs +9 -0
- package/src/resolve/arazzo.cjs +208 -0
- package/src/resolve/arazzo.mjs +198 -0
- package/src/resolve/openapi.cjs +234 -0
- package/src/resolve/openapi.mjs +224 -0
- package/types/resolver.d.ts +529 -0
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import { ApiDOMError } from '@speclynx/apidom-error';
|
|
2
|
+
import { ApiDOMErrorOptions } from '@speclynx/apidom-error';
|
|
3
|
+
import type { ApiDOMReferenceOptions } from '@speclynx/apidom-reference/configuration/empty';
|
|
4
|
+
import { Element as Element_2 } from '@speclynx/apidom-datamodel';
|
|
5
|
+
import { ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
6
|
+
import type { PartialDeep } from 'type-fest';
|
|
7
|
+
import { ReferenceSet } from '@speclynx/apidom-reference/configuration/empty';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Bundles an Arazzo Document from a file system path or HTTP(S) URL.
|
|
11
|
+
*
|
|
12
|
+
* This function embeds every external JSON Schema resource reached through
|
|
13
|
+
* JSON References ($ref) into the Components Object of the Arazzo Document,
|
|
14
|
+
* producing a single compound document.
|
|
15
|
+
*
|
|
16
|
+
* @param uri - A file system path or HTTP(S) URL to the Arazzo Document
|
|
17
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
18
|
+
* @returns A promise that resolves to the bundled Arazzo Document as ApiDOM element
|
|
19
|
+
* @throws BundleError - When bundling fails or document is not an Arazzo specification. The original error is available via the `cause` property.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Bundle from file
|
|
23
|
+
* const result = await bundleArazzo('/path/to/arazzo.json');
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Bundle from URL
|
|
27
|
+
* const result = await bundleArazzo('https://example.com/arazzo.yaml');
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Bundle with custom options
|
|
31
|
+
* const result = await bundleArazzo('/path/to/arazzo.json', customReferenceOptions);
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export declare function bundleArazzo(uri: string, options?: BundleArazzoOptions): Promise<ParseResultElement>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Options for bundling Arazzo Documents.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export declare type BundleArazzoOptions = PartialDeep<ApiDOMReferenceOptions>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Error thrown when bundling an Arazzo or OpenAPI document fails.
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
export declare class BundleError extends ApiDOMError {
|
|
47
|
+
constructor(message?: string, options?: ApiDOMErrorOptions);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Bundles an OpenAPI Document from a file system path or HTTP(S) URL.
|
|
52
|
+
*
|
|
53
|
+
* This function hoists every external document reached through JSON References ($ref)
|
|
54
|
+
* into the components of the OpenAPI Document, producing a single compound document.
|
|
55
|
+
*
|
|
56
|
+
* Supports OpenAPI 2.0 (Swagger), OpenAPI 3.0.x, and OpenAPI 3.1.x.
|
|
57
|
+
*
|
|
58
|
+
* @param uri - A file system path or HTTP(S) URL to the OpenAPI Document
|
|
59
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
60
|
+
* @returns A promise that resolves to the bundled OpenAPI Document as ApiDOM element
|
|
61
|
+
* @throws BundleError - When bundling fails or document is not an OpenAPI specification. The original error is available via the `cause` property.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Bundle from file
|
|
65
|
+
* const result = await bundleOpenAPI('/path/to/openapi.json');
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // Bundle from URL
|
|
69
|
+
* const result = await bundleOpenAPI('https://example.com/openapi.yaml');
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Bundle with custom options
|
|
73
|
+
* const result = await bundleOpenAPI('/path/to/openapi.json', customReferenceOptions);
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
export declare function bundleOpenAPI(uri: string, options?: BundleOpenAPIOptions): Promise<ParseResultElement>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Options for bundling OpenAPI Documents.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export declare type BundleOpenAPIOptions = PartialDeep<ApiDOMReferenceOptions>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Default reference options for bundling Arazzo Documents.
|
|
86
|
+
*
|
|
87
|
+
* Bundling reads only the bundle strategies plus the resolvers and parsers that fetch
|
|
88
|
+
* external documents, so no resolve or dereference strategies are configured.
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
export declare const defaultBundleArazzoOptions: BundleArazzoOptions;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Default reference options for bundling OpenAPI Documents.
|
|
95
|
+
*
|
|
96
|
+
* Bundling reads only the bundle strategies plus the resolvers and parsers that fetch
|
|
97
|
+
* external documents, so no resolve or dereference strategies are configured.
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
export declare const defaultBundleOpenAPIOptions: BundleOpenAPIOptions;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Default reference options for dereferencing Arazzo Documents.
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
export declare const defaultDereferenceArazzoOptions: DereferenceArazzoOptions;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Default reference options for dereferencing OpenAPI Documents.
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
export declare const defaultDereferenceOpenAPIOptions: DereferenceOpenAPIOptions;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Default reference options for resolving Arazzo Documents.
|
|
116
|
+
*
|
|
117
|
+
* The resolve strategies delegate to the dereference strategies of the same name,
|
|
118
|
+
* so the dereference defaults are carried over and only the resolve strategies are added.
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
export declare const defaultResolveArazzoOptions: ResolveArazzoOptions;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Default reference options for resolving OpenAPI Documents.
|
|
125
|
+
*
|
|
126
|
+
* The resolve strategies delegate to the dereference strategies of the same name,
|
|
127
|
+
* so the dereference defaults are carried over and only the resolve strategies are added.
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
export declare const defaultResolveOpenAPIOptions: ResolveOpenAPIOptions;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Dereferences an Arazzo Document from a file system path or HTTP(S) URL.
|
|
134
|
+
*
|
|
135
|
+
* This function resolves all JSON References ($ref) and Reusable Object references
|
|
136
|
+
* ($components.*) in the Arazzo Document.
|
|
137
|
+
*
|
|
138
|
+
* Source descriptions can optionally be dereferenced using strategy options:
|
|
139
|
+
* - `sourceDescriptions`: `true` (all) or `['name1', 'name2']` (specific names only)
|
|
140
|
+
* - `sourceDescriptionsMaxDepth`: Maximum recursion depth for nested Arazzo source descriptions (default: `+Infinity`)
|
|
141
|
+
*
|
|
142
|
+
* Options can be passed globally via `strategyOpts` or strategy-specific via `strategyOpts['arazzo-1']`.
|
|
143
|
+
*
|
|
144
|
+
* @param uri - A file system path or HTTP(S) URL to the Arazzo Document
|
|
145
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
146
|
+
* @returns A promise that resolves to the dereferenced Arazzo Document as ApiDOM element
|
|
147
|
+
* @throws DereferenceError - When dereferencing fails or document is not an Arazzo specification. The original error is available via the `cause` property.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* // Dereference from file
|
|
151
|
+
* const result = await dereferenceArazzo('/path/to/arazzo.json');
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* // Dereference from URL
|
|
155
|
+
* const result = await dereferenceArazzo('https://example.com/arazzo.yaml');
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* Dereference with source descriptions
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const result = await dereferenceArazzo('/path/to/arazzo.json', {
|
|
161
|
+
* dereference: { strategyOpts: { sourceDescriptions: true } },
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* // Dereference with custom options
|
|
167
|
+
* const result = await dereferenceArazzo('/path/to/arazzo.json', customReferenceOptions);
|
|
168
|
+
* @public
|
|
169
|
+
*/
|
|
170
|
+
export declare function dereferenceArazzo(uri: string, options?: DereferenceArazzoOptions): Promise<ParseResultElement>;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Dereferences an ApiDOM element representing an Arazzo Document.
|
|
174
|
+
*
|
|
175
|
+
* This function resolves all JSON References ($ref) and Reusable Object references
|
|
176
|
+
* ($components.*) in the Arazzo Document element.
|
|
177
|
+
*
|
|
178
|
+
* Supported scenarios:
|
|
179
|
+
* - ParseResultElement with retrievalURI metadata: baseURI derived automatically
|
|
180
|
+
* - ParseResultElement without retrievalURI: requires `options.resolve.baseURI`
|
|
181
|
+
* - Child element (e.g., WorkflowElement) with parseResult in strategyOpts:
|
|
182
|
+
* requires `options.dereference.strategyOpts.parseResult` for component resolution,
|
|
183
|
+
* and `options.resolve.baseURI` if parseResult lacks retrievalURI metadata
|
|
184
|
+
*
|
|
185
|
+
* Source descriptions can optionally be dereferenced using strategy options:
|
|
186
|
+
* - `sourceDescriptions`: `true` (all) or `['name1', 'name2']` (specific names only)
|
|
187
|
+
* - `sourceDescriptionsMaxDepth`: Maximum recursion depth for nested Arazzo source descriptions (default: `+Infinity`)
|
|
188
|
+
*
|
|
189
|
+
* Options can be passed globally via `strategyOpts` or strategy-specific via `strategyOpts['arazzo-1']`.
|
|
190
|
+
*
|
|
191
|
+
* @param element - An ApiDOM element (ParseResultElement or child element like WorkflowElement)
|
|
192
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
193
|
+
* @returns A promise that resolves to the dereferenced element
|
|
194
|
+
* @throws DereferenceError - When baseURI is required but not provided, or when dereferencing fails
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* Dereference ParseResultElement with retrievalURI (from file parsing)
|
|
198
|
+
* ```typescript
|
|
199
|
+
* import { parseArazzo } from '@usearazzo/parser';
|
|
200
|
+
*
|
|
201
|
+
* const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
202
|
+
* const dereferenced = await dereferenceArazzoElement(parseResult);
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* Dereference ParseResultElement without retrievalURI (from inline parsing)
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const parseResult = await parseArazzo({ arazzo: '1.0.1', ... });
|
|
209
|
+
* const dereferenced = await dereferenceArazzoElement(parseResult, {
|
|
210
|
+
* resolve: { baseURI: 'https://example.com/arazzo.json' },
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* Dereference child element (e.g., WorkflowElement)
|
|
216
|
+
* ```typescript
|
|
217
|
+
* const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
218
|
+
* const workflow = parseResult.api.workflows.get(0);
|
|
219
|
+
* const dereferenced = await dereferenceArazzoElement(workflow, {
|
|
220
|
+
* dereference: { strategyOpts: { parseResult } },
|
|
221
|
+
* });
|
|
222
|
+
* ```
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* Dereference with source descriptions
|
|
226
|
+
* ```typescript
|
|
227
|
+
* const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
228
|
+
* const dereferenced = await dereferenceArazzoElement(parseResult, {
|
|
229
|
+
* dereference: { strategyOpts: { sourceDescriptions: true } },
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
* @public
|
|
233
|
+
*/
|
|
234
|
+
export declare function dereferenceArazzoElement<T extends Element_2>(element: T, options?: DereferenceArazzoOptions): Promise<T>;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Options for dereferencing Arazzo Documents.
|
|
238
|
+
* @public
|
|
239
|
+
*/
|
|
240
|
+
export declare type DereferenceArazzoOptions = PartialDeep<ApiDOMReferenceOptions>;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Error thrown when dereferencing an Arazzo document or element fails.
|
|
244
|
+
* @public
|
|
245
|
+
*/
|
|
246
|
+
export declare class DereferenceError extends ApiDOMError {
|
|
247
|
+
constructor(message?: string, options?: ApiDOMErrorOptions);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Dereferences an OpenAPI Document from a file system path or HTTP(S) URL.
|
|
252
|
+
*
|
|
253
|
+
* This function resolves all JSON References ($ref) in the OpenAPI Document.
|
|
254
|
+
*
|
|
255
|
+
* Supports OpenAPI 2.0 (Swagger), OpenAPI 3.0.x, and OpenAPI 3.1.x.
|
|
256
|
+
*
|
|
257
|
+
* @param uri - A file system path or HTTP(S) URL to the OpenAPI Document
|
|
258
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
259
|
+
* @returns A promise that resolves to the dereferenced OpenAPI Document as ApiDOM element
|
|
260
|
+
* @throws DereferenceError - When dereferencing fails or document is not an OpenAPI specification. The original error is available via the `cause` property.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* // Dereference from file
|
|
264
|
+
* const result = await dereferenceOpenAPI('/path/to/openapi.json');
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* // Dereference from URL
|
|
268
|
+
* const result = await dereferenceOpenAPI('https://example.com/openapi.yaml');
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* // Dereference with custom options
|
|
272
|
+
* const result = await dereferenceOpenAPI('/path/to/openapi.json', customReferenceOptions);
|
|
273
|
+
* @public
|
|
274
|
+
*/
|
|
275
|
+
export declare function dereferenceOpenAPI(uri: string, options?: DereferenceOpenAPIOptions): Promise<ParseResultElement>;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Dereferences an ApiDOM element representing an OpenAPI Document.
|
|
279
|
+
*
|
|
280
|
+
* This function resolves all JSON References ($ref) in the OpenAPI Document element.
|
|
281
|
+
*
|
|
282
|
+
* Supported scenarios:
|
|
283
|
+
* - ParseResultElement with retrievalURI metadata: baseURI derived automatically
|
|
284
|
+
* - ParseResultElement without retrievalURI: requires `options.resolve.baseURI`
|
|
285
|
+
* - Child element (e.g., PathItemElement) with parseResult in strategyOpts:
|
|
286
|
+
* requires `options.dereference.strategyOpts.parseResult` for component resolution,
|
|
287
|
+
* and `options.resolve.baseURI` if parseResult lacks retrievalURI metadata
|
|
288
|
+
*
|
|
289
|
+
* @param element - An ApiDOM element (ParseResultElement or child element like PathItemElement)
|
|
290
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
291
|
+
* @returns A promise that resolves to the dereferenced element
|
|
292
|
+
* @throws DereferenceError - When baseURI is required but not provided, or when dereferencing fails
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* Dereference ParseResultElement with retrievalURI (from file parsing)
|
|
296
|
+
* ```typescript
|
|
297
|
+
* import { parseOpenAPI } from '@usearazzo/parser';
|
|
298
|
+
*
|
|
299
|
+
* const parseResult = await parseOpenAPI('/path/to/openapi.json');
|
|
300
|
+
* const dereferenced = await dereferenceOpenAPIElement(parseResult);
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* Dereference ParseResultElement without retrievalURI (from inline parsing)
|
|
305
|
+
* ```typescript
|
|
306
|
+
* const parseResult = await parseOpenAPI({ openapi: '3.1.0', ... });
|
|
307
|
+
* const dereferenced = await dereferenceOpenAPIElement(parseResult, {
|
|
308
|
+
* resolve: { baseURI: 'https://example.com/openapi.json' },
|
|
309
|
+
* });
|
|
310
|
+
* ```
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* Dereference child element (e.g., PathItemElement)
|
|
314
|
+
* ```typescript
|
|
315
|
+
* const parseResult = await parseOpenAPI('/path/to/openapi.json');
|
|
316
|
+
* const pathItem = parseResult.api.paths.get('/users');
|
|
317
|
+
* const dereferenced = await dereferenceOpenAPIElement(pathItem, {
|
|
318
|
+
* dereference: { strategyOpts: { parseResult } },
|
|
319
|
+
* });
|
|
320
|
+
* ```
|
|
321
|
+
* @public
|
|
322
|
+
*/
|
|
323
|
+
export declare function dereferenceOpenAPIElement<T extends Element_2>(element: T, options?: DereferenceOpenAPIOptions): Promise<T>;
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Options for dereferencing OpenAPI Documents.
|
|
327
|
+
* @public
|
|
328
|
+
*/
|
|
329
|
+
export declare type DereferenceOpenAPIOptions = PartialDeep<ApiDOMReferenceOptions>;
|
|
330
|
+
|
|
331
|
+
export { ReferenceSet }
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Resolves an Arazzo Document from a file system path or HTTP(S) URL.
|
|
335
|
+
*
|
|
336
|
+
* This function collects the Arazzo Document and every external document its
|
|
337
|
+
* JSON References ($ref) reach into a ReferenceSet. Nothing is dereferenced;
|
|
338
|
+
* the root reference of the set holds the parsed entry document.
|
|
339
|
+
*
|
|
340
|
+
* The `dereference.refSet` option is ignored: resolving always builds a fresh ReferenceSet.
|
|
341
|
+
*
|
|
342
|
+
* @param uri - A file system path or HTTP(S) URL to the Arazzo Document
|
|
343
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
344
|
+
* @returns A promise that resolves to the ReferenceSet of the Arazzo Document and its external references
|
|
345
|
+
* @throws ResolveError - When resolving fails or document is not an Arazzo specification. The original error is available via the `cause` property.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* // Resolve from file
|
|
349
|
+
* const refSet = await resolveArazzo('/path/to/arazzo.json');
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* // Resolve from URL
|
|
353
|
+
* const refSet = await resolveArazzo('https://example.com/arazzo.yaml');
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* // Resolve with custom options
|
|
357
|
+
* const refSet = await resolveArazzo('/path/to/arazzo.json', customReferenceOptions);
|
|
358
|
+
* @public
|
|
359
|
+
*/
|
|
360
|
+
export declare function resolveArazzo(uri: string, options?: ResolveArazzoOptions): Promise<ReferenceSet>;
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Resolves an ApiDOM element representing an Arazzo Document.
|
|
364
|
+
*
|
|
365
|
+
* This function collects the element and every external document its
|
|
366
|
+
* JSON References ($ref) reach into a ReferenceSet. Nothing is dereferenced
|
|
367
|
+
* and the element itself is left untouched.
|
|
368
|
+
*
|
|
369
|
+
* Supported scenarios:
|
|
370
|
+
* - ParseResultElement with retrievalURI metadata: baseURI derived automatically
|
|
371
|
+
* - ParseResultElement without retrievalURI: requires `options.resolve.baseURI`
|
|
372
|
+
* - Child element (e.g., WorkflowElement) with parseResult in strategyOpts:
|
|
373
|
+
* requires `options.dereference.strategyOpts.parseResult`,
|
|
374
|
+
* and `options.resolve.baseURI` if parseResult lacks retrievalURI metadata
|
|
375
|
+
* - Child element without parseResult: requires `options.resolve.baseURI` and
|
|
376
|
+
* `options.parse.mediaType`, since the element alone cannot identify the document kind
|
|
377
|
+
*
|
|
378
|
+
* For a child element the root reference of the returned set is keyed by the root document
|
|
379
|
+
* URI but holds a ParseResultElement wrapping a copy of the child, not the root document.
|
|
380
|
+
* The set describes the references reachable from the child and is not a whole-document set.
|
|
381
|
+
*
|
|
382
|
+
* The `dereference.refSet` option is ignored: resolving always builds a fresh ReferenceSet.
|
|
383
|
+
*
|
|
384
|
+
* @param element - An ApiDOM element (ParseResultElement or child element like WorkflowElement)
|
|
385
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
386
|
+
* @returns A promise that resolves to the ReferenceSet of the element and its external references
|
|
387
|
+
* @throws ResolveError - When baseURI is required but not provided, when the document is not an Arazzo specification, or when resolving fails
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* Resolve ParseResultElement with retrievalURI (from file parsing)
|
|
391
|
+
* ```typescript
|
|
392
|
+
* import { parseArazzo } from '@usearazzo/parser';
|
|
393
|
+
*
|
|
394
|
+
* const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
395
|
+
* const refSet = await resolveArazzoElement(parseResult);
|
|
396
|
+
* ```
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* Resolve ParseResultElement without retrievalURI (from inline parsing)
|
|
400
|
+
* ```typescript
|
|
401
|
+
* const parseResult = await parseArazzo({ arazzo: '1.0.1', ... });
|
|
402
|
+
* const refSet = await resolveArazzoElement(parseResult, {
|
|
403
|
+
* resolve: { baseURI: 'https://example.com/arazzo.json' },
|
|
404
|
+
* });
|
|
405
|
+
* ```
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* Resolve child element (e.g., WorkflowElement)
|
|
409
|
+
* ```typescript
|
|
410
|
+
* const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
411
|
+
* const workflow = parseResult.api.workflows.get(0);
|
|
412
|
+
* const refSet = await resolveArazzoElement(workflow, {
|
|
413
|
+
* dereference: { strategyOpts: { parseResult } },
|
|
414
|
+
* });
|
|
415
|
+
* ```
|
|
416
|
+
* @public
|
|
417
|
+
*/
|
|
418
|
+
export declare function resolveArazzoElement<T extends Element_2>(element: T, options?: ResolveArazzoOptions): Promise<ReferenceSet>;
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Options for resolving Arazzo Documents.
|
|
422
|
+
* @public
|
|
423
|
+
*/
|
|
424
|
+
export declare type ResolveArazzoOptions = PartialDeep<ApiDOMReferenceOptions>;
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Error thrown when resolving an Arazzo or OpenAPI document or element fails.
|
|
428
|
+
* @public
|
|
429
|
+
*/
|
|
430
|
+
export declare class ResolveError extends ApiDOMError {
|
|
431
|
+
constructor(message?: string, options?: ApiDOMErrorOptions);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Resolves an OpenAPI Document from a file system path or HTTP(S) URL.
|
|
436
|
+
*
|
|
437
|
+
* This function collects the OpenAPI Document and every external document its
|
|
438
|
+
* JSON References ($ref) reach into a ReferenceSet. Nothing is dereferenced;
|
|
439
|
+
* the root reference of the set holds the parsed entry document.
|
|
440
|
+
*
|
|
441
|
+
* Supports OpenAPI 2.0 (Swagger), OpenAPI 3.0.x, and OpenAPI 3.1.x.
|
|
442
|
+
*
|
|
443
|
+
* The `dereference.refSet` option is ignored: resolving always builds a fresh ReferenceSet.
|
|
444
|
+
*
|
|
445
|
+
* @param uri - A file system path or HTTP(S) URL to the OpenAPI Document
|
|
446
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
447
|
+
* @returns A promise that resolves to the ReferenceSet of the OpenAPI Document and its external references
|
|
448
|
+
* @throws ResolveError - When resolving fails or document is not an OpenAPI specification. The original error is available via the `cause` property.
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* // Resolve from file
|
|
452
|
+
* const refSet = await resolveOpenAPI('/path/to/openapi.json');
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* // Resolve from URL
|
|
456
|
+
* const refSet = await resolveOpenAPI('https://example.com/openapi.yaml');
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* // Resolve with custom options
|
|
460
|
+
* const refSet = await resolveOpenAPI('/path/to/openapi.json', customReferenceOptions);
|
|
461
|
+
* @public
|
|
462
|
+
*/
|
|
463
|
+
export declare function resolveOpenAPI(uri: string, options?: ResolveOpenAPIOptions): Promise<ReferenceSet>;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Resolves an ApiDOM element representing an OpenAPI Document.
|
|
467
|
+
*
|
|
468
|
+
* This function collects the element and every external document its
|
|
469
|
+
* JSON References ($ref) reach into a ReferenceSet. Nothing is dereferenced
|
|
470
|
+
* and the element itself is left untouched.
|
|
471
|
+
*
|
|
472
|
+
* Supported scenarios:
|
|
473
|
+
* - ParseResultElement with retrievalURI metadata: baseURI derived automatically
|
|
474
|
+
* - ParseResultElement without retrievalURI: requires `options.resolve.baseURI`
|
|
475
|
+
* - Child element (e.g., PathItemElement) with parseResult in strategyOpts:
|
|
476
|
+
* requires `options.dereference.strategyOpts.parseResult`,
|
|
477
|
+
* and `options.resolve.baseURI` if parseResult lacks retrievalURI metadata
|
|
478
|
+
* - Child element without parseResult: requires `options.resolve.baseURI` and
|
|
479
|
+
* `options.parse.mediaType`, since the element alone cannot identify the document kind
|
|
480
|
+
*
|
|
481
|
+
* For a child element the root reference of the returned set is keyed by the root document
|
|
482
|
+
* URI but holds a ParseResultElement wrapping a copy of the child, not the root document.
|
|
483
|
+
* The set describes the references reachable from the child and is not a whole-document set.
|
|
484
|
+
*
|
|
485
|
+
* The `dereference.refSet` option is ignored: resolving always builds a fresh ReferenceSet.
|
|
486
|
+
*
|
|
487
|
+
* @param element - An ApiDOM element (ParseResultElement or child element like PathItemElement)
|
|
488
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
489
|
+
* @returns A promise that resolves to the ReferenceSet of the element and its external references
|
|
490
|
+
* @throws ResolveError - When baseURI is required but not provided, when the document is not an OpenAPI specification, or when resolving fails
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* Resolve ParseResultElement with retrievalURI (from file parsing)
|
|
494
|
+
* ```typescript
|
|
495
|
+
* import { parseOpenAPI } from '@usearazzo/parser';
|
|
496
|
+
*
|
|
497
|
+
* const parseResult = await parseOpenAPI('/path/to/openapi.json');
|
|
498
|
+
* const refSet = await resolveOpenAPIElement(parseResult);
|
|
499
|
+
* ```
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* Resolve ParseResultElement without retrievalURI (from inline parsing)
|
|
503
|
+
* ```typescript
|
|
504
|
+
* const parseResult = await parseOpenAPI({ openapi: '3.1.0', ... });
|
|
505
|
+
* const refSet = await resolveOpenAPIElement(parseResult, {
|
|
506
|
+
* resolve: { baseURI: 'https://example.com/openapi.json' },
|
|
507
|
+
* });
|
|
508
|
+
* ```
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* Resolve child element (e.g., PathItemElement)
|
|
512
|
+
* ```typescript
|
|
513
|
+
* const parseResult = await parseOpenAPI('/path/to/openapi.json');
|
|
514
|
+
* const pathItem = parseResult.api.paths.get('/users');
|
|
515
|
+
* const refSet = await resolveOpenAPIElement(pathItem, {
|
|
516
|
+
* dereference: { strategyOpts: { parseResult } },
|
|
517
|
+
* });
|
|
518
|
+
* ```
|
|
519
|
+
* @public
|
|
520
|
+
*/
|
|
521
|
+
export declare function resolveOpenAPIElement<T extends Element_2>(element: T, options?: ResolveOpenAPIOptions): Promise<ReferenceSet>;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Options for resolving OpenAPI Documents.
|
|
525
|
+
* @public
|
|
526
|
+
*/
|
|
527
|
+
export declare type ResolveOpenAPIOptions = PartialDeep<ApiDOMReferenceOptions>;
|
|
528
|
+
|
|
529
|
+
export { }
|