@jentic/arazzo-parser 1.0.0-alpha.0 → 1.0.0-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 ADDED
@@ -0,0 +1,65 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [1.0.0-alpha.10](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2026-02-08)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **parser:** add doc for accessing parse result via SourceDescription ([c23699b](https://github.com/jentic/jentic-arazzo-tools/commit/c23699bc6cf77cafbd77a9df5dd5fb355f771696))
11
+
12
+ # [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)
13
+
14
+ ### Features
15
+
16
+ - **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))
17
+
18
+ # [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)
19
+
20
+ **Note:** Version bump only for package @jentic/arazzo-parser
21
+
22
+ # [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)
23
+
24
+ ### Features
25
+
26
+ - **parser:** add support for parsing OpenAPI Documents ([#35](https://github.com/jentic/jentic-arazzo-tools/issues/35)) ([4c2615e](https://github.com/jentic/jentic-arazzo-tools/commit/4c2615e07c3b74ea7fe74b91b977c8c7123a2188))
27
+
28
+ # [1.0.0-alpha.6](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2026-02-04)
29
+
30
+ ### Features
31
+
32
+ - **parser:** add support for parsing entire Arazzo Description ([#34](https://github.com/jentic/jentic-arazzo-tools/issues/34)) ([44b2bda](https://github.com/jentic/jentic-arazzo-tools/commit/44b2bda1c7449e1db8145af1dea457f2e09a465b))
33
+
34
+ # [1.0.0-alpha.5](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.4...v1.0.0-alpha.5) (2026-01-31)
35
+
36
+ **Note:** Version bump only for package @jentic/arazzo-parser
37
+
38
+ # [1.0.0-alpha.4](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.3...v1.0.0-alpha.4) (2026-01-31)
39
+
40
+ ### Features
41
+
42
+ - **parser:** add unified options interface & retrievalURI meta ([#16](https://github.com/jentic/jentic-arazzo-tools/issues/16)) ([2d6c3b3](https://github.com/jentic/jentic-arazzo-tools/commit/2d6c3b37f3246bc5ad775c30b508607119c9eb50))
43
+ - **resolver:** add dereferencing support for Arazzo Document fragments ([#21](https://github.com/jentic/jentic-arazzo-tools/issues/21)) ([868dc43](https://github.com/jentic/jentic-arazzo-tools/commit/868dc434b51f6247ca102fae7422a85a0e545d09))
44
+ - **resolver:** add dereferencing support for entry Arazzo Document ([#15](https://github.com/jentic/jentic-arazzo-tools/issues/15)) ([cf016ed](https://github.com/jentic/jentic-arazzo-tools/commit/cf016ed9130f08aac87bbb94b0e45e80c27f8fc3))
45
+
46
+ # [1.0.0-alpha.3](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.2...v1.0.0-alpha.3) (2026-01-29)
47
+
48
+ ### Features
49
+
50
+ - **parser:** add package keywords ([#10](https://github.com/jentic/jentic-arazzo-tools/issues/10)) ([0e71b1b](https://github.com/jentic/jentic-arazzo-tools/commit/0e71b1b77a1222a427214f7f9c281cbc1da13278))
51
+
52
+ # [1.0.0-alpha.2](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2026-01-28)
53
+
54
+ **Note:** Version bump only for package @jentic/arazzo-parser
55
+
56
+ # 1.0.0-alpha.1 (2026-01-28)
57
+
58
+ ### Bug Fixes
59
+
60
+ - **parser:** trhow error on pojo + sourceMap option combo ([#4](https://github.com/jentic/jentic-arazzo-tools/issues/4)) ([b3c4527](https://github.com/jentic/jentic-arazzo-tools/commit/b3c45271397daa297213308b048efbcaf85524f1)), closes [#3](https://github.com/jentic/jentic-arazzo-tools/issues/3)
61
+
62
+ ### Features
63
+
64
+ - implement semantic Arazzo Document parser ([#1](https://github.com/jentic/jentic-arazzo-tools/issues/1)) ([ce65056](https://github.com/jentic/jentic-arazzo-tools/commit/ce650568b1926f65bea1831d91e0fcbd9c44e383))
65
+ - setup lerna monorepo ([15a7363](https://github.com/jentic/jentic-arazzo-tools/commit/15a7363e93c630f8cbe7393cfd808186e6fdf852))
package/README.md CHANGED
@@ -13,17 +13,21 @@ npm install @jentic/arazzo-parser
13
13
 
14
14
  ## Usage
15
15
 
16
- `@jentic/arazzo-parser` provides a unified `parse` function that accepts multiple input types:
16
+ `@jentic/arazzo-parser` provides a `parseArazzo` function for parsing Arazzo documents.
17
17
 
18
- 1. **Plain JavaScript object** - directly refracts into ApiDOM
19
- 2. **String content** - parses inline JSON or YAML Arazzo Documents
18
+ ## Parsing Arazzo Documents
19
+
20
+ The `parseArazzo` function accepts multiple input types:
21
+
22
+ 1. **Plain JavaScript object** - converts to JSON and parses (source maps supported with `strict: false`)
23
+ 2. **String content** - detects Arazzo content and parses inline JSON or YAML
20
24
  3. **File system path** - resolves and parses local Arazzo Documents
21
25
  4. **HTTP(S) URL** - fetches and parses remote Arazzo Documents
22
26
 
23
- ### Parsing from object
27
+ ### From object
24
28
 
25
29
  ```js
26
- import { parse } from '@jentic/arazzo-parser';
30
+ import { parseArazzo } from '@jentic/arazzo-parser';
27
31
 
28
32
  const arazzoDocument = {
29
33
  arazzo: '1.0.1',
@@ -41,20 +45,20 @@ const arazzoDocument = {
41
45
  workflows: [],
42
46
  };
43
47
 
44
- const parseResult = await parse(arazzoDocument);
48
+ const parseResult = await parseArazzo(arazzoDocument);
45
49
  // parseResult is ParseResultElement containing ArazzoSpecification1Element
46
50
  ```
47
51
 
48
- ### Parsing from string
52
+ ### From string
49
53
 
50
54
  ```js
51
- import { parse } from '@jentic/arazzo-parser';
55
+ import { parseArazzo } from '@jentic/arazzo-parser';
52
56
 
53
57
  // JSON string
54
- const parseResult = await parse('{"arazzo": "1.0.1", "info": {...}}');
58
+ const parseResult = await parseArazzo('{"arazzo": "1.0.1", "info": {...}}');
55
59
 
56
60
  // YAML string
57
- const parseResult = await parse(`
61
+ const parseResult = await parseArazzo(`
58
62
  arazzo: '1.0.1'
59
63
  info:
60
64
  title: My API Workflow
@@ -62,55 +66,62 @@ info:
62
66
  `);
63
67
  ```
64
68
 
65
- ### Parsing from file
69
+ ### From file
66
70
 
67
71
  ```js
68
- import { parse } from '@jentic/arazzo-parser';
72
+ import { parseArazzo } from '@jentic/arazzo-parser';
69
73
 
70
- const parseResult = await parse('/path/to/arazzo.json');
74
+ const parseResult = await parseArazzo('/path/to/arazzo.json');
71
75
  ```
72
76
 
73
- ### Parsing from URL
77
+ ### From URL
74
78
 
75
79
  ```js
76
- import { parse } from '@jentic/arazzo-parser';
80
+ import { parseArazzo } from '@jentic/arazzo-parser';
77
81
 
78
- const parseResult = await parse('https://example.com/arazzo.yaml');
82
+ const parseResult = await parseArazzo('https://example.com/arazzo.yaml');
79
83
  ```
80
84
 
81
85
  ## Parse options
82
86
 
83
- The `parse` function accepts an optional second argument with parsing options:
87
+ The `parseArazzo` function accepts an optional second argument with reference options compatible with [SpecLynx ApiDOM Reference Options](https://github.com/speclynx/apidom/blob/main/packages/apidom-reference/src/options/index.ts):
84
88
 
85
89
  ```js
86
- import { parse } from '@jentic/arazzo-parser';
90
+ import { parseArazzo } from '@jentic/arazzo-parser';
87
91
 
88
- const parseResult = await parse(source, {
89
- strict: true, // Use strict parsing mode (default: true)
90
- sourceMap: false, // Include source maps (default: false)
91
- parserOpts: {}, // Additional parser options (default: {})
92
- resolverOpts: {}, // Additional resolver options (default: {})
92
+ const parseResult = await parseArazzo(source, {
93
+ parse: {
94
+ parserOpts: {
95
+ strict: true, // Use strict parsing mode (default: true)
96
+ sourceMap: false, // Include source maps (default: false)
97
+ },
98
+ },
93
99
  });
94
100
  ```
95
101
 
96
- ### Options
97
-
98
- | Option | Type | Default | Description |
99
- |--------|------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------|
100
- | `strict` | `boolean` | `true` | Whether to enforce strict parsing mode. Strict mode uses native JSON and YAML parsers without error recovery. |
101
- | `sourceMap` | `boolean` | `false` | Whether to include [source maps](https://github.com/speclynx/apidom/blob/main/packages/apidom-datamodel/README.md#source-maps) in the parsed result. |
102
- | `parserOpts` | `Record<string, unknown>` | `{}` | Additional options passed to the underlying parsers. |
103
- | `resolverOpts` | `Record<string, unknown>` | `{}` | Additional options passed to the underlying resolvers. |
104
-
105
102
  ### Default options
106
103
 
107
104
  You can import the default options:
108
105
 
109
106
  ```js
110
- import { defaultParseOptions } from '@jentic/arazzo-parser';
111
-
112
- console.log(defaultParseOptions);
113
- // { strict: true, sourceMap: false, parserOpts: {}, resolverOpts: {} }
107
+ import { defaultOptions } from '@jentic/arazzo-parser';
108
+
109
+ console.log(defaultOptions);
110
+ // {
111
+ // parse: {
112
+ // parsers: [
113
+ // ArazzoJSON1Parser, ArazzoYAML1Parser,
114
+ // OpenApiJSON2Parser, OpenApiYAML2Parser,
115
+ // OpenApiJSON3_0Parser, OpenApiYAML3_0Parser,
116
+ // OpenApiJSON3_1Parser, OpenApiYAML3_1Parser,
117
+ // ],
118
+ // parserOpts: { sourceMap: false, strict: true, sourceDescriptions: false },
119
+ // },
120
+ // resolve: {
121
+ // resolvers: [MemoryResolver, FileResolver, HTTPResolverAxios],
122
+ // resolverOpts: {},
123
+ // },
124
+ // }
114
125
  ```
115
126
 
116
127
  ## Error handling
@@ -118,10 +129,10 @@ console.log(defaultParseOptions);
118
129
  When parsing fails, a `ParseError` is thrown. The original error is available via the `cause` property:
119
130
 
120
131
  ```js
121
- import { parse } from '@jentic/arazzo-parser';
132
+ import { parseArazzo } from '@jentic/arazzo-parser';
122
133
 
123
134
  try {
124
- await parse('invalid content');
135
+ await parseArazzo('invalid content');
125
136
  } catch (error) {
126
137
  console.error(error.message); // 'Failed to parse Arazzo Document'
127
138
  console.error(error.cause); // Original error from underlying parser
@@ -130,12 +141,12 @@ try {
130
141
 
131
142
  ## Working with the result
132
143
 
133
- The `parse` function returns a [ParseResultElement](https://github.com/speclynx/apidom/blob/main/packages/apidom-datamodel/README.md#parseresultelement) representing the result of the parsing operation.
144
+ The `parseArazzo` function returns a [ParseResultElement](https://github.com/speclynx/apidom/blob/main/packages/apidom-datamodel/README.md#parseresultelement) representing the result of the parsing operation.
134
145
 
135
146
  ```js
136
- import { parse } from '@jentic/arazzo-parser';
147
+ import { parseArazzo } from '@jentic/arazzo-parser';
137
148
 
138
- const parseResult = await parse(source);
149
+ const parseResult = await parseArazzo(source);
139
150
 
140
151
  // Access the main Arazzo specification element
141
152
  const arazzoSpec = parseResult.api;
@@ -147,6 +158,349 @@ const hasErrors = parseResult.errors.length > 0;
147
158
  const isEmpty = parseResult.isEmpty;
148
159
  ```
149
160
 
161
+ ### Retrieval URI metadata
162
+
163
+ When parsing from a file system path or HTTP(S) URL, the `retrievalURI` metadata is set on the parse result:
164
+
165
+ ```js
166
+ import { parseArazzo } from '@jentic/arazzo-parser';
167
+ import { toValue } from '@speclynx/apidom-core';
168
+
169
+ const parseResult = await parseArazzo('/path/to/arazzo.json');
170
+
171
+ // Get the URI from which the document was retrieved
172
+ const uri = toValue(parseResult.meta.get('retrievalURI'));
173
+ // '/path/to/arazzo.json'
174
+ ```
175
+
176
+ Note: `retrievalURI` is not set when parsing from inline content (string) or plain objects.
177
+
178
+ ### Source maps
179
+
180
+ Source maps allow you to track the original position (line, column) of each element in the parsed document. This is useful for error reporting, IDE integrations, linting, and any tooling that needs to show precise locations in the original source.
181
+
182
+
183
+ To enable source maps, set `sourceMap: true` and `strict: false` in the parser options:
184
+
185
+ ```js
186
+ import { parseArazzo } from '@jentic/arazzo-parser';
187
+
188
+ const parseResult = await parseArazzo('/path/to/arazzo.yaml', {
189
+ parse: {
190
+ parserOpts: {
191
+ sourceMap: true,
192
+ strict: false,
193
+ },
194
+ },
195
+ });
196
+ ```
197
+
198
+ When source maps are enabled, each element in the parsed result contains positional properties stored directly on the element. Position values use UTF-16 code units for compatibility with Language Server Protocol (LSP) and JavaScript string indexing:
199
+
200
+ ```js
201
+ import { parseArazzo } from '@jentic/arazzo-parser';
202
+
203
+ const parseResult = await parseArazzo('/path/to/arazzo.yaml', {
204
+ parse: { parserOpts: { sourceMap: true, strict: false } },
205
+ });
206
+
207
+ const arazzoSpec = parseResult.api;
208
+
209
+ // Access source map properties directly on the element
210
+ arazzoSpec.startLine; // 0-based line number where element begins
211
+ arazzoSpec.startCharacter; // 0-based column number where element begins
212
+ arazzoSpec.startOffset; // 0-based character offset from document start
213
+ arazzoSpec.endLine; // 0-based line number where element ends
214
+ arazzoSpec.endCharacter; // 0-based column number where element ends
215
+ arazzoSpec.endOffset; // 0-based character offset where element ends
216
+
217
+ // Access source map on nested elements
218
+ const workflow = arazzoSpec.workflows.get(0);
219
+ console.log(`Workflow starts at line ${workflow.startLine}, column ${workflow.startCharacter}`);
220
+ ```
221
+
222
+ For more details about source maps, see the [SpecLynx ApiDOM Data Model documentation](https://github.com/speclynx/apidom/tree/main/packages/apidom-datamodel#source-maps).
223
+
224
+ **Note:** Source maps require `strict: false` to be set. When parsing from objects, they are converted to pretty-printed JSON strings internally (2-space indentation), so source map positions refer to this generated JSON representation, not the original object structure:
225
+
226
+ ```js
227
+ // Source maps with objects (requires strict: false)
228
+ // Positions will reference the internally generated JSON string
229
+ await parseArazzo({ arazzo: '1.0.1', ... }, {
230
+ parse: { parserOpts: { sourceMap: true, strict: false } },
231
+ });
232
+ ```
233
+
234
+ ## Parsing source descriptions
235
+
236
+ Arazzo documents can reference external API specifications (OpenAPI, Arazzo) through [Source Descriptions](https://spec.openapis.org/arazzo/latest.html#source-description-object). The parser can automatically fetch and parse these referenced documents.
237
+
238
+ **Note:** Source descriptions parsing is disabled by default for performance reasons. Enable it explicitly when you need to resolve and parse referenced API specifications.
239
+
240
+ ### Enabling source descriptions parsing
241
+
242
+ To parse source descriptions, enable the `sourceDescriptions` option in `parserOpts`:
243
+
244
+ ```js
245
+ import { parseArazzo } from '@jentic/arazzo-parser';
246
+
247
+ const parseResult = await parseArazzo('/path/to/arazzo.json', {
248
+ parse: {
249
+ parserOpts: {
250
+ sourceDescriptions: true,
251
+ },
252
+ },
253
+ });
254
+ ```
255
+
256
+ Alternatively, you can configure it per parser for more granular control:
257
+
258
+ ```js
259
+ const parseResult = await parseArazzo('/path/to/arazzo.json', {
260
+ parse: {
261
+ parserOpts: {
262
+ 'arazzo-json-1': { sourceDescriptions: true },
263
+ 'arazzo-yaml-1': { sourceDescriptions: true },
264
+ },
265
+ },
266
+ });
267
+ ```
268
+
269
+ ### Selective parsing
270
+
271
+ You can selectively parse only specific source descriptions by providing an array of names:
272
+
273
+ ```js
274
+ const parseResult = await parseArazzo('/path/to/arazzo.json', {
275
+ parse: {
276
+ parserOpts: {
277
+ sourceDescriptions: ['petStoreApi', 'paymentApi'],
278
+ },
279
+ },
280
+ });
281
+ ```
282
+
283
+ ### Result structure
284
+
285
+ When source descriptions are parsed, each parsed document that is a *direct* source description of the main Arazzo document is added to the main `ParseResultElement` as an additional top-level element. The first element is always the main Arazzo document, and subsequent top-level elements are these directly parsed source descriptions. When recursive parsing discovers further source descriptions from within an already parsed source description, those recursively parsed documents are attached as nested `ParseResultElement` instances beneath the source-description element that referenced them (they are not duplicated at the top level). Consumers that need to see all documents should traverse both the top-level elements and any nested `ParseResultElement`s reachable from source-description elements.
286
+
287
+ Source descriptions are parsed into their appropriate SpecLynx ApiDOM namespace data models based on document type:
288
+
289
+ - [Arazzo 1.x](https://spec.openapis.org/arazzo/latest.html) → [@speclynx/apidom-ns-arazzo-1](https://github.com/speclynx/apidom/tree/main/packages/apidom-ns-arazzo-1)
290
+ - [OpenAPI 2.0 (Swagger)](https://spec.openapis.org/oas/v2.0) → [@speclynx/apidom-ns-openapi-2](https://github.com/speclynx/apidom/tree/main/packages/apidom-ns-openapi-2)
291
+ - [OpenAPI 3.0.x](https://spec.openapis.org/oas/v3.0.4) → [@speclynx/apidom-ns-openapi-3-0](https://github.com/speclynx/apidom/tree/main/packages/apidom-ns-openapi-3-0)
292
+ - [OpenAPI 3.1.x](https://spec.openapis.org/oas/v3.1.1) → [@speclynx/apidom-ns-openapi-3-1](https://github.com/speclynx/apidom/tree/main/packages/apidom-ns-openapi-3-1)
293
+
294
+ ```mermaid
295
+ graph TD
296
+ PR["ParseResultElement"] --> API[".api: ArazzoSpecification1Element"]
297
+ PR --> SD1
298
+ PR --> SD2
299
+
300
+ subgraph source-descriptions [source descriptions]
301
+ SD1["ParseResultElement<br/>(petStoreApi)"] --> SD1_API[".api: OpenApi3_1Element"]
302
+ SD2["ParseResultElement<br/>(legacyApi)"] --> SD2_ERR[".errors"]
303
+ SD2 --> SD2_WARN[".warnings"]
304
+ end
305
+
306
+ style PR fill:#e7f1ff,stroke:#0366d6,stroke-width:2px
307
+ style SD1 fill:#f6f8fa,stroke:#586069
308
+ style SD2 fill:#f6f8fa,stroke:#586069
309
+ style API fill:#d4edda,stroke:#28a745
310
+ style SD1_API fill:#d4edda,stroke:#28a745
311
+ style SD2_ERR fill:#f8d7da,stroke:#dc3545
312
+ style SD2_WARN fill:#fff3cd,stroke:#ffc107
313
+ ```
314
+
315
+ ```js
316
+ import { parseArazzo } from '@jentic/arazzo-parser';
317
+
318
+ const parseResult = await parseArazzo('/path/to/arazzo.json', {
319
+ parse: {
320
+ parserOpts: {
321
+ sourceDescriptions: true,
322
+ },
323
+ },
324
+ });
325
+
326
+ // Main Arazzo document
327
+ const arazzoSpec = parseResult.api;
328
+
329
+ // Number of elements (1 main + N source descriptions)
330
+ console.log(parseResult.length);
331
+
332
+ // Access parsed source descriptions (filter by 'source-description' class)
333
+ for (let i = 0; i < parseResult.length; i++) {
334
+ const element = parseResult.get(i);
335
+
336
+ if (element.classes.includes('source-description')) {
337
+ // Source description metadata
338
+ const name = element.meta.get('name')?.toValue();
339
+ const type = element.meta.get('type')?.toValue();
340
+
341
+ console.log(`Source description "${name}" (${type})`);
342
+
343
+ // The parsed API document
344
+ const api = element.api;
345
+ }
346
+ }
347
+ ```
348
+
349
+ ### Accessing via SourceDescriptionElement
350
+
351
+ An alternative way to access parsed source descriptions is through the `SourceDescriptionElement` metadata.
352
+ When source descriptions are parsed, a `ParseResultElement` is attached to each `SourceDescriptionElement`'s metadata under the key `'parseResult'`.
353
+
354
+ ```js
355
+ import { parseArazzo } from '@jentic/arazzo-parser';
356
+ import { toValue } from '@speclynx/apidom-core';
357
+
358
+ const parseResult = await parseArazzo('/path/to/arazzo.json', {
359
+ parse: {
360
+ parserOpts: {
361
+ sourceDescriptions: true,
362
+ },
363
+ },
364
+ });
365
+
366
+ const arazzoSpec = parseResult.api;
367
+
368
+ // Access parsed document via SourceDescriptionElement
369
+ const sourceDesc = arazzoSpec.sourceDescriptions.get(0);
370
+ const sdParseResult = sourceDesc.meta.get('parseResult');
371
+
372
+ // Check for errors before using
373
+ if (sdParseResult.errors.length === 0) {
374
+ // Access the parsed API
375
+ const api = sdParseResult.api;
376
+ console.log(`API type: ${api.element}`); // e.g., 'openApi3_1'
377
+
378
+ // Get the retrieval URI
379
+ const retrievalURI = toValue(sdParseResult.meta.get('retrievalURI'));
380
+ console.log(`Loaded from: ${retrievalURI}`);
381
+ }
382
+ ```
383
+
384
+ This approach is useful when you need to:
385
+ - Access a specific source description by its position in the `sourceDescriptions` array
386
+ - Get the `retrievalURI` metadata indicating where the document was fetched from
387
+ - Correlate parsed documents with their source description definitions
388
+
389
+ ### Recursive parsing
390
+
391
+ When a source description is of type `arazzo`, the parser recursively parses that document's source descriptions as well. This allows you to parse entire dependency trees of Arazzo documents.
392
+
393
+ ### Limiting recursion depth
394
+
395
+ To prevent excessive recursion or handle deeply nested documents, use the `sourceDescriptionsMaxDepth` option:
396
+
397
+ ```js
398
+ const parseResult = await parseArazzo('/path/to/arazzo.json', {
399
+ parse: {
400
+ parserOpts: {
401
+ sourceDescriptions: true,
402
+ sourceDescriptionsMaxDepth: 2, // Only parse 2 levels deep
403
+ },
404
+ },
405
+ });
406
+ ```
407
+
408
+ The default value is `+Infinity` (no limit). Setting it to `0` will create error annotations instead of parsing any source descriptions.
409
+
410
+ ### Cycle detection
411
+
412
+ The parser automatically detects circular references between Arazzo documents. When a cycle is detected, a warning annotation is added instead of causing infinite recursion:
413
+
414
+ ```js
415
+ // arazzo-a.json references arazzo-b.json
416
+ // arazzo-b.json references arazzo-a.json (cycle!)
417
+
418
+ const parseResult = await parseArazzo('/path/to/arazzo-a.json', {
419
+ parse: {
420
+ parserOpts: {
421
+ sourceDescriptions: true,
422
+ },
423
+ },
424
+ });
425
+
426
+ // The cycle is handled gracefully - check for warning annotations
427
+ ```
428
+
429
+ ### Error and warning handling
430
+
431
+ When issues occur during source description parsing, the parser does not throw errors. Instead, it adds annotation elements to the source description's parse result:
432
+
433
+ - **`error`** class - Parsing failed (e.g., file not found, invalid document, max depth exceeded)
434
+ - **`warning`** class - Non-fatal issues (e.g., cycle detected, type mismatch between declared and actual)
435
+
436
+ This allows partial parsing to succeed even if some source descriptions have issues:
437
+
438
+ ```js
439
+ const parseResult = await parseArazzo('/path/to/arazzo.json', {
440
+ parse: {
441
+ parserOpts: {
442
+ sourceDescriptions: true,
443
+ },
444
+ },
445
+ });
446
+
447
+ // Check each source description for errors and warnings
448
+ for (let i = 0; i < parseResult.length; i++) {
449
+ const element = parseResult.get(i);
450
+
451
+ if (element.classes.includes('source-description')) {
452
+ const name = element.meta.get('name')?.toValue();
453
+
454
+ // Use built-in accessors for errors and warnings
455
+ element.errors.forEach((error) => {
456
+ console.error(`Error in "${name}": ${error.toValue()}`);
457
+ });
458
+
459
+ element.warnings.forEach((warning) => {
460
+ console.warn(`Warning in "${name}": ${warning.toValue()}`);
461
+ });
462
+ }
463
+ }
464
+ ```
465
+
466
+ ## Parsing OpenAPI Documents
467
+
468
+ The `parseOpenAPI` function provides complete control for parsing OpenAPI documents manually.
469
+ This is useful when you need to parse source descriptions independently or implement custom source description resolution logic.
470
+
471
+ The function accepts the same input types as `parseArazzo`:
472
+
473
+ 1. **Plain JavaScript object** - converts to JSON and parses
474
+ 2. **String content** - detects OpenAPI content and parses inline JSON or YAML
475
+ 3. **File system path** - resolves and parses local OpenAPI Documents
476
+ 4. **HTTP(S) URL** - fetches and parses remote OpenAPI Documents
477
+
478
+ Documents are parsed into their appropriate SpecLynx ApiDOM namespace data models:
479
+
480
+ - [OpenAPI 2.0 (Swagger)](https://spec.openapis.org/oas/v2.0) → [@speclynx/apidom-ns-openapi-2](https://github.com/speclynx/apidom/tree/main/packages/apidom-ns-openapi-2)
481
+ - [OpenAPI 3.0.x](https://spec.openapis.org/oas/v3.0.4) → [@speclynx/apidom-ns-openapi-3-0](https://github.com/speclynx/apidom/tree/main/packages/apidom-ns-openapi-3-0)
482
+ - [OpenAPI 3.1.x](https://spec.openapis.org/oas/v3.1.1) → [@speclynx/apidom-ns-openapi-3-1](https://github.com/speclynx/apidom/tree/main/packages/apidom-ns-openapi-3-1)
483
+
484
+ ```js
485
+ import { parseOpenAPI } from '@jentic/arazzo-parser';
486
+
487
+ // From object
488
+ const parseResult = await parseOpenAPI({
489
+ openapi: '3.1.0',
490
+ info: { title: 'My API', version: '1.0.0' },
491
+ paths: {},
492
+ });
493
+
494
+ // From string
495
+ const parseResult = await parseOpenAPI('{"openapi": "3.1.0", ...}');
496
+
497
+ // From file
498
+ const parseResult = await parseOpenAPI('/path/to/openapi.json');
499
+
500
+ // From URL
501
+ const parseResult = await parseOpenAPI('https://example.com/openapi.yaml');
502
+ ```
503
+
150
504
  ## SpecLynx ApiDOM tooling
151
505
 
152
506
  Since `@jentic/arazzo-parser` produces a SpecLynx ApiDOM data model, you have access to the full suite of ApiDOM tools for manipulating, traversing, and transforming the parsed document.
@@ -156,10 +510,11 @@ Since `@jentic/arazzo-parser` produces a SpecLynx ApiDOM data model, you have ac
156
510
  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:
157
511
 
158
512
  ```js
159
- import { parse } from '@jentic/arazzo-parser';
160
- import { toValue, toJSON, toYAML, clone, sexprs } from '@speclynx/apidom-core';
513
+ import { parseArazzo } from '@jentic/arazzo-parser';
514
+ import { cloneDeep, cloneShallow } from '@speclynx/apidom-datamodel';
515
+ import { toValue, toJSON, toYAML, sexprs } from '@speclynx/apidom-core';
161
516
 
162
- const parseResult = await parse(source);
517
+ const parseResult = await parseArazzo(source);
163
518
  const arazzoSpec = parseResult.api;
164
519
 
165
520
  // Convert to plain JavaScript object
@@ -171,8 +526,9 @@ const json = toJSON(arazzoSpec);
171
526
  // Serialize to YAML string
172
527
  const yaml = toYAML(arazzoSpec);
173
528
 
174
- // Deep clone the element
175
- const cloned = clone(arazzoSpec);
529
+ // Clone the element
530
+ const clonedShallow = cloneShallow(arazzoSpec);
531
+ const clonedDeep = cloneDeep(arazzoSpec);
176
532
 
177
533
  // Get S-expression representation (useful for debugging)
178
534
  const sexpr = sexprs(arazzoSpec);
@@ -183,10 +539,10 @@ const sexpr = sexprs(arazzoSpec);
183
539
  The [@speclynx/apidom-traverse](https://github.com/speclynx/apidom/tree/main/packages/apidom-traverse) package provides powerful traversal capabilities. Here is a basic example:
184
540
 
185
541
  ```js
186
- import { parse } from '@jentic/arazzo-parser';
542
+ import { parseArazzo } from '@jentic/arazzo-parser';
187
543
  import { traverse } from '@speclynx/apidom-traverse';
188
544
 
189
- const parseResult = await parse(source);
545
+ const parseResult = await parseArazzo(source);
190
546
 
191
547
  // Traverse and collect steps using semantic visitor hook
192
548
  const steps = [];