@jentic/arazzo-resolver 1.0.0-alpha.7 → 1.0.0-alpha.9
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 +13 -0
- package/README.md +264 -67
- package/dist/jentic-arazzo-resolver.browser.js +1550 -92
- package/dist/jentic-arazzo-resolver.browser.min.js +1 -1
- package/package.json +10 -7
- package/src/{dereference.cjs → dereference/arazzo.cjs} +89 -19
- package/src/{dereference.mjs → dereference/arazzo.mjs} +94 -24
- package/src/dereference/openapi.cjs +259 -0
- package/src/dereference/openapi.mjs +251 -0
- package/src/index.cjs +9 -8
- package/src/index.mjs +2 -1
- package/types/arazzo-resolver.d.ts +128 -20
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-alpha.9](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2026-02-05)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **resolver:** add dereferencing support for Arazzo Source Descriptions ([#43](https://github.com/jentic/jentic-arazzo-tools/issues/43)) ([091610b](https://github.com/jentic/jentic-arazzo-tools/commit/091610be81b32540845c7f1cb60dd68348ee282b))
|
|
11
|
+
|
|
12
|
+
# [1.0.0-alpha.8](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2026-02-05)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- **resolver:** add dereferencing support for OpenAPI Documents & fragments ([#42](https://github.com/jentic/jentic-arazzo-tools/issues/42)) ([7687c9e](https://github.com/jentic/jentic-arazzo-tools/commit/7687c9eecc50aab508e67ba5d639b31e25154eff))
|
|
17
|
+
- **resolver:** improve API consistency and validation ([#36](https://github.com/jentic/jentic-arazzo-tools/issues/36)) ([aa095cb](https://github.com/jentic/jentic-arazzo-tools/commit/aa095cb19a1543cd675bfa94a6de1651d21a58b5))
|
|
18
|
+
|
|
6
19
|
# [1.0.0-alpha.7](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.6...v1.0.0-alpha.7) (2026-02-04)
|
|
7
20
|
|
|
8
21
|
### Features
|
package/README.md
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
# @jentic/arazzo-resolver
|
|
2
2
|
|
|
3
|
-
`@jentic/arazzo-resolver` is a resolver for [Arazzo Specification](https://spec.openapis.org/arazzo/latest.html) documents.
|
|
4
|
-
It produces [SpecLynx ApiDOM](https://github.com/speclynx/apidom) data
|
|
5
|
-
|
|
6
|
-
## What is dereferencing?
|
|
7
|
-
|
|
8
|
-
Dereferencing is the process of replacing references with the actual content they point to. In Arazzo Documents, this includes:
|
|
9
|
-
|
|
10
|
-
- **JSON Schemas** - resolves all referencing mechanisms (`$ref`, `$anchor`, etc.) within schemas
|
|
11
|
-
- **Reusable Object references** (`$components.*`) - references to reusable components like inputs, parameters, and success actions
|
|
12
|
-
|
|
13
|
-
After dereferencing, all references are resolved inline, making the document self-contained and easier to process programmatically.
|
|
14
|
-
|
|
15
|
-
**Current limitation:** The resolver only processes the entry Arazzo Document. Referenced OpenAPI/AsyncAPI source descriptions are not resolved.
|
|
3
|
+
`@jentic/arazzo-resolver` is a resolver for [Arazzo Specification](https://spec.openapis.org/arazzo/latest.html) and [OpenAPI Specification](https://spec.openapis.org/oas/latest.html) documents.
|
|
4
|
+
It produces [SpecLynx ApiDOM](https://github.com/speclynx/apidom) data models using the appropriate namespace ([Arazzo 1.x](https://github.com/speclynx/apidom/tree/main/packages/apidom-ns-arazzo-1#readme), [OpenAPI 2.0](https://github.com/speclynx/apidom/tree/main/packages/apidom-ns-openapi-2#readme), [OpenAPI 3.0.x](https://github.com/speclynx/apidom/tree/main/packages/apidom-ns-openapi-3-0#readme), [OpenAPI 3.1.x](https://github.com/speclynx/apidom/tree/main/packages/apidom-ns-openapi-3-1#readme)).
|
|
16
5
|
|
|
17
6
|
## Installation
|
|
18
7
|
|
|
@@ -22,81 +11,223 @@ You can install this package via [npm](https://npmjs.org/) CLI by running the fo
|
|
|
22
11
|
npm install @jentic/arazzo-resolver
|
|
23
12
|
```
|
|
24
13
|
|
|
25
|
-
##
|
|
14
|
+
## Dereferencing
|
|
15
|
+
|
|
16
|
+
Dereferencing is the process of replacing references with the actual content they point to.
|
|
17
|
+
|
|
18
|
+
**In Arazzo Documents**, this includes:
|
|
19
|
+
|
|
20
|
+
- **JSON Schemas** - resolves references within schemas
|
|
21
|
+
- **Reusable Object references** (`$components.*`) - references to reusable components like parameters and actions
|
|
22
|
+
|
|
23
|
+
**In OpenAPI Documents**, this includes:
|
|
24
|
+
|
|
25
|
+
- **Reference Objects** (`$ref`) - resolves references to components, external files, and URLs
|
|
26
|
+
- **JSON Schemas** - resolves references within schemas
|
|
27
|
+
- **Path Item Object** - resolves references to path items
|
|
28
|
+
- and others
|
|
29
|
+
|
|
30
|
+
After dereferencing, all references are resolved inline, making the document self-contained and easier to process programmatically.
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
### Functions
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
**Arazzo:**
|
|
35
|
+
- **`dereferenceArazzo(uri)`** - Dereferences from a file system path or HTTP(S) URL
|
|
36
|
+
- **`dereferenceArazzoElement(element)`** - Dereferences a SpecLynx ApiDOM element
|
|
31
37
|
|
|
32
|
-
|
|
38
|
+
**OpenAPI:**
|
|
39
|
+
- **`dereferenceOpenAPI(uri)`** - Dereferences from a file system path or HTTP(S) URL
|
|
40
|
+
- **`dereferenceOpenAPIElement(element)`** - Dereferences a SpecLynx ApiDOM element
|
|
41
|
+
|
|
42
|
+
### Arazzo Documents
|
|
43
|
+
|
|
44
|
+
#### From file
|
|
33
45
|
|
|
34
46
|
```js
|
|
35
|
-
import {
|
|
47
|
+
import { dereferenceArazzo } from '@jentic/arazzo-resolver';
|
|
36
48
|
|
|
37
|
-
const parseResult = await
|
|
49
|
+
const parseResult = await dereferenceArazzo('/path/to/arazzo.json');
|
|
38
50
|
// parseResult is ParseResultElement with all references resolved
|
|
39
51
|
```
|
|
40
52
|
|
|
41
|
-
|
|
53
|
+
#### From URL
|
|
42
54
|
|
|
43
55
|
```js
|
|
44
|
-
import {
|
|
56
|
+
import { dereferenceArazzo } from '@jentic/arazzo-resolver';
|
|
45
57
|
|
|
46
|
-
const parseResult = await
|
|
58
|
+
const parseResult = await dereferenceArazzo('https://example.com/arazzo.yaml');
|
|
47
59
|
```
|
|
48
60
|
|
|
49
|
-
|
|
61
|
+
#### From ApiDOM element
|
|
50
62
|
|
|
51
63
|
When you already have a parsed Arazzo Document (e.g., from `@jentic/arazzo-parser`), you can dereference the element directly:
|
|
52
64
|
|
|
53
65
|
```js
|
|
54
66
|
import { parseArazzo } from '@jentic/arazzo-parser';
|
|
55
|
-
import {
|
|
67
|
+
import { dereferenceArazzoElement } from '@jentic/arazzo-resolver';
|
|
56
68
|
|
|
57
69
|
// Parse first, then dereference
|
|
58
70
|
const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
59
|
-
const dereferenced = await
|
|
71
|
+
const dereferenced = await dereferenceArazzoElement(parseResult);
|
|
60
72
|
```
|
|
61
73
|
|
|
62
|
-
|
|
74
|
+
##### Without retrievalURI
|
|
63
75
|
|
|
64
76
|
When dereferencing a ParseResultElement that was parsed from inline content (string or object), you must provide a `baseURI`:
|
|
65
77
|
|
|
66
78
|
```js
|
|
67
79
|
import { parseArazzo } from '@jentic/arazzo-parser';
|
|
68
|
-
import {
|
|
80
|
+
import { dereferenceArazzoElement } from '@jentic/arazzo-resolver';
|
|
69
81
|
|
|
70
82
|
const parseResult = await parseArazzo({ arazzo: '1.0.1', ... });
|
|
71
|
-
const dereferenced = await
|
|
83
|
+
const dereferenced = await dereferenceArazzoElement(parseResult, {
|
|
72
84
|
resolve: { baseURI: 'https://example.com/arazzo.json' },
|
|
73
85
|
});
|
|
74
86
|
```
|
|
75
87
|
|
|
76
|
-
|
|
88
|
+
##### Child elements
|
|
77
89
|
|
|
78
90
|
You can dereference individual child elements (e.g., a specific workflow) by providing the parent parseResult in options:
|
|
79
91
|
|
|
80
92
|
```js
|
|
81
93
|
import { parseArazzo } from '@jentic/arazzo-parser';
|
|
82
|
-
import {
|
|
94
|
+
import { dereferenceArazzoElement } from '@jentic/arazzo-resolver';
|
|
83
95
|
|
|
84
96
|
const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
85
97
|
const workflow = parseResult.api.workflows.get(0);
|
|
86
98
|
|
|
87
|
-
const dereferencedWorkflow = await
|
|
99
|
+
const dereferencedWorkflow = await dereferenceArazzoElement(workflow, {
|
|
100
|
+
dereference: { strategyOpts: { parseResult } },
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
##### Source descriptions
|
|
105
|
+
|
|
106
|
+
Source descriptions referenced in the Arazzo Document can optionally be dereferenced using strategy options.
|
|
107
|
+
|
|
108
|
+
The following options can be passed via `dereference.strategyOpts` (globally) or `dereference.strategyOpts['arazzo-1']` (strategy-specific).
|
|
109
|
+
Strategy-specific options take precedence over global options.
|
|
110
|
+
|
|
111
|
+
- **sourceDescriptions** - Controls which external source descriptions are dereferenced and included in the result.
|
|
112
|
+
- `true` - dereference all source descriptions
|
|
113
|
+
- `string[]` - dereference only source descriptions with matching names (e.g., `['petStore', 'paymentApi']`)
|
|
114
|
+
|
|
115
|
+
Each dereferenced source description is added with a `'source-description'` class and metadata (`name`, `type`).
|
|
116
|
+
Only [OpenAPI 2.0](https://spec.openapis.org/oas/v2.0), [OpenAPI 3.0.x](https://spec.openapis.org/oas/v3.0.4), [OpenAPI 3.1.x](https://spec.openapis.org/oas/v3.1.2), and [Arazzo 1.x](https://spec.openapis.org/arazzo/v1.0.1) documents are accepted as source descriptions.
|
|
117
|
+
- **sourceDescriptionsMaxDepth** - Maximum recursion depth for dereferencing nested Arazzo source descriptions.
|
|
118
|
+
Defaults to `+Infinity`. Circular references are automatically detected and skipped.
|
|
119
|
+
|
|
120
|
+
###### Error handling
|
|
121
|
+
|
|
122
|
+
The source descriptions dereferencing uses annotations instead of throwing errors, allowing dereferencing to continue
|
|
123
|
+
even when individual source descriptions fail. Errors are reported as `AnnotationElement` instances
|
|
124
|
+
with an `'error'` class within the result:
|
|
125
|
+
|
|
126
|
+
- **Max depth exceeded** - When `sourceDescriptionsMaxDepth` is reached, an error annotation is returned
|
|
127
|
+
instead of the nested source descriptions
|
|
128
|
+
- **Dereference failures** - If a source description file cannot be dereferenced (e.g., file not found, invalid syntax),
|
|
129
|
+
an error annotation is returned for that specific source description while other source descriptions
|
|
130
|
+
continue to be processed
|
|
131
|
+
- **Validation warnings** - Warning annotations (with `'warning'` class) are returned when the dereferenced document
|
|
132
|
+
is not an OpenAPI or Arazzo specification
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
import { dereferenceArazzo } from '@jentic/arazzo-resolver';
|
|
136
|
+
|
|
137
|
+
// Dereference all source descriptions
|
|
138
|
+
const result = await dereferenceArazzo('/path/to/arazzo.json', {
|
|
139
|
+
dereference: {
|
|
140
|
+
strategyOpts: {
|
|
141
|
+
sourceDescriptions: true,
|
|
142
|
+
sourceDescriptionsMaxDepth: 10,
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Dereference only specific source descriptions by name
|
|
148
|
+
const resultFiltered = await dereferenceArazzo('/path/to/arazzo.json', {
|
|
149
|
+
dereference: {
|
|
150
|
+
strategyOpts: {
|
|
151
|
+
'arazzo-1': {
|
|
152
|
+
sourceDescriptions: ['petStore', 'paymentApi'],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### OpenAPI Documents
|
|
160
|
+
|
|
161
|
+
Supports [OpenAPI 2.0 (Swagger)](https://spec.openapis.org/oas/v2.0), [OpenAPI 3.0.x](https://spec.openapis.org/oas/v3.0.4), and [OpenAPI 3.1.x](https://spec.openapis.org/oas/v3.1.2).
|
|
162
|
+
|
|
163
|
+
#### From file
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
import { dereferenceOpenAPI } from '@jentic/arazzo-resolver';
|
|
167
|
+
|
|
168
|
+
const parseResult = await dereferenceOpenAPI('/path/to/openapi.json');
|
|
169
|
+
// parseResult is ParseResultElement with all references resolved
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
#### From URL
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
import { dereferenceOpenAPI } from '@jentic/arazzo-resolver';
|
|
176
|
+
|
|
177
|
+
const parseResult = await dereferenceOpenAPI('https://example.com/openapi.yaml');
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### From ApiDOM element
|
|
181
|
+
|
|
182
|
+
When you already have a parsed OpenAPI Document (e.g., from `@jentic/arazzo-parser`), you can dereference the element directly:
|
|
183
|
+
|
|
184
|
+
```js
|
|
185
|
+
import { parseOpenAPI } from '@jentic/arazzo-parser';
|
|
186
|
+
import { dereferenceOpenAPIElement } from '@jentic/arazzo-resolver';
|
|
187
|
+
|
|
188
|
+
// Parse first, then dereference
|
|
189
|
+
const parseResult = await parseOpenAPI('/path/to/openapi.json');
|
|
190
|
+
const dereferenced = await dereferenceOpenAPIElement(parseResult);
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
##### Without retrievalURI
|
|
194
|
+
|
|
195
|
+
When dereferencing a ParseResultElement that was parsed from inline content (string or object), you must provide a `baseURI`:
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
import { parseOpenAPI } from '@jentic/arazzo-parser';
|
|
199
|
+
import { dereferenceOpenAPIElement } from '@jentic/arazzo-resolver';
|
|
200
|
+
|
|
201
|
+
const parseResult = await parseOpenAPI({ openapi: '3.1.0', ... });
|
|
202
|
+
const dereferenced = await dereferenceOpenAPIElement(parseResult, {
|
|
203
|
+
resolve: { baseURI: 'https://example.com/openapi.json' },
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
##### Child elements
|
|
208
|
+
|
|
209
|
+
You can dereference individual child elements (e.g., a specific Operation Object) by providing the parent parseResult in options:
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
import { parseOpenAPI } from '@jentic/arazzo-parser';
|
|
213
|
+
import { dereferenceOpenAPIElement } from '@jentic/arazzo-resolver';
|
|
214
|
+
|
|
215
|
+
const parseResult = await parseOpenAPI('/path/to/openapi.json');
|
|
216
|
+
const operation = parseResult.api.paths.get('/users').get;
|
|
217
|
+
|
|
218
|
+
const dereferencedOperation = await dereferenceOpenAPIElement(operation, {
|
|
88
219
|
dereference: { strategyOpts: { parseResult } },
|
|
89
220
|
});
|
|
90
221
|
```
|
|
91
222
|
|
|
92
|
-
|
|
223
|
+
### Options
|
|
93
224
|
|
|
94
|
-
|
|
225
|
+
All dereference functions accept an optional options argument compatible with [SpecLynx ApiDOM Reference Options](https://github.com/speclynx/apidom/blob/main/packages/apidom-reference/src/options/index.ts):
|
|
95
226
|
|
|
96
227
|
```js
|
|
97
|
-
import {
|
|
228
|
+
import { dereferenceArazzo } from '@jentic/arazzo-resolver';
|
|
98
229
|
|
|
99
|
-
const parseResult = await
|
|
230
|
+
const parseResult = await dereferenceArazzo('/path/to/arazzo.json', {
|
|
100
231
|
resolve: {
|
|
101
232
|
baseURI: 'https://example.com/', // Base URI for relative references
|
|
102
233
|
},
|
|
@@ -108,53 +239,94 @@ const parseResult = await dereference('/path/to/arazzo.json', {
|
|
|
108
239
|
});
|
|
109
240
|
```
|
|
110
241
|
|
|
111
|
-
|
|
242
|
+
#### Default options
|
|
112
243
|
|
|
113
244
|
You can import and inspect the default options:
|
|
114
245
|
|
|
115
246
|
```js
|
|
116
|
-
import {
|
|
247
|
+
import {
|
|
248
|
+
defaultDereferenceArazzoOptions,
|
|
249
|
+
defaultDereferenceOpenAPIOptions,
|
|
250
|
+
} from '@jentic/arazzo-resolver';
|
|
251
|
+
|
|
252
|
+
console.log(defaultDereferenceArazzoOptions);
|
|
253
|
+
// {
|
|
254
|
+
// resolve: {
|
|
255
|
+
// resolvers: [FileResolver, HTTPResolverAxios],
|
|
256
|
+
// },
|
|
257
|
+
// parse: {
|
|
258
|
+
// parsers: [
|
|
259
|
+
// ArazzoJSON1Parser, ArazzoYAML1Parser,
|
|
260
|
+
// OpenApiJSON2Parser, OpenApiYAML2Parser,
|
|
261
|
+
// OpenApiJSON3_0Parser, OpenApiYAML3_0Parser,
|
|
262
|
+
// OpenApiJSON3_1Parser, OpenApiYAML3_1Parser,
|
|
263
|
+
// JSONParser, YAMLParser, BinaryParser
|
|
264
|
+
// ],
|
|
265
|
+
// },
|
|
266
|
+
// dereference: {
|
|
267
|
+
// strategies: [
|
|
268
|
+
// Arazzo1DereferenceStrategy,
|
|
269
|
+
// OpenAPI2DereferenceStrategy, OpenAPI3_0DereferenceStrategy, OpenAPI3_1DereferenceStrategy
|
|
270
|
+
// ],
|
|
271
|
+
// strategyOpts: {
|
|
272
|
+
// sourceDescriptions: false,
|
|
273
|
+
// },
|
|
274
|
+
// },
|
|
275
|
+
// }
|
|
117
276
|
|
|
118
|
-
console.log(
|
|
277
|
+
console.log(defaultDereferenceOpenAPIOptions);
|
|
119
278
|
// {
|
|
120
279
|
// resolve: {
|
|
121
280
|
// resolvers: [FileResolver, HTTPResolverAxios],
|
|
122
281
|
// },
|
|
123
282
|
// parse: {
|
|
124
|
-
//
|
|
125
|
-
//
|
|
283
|
+
// parsers: [
|
|
284
|
+
// OpenApiJSON2Parser, OpenApiYAML2Parser,
|
|
285
|
+
// OpenApiJSON3_0Parser, OpenApiYAML3_0Parser,
|
|
286
|
+
// OpenApiJSON3_1Parser, OpenApiYAML3_1Parser,
|
|
287
|
+
// JSONParser, YAMLParser, BinaryParser
|
|
288
|
+
// ],
|
|
126
289
|
// },
|
|
127
290
|
// dereference: {
|
|
128
|
-
// strategies: [
|
|
291
|
+
// strategies: [OpenAPI2DereferenceStrategy, OpenAPI3_0DereferenceStrategy, OpenAPI3_1DereferenceStrategy],
|
|
129
292
|
// },
|
|
130
293
|
// }
|
|
131
294
|
```
|
|
132
295
|
|
|
133
|
-
|
|
296
|
+
### Error handling
|
|
134
297
|
|
|
135
298
|
When dereferencing fails, a `DereferenceError` is thrown. The original error is available via the `cause` property:
|
|
136
299
|
|
|
137
300
|
```js
|
|
138
|
-
import {
|
|
301
|
+
import { dereferenceArazzo, dereferenceOpenAPI, DereferenceError } from '@jentic/arazzo-resolver';
|
|
139
302
|
|
|
140
303
|
try {
|
|
141
|
-
await
|
|
304
|
+
await dereferenceArazzo('/path/to/arazzo.json');
|
|
142
305
|
} catch (error) {
|
|
143
306
|
if (error instanceof DereferenceError) {
|
|
144
307
|
console.error(error.message); // 'Failed to dereference Arazzo Document at "/path/to/arazzo.json"'
|
|
145
308
|
console.error(error.cause); // Original error from underlying resolver
|
|
146
309
|
}
|
|
147
310
|
}
|
|
311
|
+
|
|
312
|
+
try {
|
|
313
|
+
await dereferenceOpenAPI('/path/to/openapi.json');
|
|
314
|
+
} catch (error) {
|
|
315
|
+
if (error instanceof DereferenceError) {
|
|
316
|
+
console.error(error.message); // 'Failed to dereference OpenAPI Document at "/path/to/openapi.json"'
|
|
317
|
+
console.error(error.cause); // Original error from underlying resolver
|
|
318
|
+
}
|
|
319
|
+
}
|
|
148
320
|
```
|
|
149
321
|
|
|
150
|
-
|
|
322
|
+
### Working with the result
|
|
151
323
|
|
|
152
|
-
|
|
324
|
+
Both `dereferenceArazzo` and `dereferenceOpenAPI` functions return a [ParseResultElement](https://github.com/speclynx/apidom/blob/main/packages/apidom-datamodel/README.md#parseresultelement) with all references resolved inline.
|
|
153
325
|
|
|
154
326
|
```js
|
|
155
|
-
import {
|
|
327
|
+
import { dereferenceArazzo } from '@jentic/arazzo-resolver';
|
|
156
328
|
|
|
157
|
-
const parseResult = await
|
|
329
|
+
const parseResult = await dereferenceArazzo('/path/to/arazzo.json');
|
|
158
330
|
|
|
159
331
|
// Access the main Arazzo specification element
|
|
160
332
|
const arazzoSpec = parseResult.api;
|
|
@@ -170,31 +342,56 @@ const firstWorkflow = arazzoSpec.workflows.get(0);
|
|
|
170
342
|
const firstStep = firstWorkflow.steps.get(0);
|
|
171
343
|
```
|
|
172
344
|
|
|
173
|
-
|
|
345
|
+
#### Retrieval URI metadata
|
|
174
346
|
|
|
175
|
-
|
|
347
|
+
Both `dereferenceArazzo` and `dereferenceOpenAPI` functions automatically set `retrievalURI` metadata on the parse result:
|
|
176
348
|
|
|
177
349
|
```js
|
|
178
|
-
import {
|
|
350
|
+
import { dereferenceArazzo, dereferenceOpenAPI } from '@jentic/arazzo-resolver';
|
|
179
351
|
import { toValue } from '@speclynx/apidom-core';
|
|
180
352
|
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
const uri = toValue(parseResult.meta.get('retrievalURI'));
|
|
353
|
+
const arazzoResult = await dereferenceArazzo('https://example.com/arazzo.yaml');
|
|
354
|
+
const arazzoUri = toValue(arazzoResult.meta.get('retrievalURI'));
|
|
184
355
|
// 'https://example.com/arazzo.yaml'
|
|
356
|
+
|
|
357
|
+
const openapiResult = await dereferenceOpenAPI('https://example.com/openapi.yaml');
|
|
358
|
+
const openapiUri = toValue(openapiResult.meta.get('retrievalURI'));
|
|
359
|
+
// 'https://example.com/openapi.yaml'
|
|
185
360
|
```
|
|
186
361
|
|
|
187
|
-
Note: `
|
|
362
|
+
Note: `dereferenceArazzoElement` and `dereferenceOpenAPIElement` do not set `retrievalURI` - they preserve whatever metadata was on the original element.
|
|
363
|
+
|
|
364
|
+
#### Source descriptions
|
|
365
|
+
|
|
366
|
+
When dereferencing with `sourceDescriptions` enabled, the result contains the entry Arazzo Document at index 0, followed by any dereferenced source descriptions.
|
|
367
|
+
Each source description is a `ParseResultElement` with `'source-description'` class and metadata.
|
|
368
|
+
|
|
369
|
+
```js
|
|
370
|
+
import { dereferenceArazzo } from '@jentic/arazzo-resolver';
|
|
371
|
+
import { toValue } from '@speclynx/apidom-core';
|
|
372
|
+
|
|
373
|
+
const result = await dereferenceArazzo('/path/to/arazzo.json', {
|
|
374
|
+
dereference: { strategyOpts: { sourceDescriptions: true } },
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// Access entry Arazzo Document
|
|
378
|
+
const entryArazzo = result.api; // ArazzoSpecification1Element
|
|
188
379
|
|
|
189
|
-
|
|
380
|
+
// Iterate over source descriptions (starting at index 1)
|
|
381
|
+
for (let i = 1; i < result.length; i++) {
|
|
382
|
+
const sdParseResult = result.get(i);
|
|
190
383
|
|
|
191
|
-
|
|
384
|
+
// Check if it's a source description
|
|
385
|
+
if (sdParseResult.classes.includes('source-description')) {
|
|
386
|
+
const name = toValue(sdParseResult.meta.get('name'));
|
|
387
|
+
const type = toValue(sdParseResult.meta.get('type')); // 'openapi' or 'arazzo'
|
|
192
388
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
389
|
+
// Access the dereferenced API element
|
|
390
|
+
const api = sdParseResult.api; // OpenApi3_1Element, SwaggerElement, ArazzoSpecification1Element, etc.
|
|
391
|
+
console.log(`Source "${name}" (${type}):`, api?.element);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
```
|
|
198
395
|
|
|
199
396
|
## SpecLynx ApiDOM tooling
|
|
200
397
|
|
|
@@ -205,11 +402,11 @@ Since `@jentic/arazzo-resolver` produces a SpecLynx ApiDOM data model, you have
|
|
|
205
402
|
The [@speclynx/apidom-core](https://github.com/speclynx/apidom/tree/main/packages/apidom-core) package provides essential utilities for working with ApiDOM elements. Here are just a few examples:
|
|
206
403
|
|
|
207
404
|
```js
|
|
208
|
-
import {
|
|
405
|
+
import { dereferenceArazzo } from '@jentic/arazzo-resolver';
|
|
209
406
|
import { cloneDeep, cloneShallow } from '@speclynx/apidom-datamodel';
|
|
210
407
|
import { toValue, toJSON, toYAML, sexprs } from '@speclynx/apidom-core';
|
|
211
408
|
|
|
212
|
-
const parseResult = await
|
|
409
|
+
const parseResult = await dereferenceArazzo('/path/to/arazzo.json');
|
|
213
410
|
const arazzoSpec = parseResult.api;
|
|
214
411
|
|
|
215
412
|
// Convert to plain JavaScript object
|
|
@@ -234,10 +431,10 @@ const sexpr = sexprs(arazzoSpec);
|
|
|
234
431
|
The [@speclynx/apidom-traverse](https://github.com/speclynx/apidom/tree/main/packages/apidom-traverse) package provides powerful traversal capabilities. Here is a basic example:
|
|
235
432
|
|
|
236
433
|
```js
|
|
237
|
-
import {
|
|
434
|
+
import { dereferenceArazzo } from '@jentic/arazzo-resolver';
|
|
238
435
|
import { traverse } from '@speclynx/apidom-traverse';
|
|
239
436
|
|
|
240
|
-
const parseResult = await
|
|
437
|
+
const parseResult = await dereferenceArazzo('/path/to/arazzo.json');
|
|
241
438
|
|
|
242
439
|
// Traverse and collect steps using semantic visitor hook
|
|
243
440
|
const steps = [];
|