@speclynx/apidom-reference 2.13.1 → 3.1.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +102 -5
  3. package/dist/apidom-reference.browser.js +4402 -3546
  4. package/dist/apidom-reference.browser.min.js +1 -1
  5. package/package.json +25 -25
  6. package/src/dereference/index.cjs +4 -0
  7. package/src/dereference/index.mjs +4 -0
  8. package/src/dereference/strategies/apidom/selectors/element-id.cjs +11 -2
  9. package/src/dereference/strategies/apidom/selectors/element-id.mjs +12 -3
  10. package/src/dereference/strategies/apidom/visitor.cjs +139 -59
  11. package/src/dereference/strategies/apidom/visitor.mjs +142 -62
  12. package/src/dereference/strategies/arazzo-1/index.cjs +1 -4
  13. package/src/dereference/strategies/arazzo-1/index.mjs +2 -4
  14. package/src/dereference/strategies/arazzo-1/source-descriptions.cjs +2 -2
  15. package/src/dereference/strategies/arazzo-1/source-descriptions.mjs +3 -3
  16. package/src/dereference/strategies/arazzo-1/visitor.cjs +288 -199
  17. package/src/dereference/strategies/arazzo-1/visitor.mjs +291 -203
  18. package/src/dereference/strategies/asyncapi-2/index.cjs +1 -4
  19. package/src/dereference/strategies/asyncapi-2/index.mjs +2 -4
  20. package/src/dereference/strategies/asyncapi-2/visitor.cjs +326 -232
  21. package/src/dereference/strategies/asyncapi-2/visitor.mjs +327 -234
  22. package/src/dereference/strategies/openapi-2/index.cjs +1 -4
  23. package/src/dereference/strategies/openapi-2/index.mjs +2 -4
  24. package/src/dereference/strategies/openapi-2/visitor.cjs +423 -324
  25. package/src/dereference/strategies/openapi-2/visitor.mjs +428 -330
  26. package/src/dereference/strategies/openapi-3-0/index.cjs +1 -4
  27. package/src/dereference/strategies/openapi-3-0/index.mjs +2 -4
  28. package/src/dereference/strategies/openapi-3-0/visitor.cjs +406 -289
  29. package/src/dereference/strategies/openapi-3-0/visitor.mjs +410 -294
  30. package/src/dereference/strategies/openapi-3-1/index.cjs +1 -4
  31. package/src/dereference/strategies/openapi-3-1/index.mjs +2 -4
  32. package/src/dereference/strategies/openapi-3-1/util.cjs +2 -2
  33. package/src/dereference/strategies/openapi-3-1/util.mjs +2 -2
  34. package/src/dereference/strategies/openapi-3-1/visitor.cjs +601 -487
  35. package/src/dereference/strategies/openapi-3-1/visitor.mjs +605 -492
  36. package/src/errors/DereferenceError.cjs +1 -1
  37. package/src/errors/DereferenceError.mjs +2 -2
  38. package/src/errors/ResolveError.cjs +1 -1
  39. package/src/errors/ResolveError.mjs +2 -2
  40. package/src/errors/UnresolvableReferenceError.cjs +11 -0
  41. package/src/errors/UnresolvableReferenceError.mjs +6 -0
  42. package/src/index.cjs +3 -1
  43. package/src/index.mjs +1 -0
  44. package/src/options/index.cjs +10 -1
  45. package/src/options/index.mjs +10 -1
  46. package/src/parse/parsers/arazzo-json-1/source-descriptions.cjs +2 -2
  47. package/src/parse/parsers/arazzo-json-1/source-descriptions.mjs +3 -3
  48. package/src/util/plugins.cjs +1 -6
  49. package/src/util/plugins.mjs +2 -5
  50. package/types/apidom-reference.d.ts +10 -2
  51. package/types/dereference/strategies/apidom/visitor.d.ts +10 -0
  52. package/types/dereference/strategies/arazzo-1/visitor.d.ts +19 -5
  53. package/types/dereference/strategies/asyncapi-2/visitor.d.ts +21 -7
  54. package/types/dereference/strategies/openapi-2/visitor.d.ts +21 -8
  55. package/types/dereference/strategies/openapi-3-0/visitor.d.ts +21 -7
  56. package/types/dereference/strategies/openapi-3-1/visitor.d.ts +21 -7
  57. package/types/errors/DereferenceError.d.ts +2 -2
  58. package/types/errors/ResolveError.d.ts +2 -2
  59. package/types/errors/UnresolvableReferenceError.d.ts +7 -0
  60. package/types/index.d.ts +1 -0
  61. package/types/options/index.d.ts +2 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
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
+ # [3.1.0](https://github.com/speclynx/apidom/compare/v3.0.0...v3.1.0) (2026-03-08)
7
+
8
+ ### Features
9
+
10
+ - **reference:** introduce continueOnError option for dereferencing ([#140](https://github.com/speclynx/apidom/issues/140)) ([a4b21fe](https://github.com/speclynx/apidom/commit/a4b21fe1ea7b6330d0f05c8bbbd713a0579b5115))
11
+
12
+ # [3.0.0](https://github.com/speclynx/apidom/compare/v2.13.1...v3.0.0) (2026-03-05)
13
+
14
+ ### Features
15
+
16
+ - introduce new memory efficient meta data management ([#129](https://github.com/speclynx/apidom/issues/129)) ([82ae0d7](https://github.com/speclynx/apidom/commit/82ae0d7cc2e9ee7037c3d9681817add2ca18dc92))
17
+
18
+ ### BREAKING CHANGES
19
+
20
+ - meta data use to be elements before, now they are simple primitives
21
+
6
22
  ## [2.13.1](https://github.com/speclynx/apidom/compare/v2.13.0...v2.13.1) (2026-02-28)
7
23
 
8
24
  ### Bug Fixes
package/README.md CHANGED
@@ -346,9 +346,9 @@ const parseResultFiltered = await parse('/path/to/arazzo.json', {
346
346
  // Access parsed source descriptions
347
347
  for (const element of parseResult) {
348
348
  if (element.classes.includes('source-description')) {
349
- console.log(toValue(element.meta.get('name'))); // e.g., 'petStore'
350
- console.log(toValue(element.meta.get('type'))); // e.g., 'openapi'
351
- console.log(toValue(element.meta.get('retrievalURI'))); // e.g., '/path/to/petstore.json'
349
+ console.log(element.meta.get('name')); // e.g., 'petStore'
350
+ console.log(element.meta.get('type')); // e.g., 'openapi'
351
+ console.log(element.meta.get('retrievalURI')); // e.g., '/path/to/petstore.json'
352
352
  }
353
353
  }
354
354
  ```
@@ -380,7 +380,7 @@ if (parsedDoc.errors.length > 0) {
380
380
  console.log('Parsing failed:', parsedDoc.errors);
381
381
  } else {
382
382
  console.log(parsedDoc.api.element); // e.g., 'openApi3_1'
383
- console.log(toValue(parsedDoc.meta.get('retrievalURI'))); // URI where it was fetched from
383
+ console.log(parsedDoc.meta.get('retrievalURI')); // URI where it was fetched from
384
384
  }
385
385
  ```
386
386
 
@@ -1889,7 +1889,7 @@ if (dereferencedDoc.errors.length > 0) {
1889
1889
  console.log('Dereferencing failed:', dereferencedDoc.errors);
1890
1890
  } else {
1891
1891
  console.log(dereferencedDoc.api.element); // e.g., 'openApi3_1'
1892
- console.log(toValue(dereferencedDoc.meta.get('retrievalURI'))); // URI where it was fetched from
1892
+ console.log(dereferencedDoc.meta.get('retrievalURI')); // URI where it was fetched from
1893
1893
  }
1894
1894
  ```
1895
1895
 
@@ -2099,6 +2099,103 @@ await dereference('https://raw.githubusercontent.com/OAI/OpenAPI-Specification/m
2099
2099
  });
2100
2100
  ```
2101
2101
 
2102
+ ##### Continue on error
2103
+
2104
+ By default, dereferencing fails fast on the first unresolvable reference. The `continueOnError` option
2105
+ allows dereferencing to continue past broken references, collecting errors instead of throwing.
2106
+
2107
+ **Type:** `false | true | ((error: UnresolvableReferenceError) => void)`
2108
+
2109
+ **Default:** `false`
2110
+
2111
+ | Value | Behavior |
2112
+ |---|---|
2113
+ | `false` | Fail fast — throws `UnresolvableReferenceError` on first broken reference |
2114
+ | `true` | Skip unresolvable references silently |
2115
+ | callback | Called for each unresolvable reference with structured error context |
2116
+
2117
+ **Collecting errors with a callback:**
2118
+
2119
+ ```js
2120
+ import { dereference, UnresolvableReferenceError } from '@speclynx/apidom-reference';
2121
+
2122
+ const errors = [];
2123
+
2124
+ await dereference('/home/user/oas.json', {
2125
+ parse: { mediaType: 'application/openapi+json;version=3.1.2' },
2126
+ dereference: {
2127
+ continueOnError: (error) => {
2128
+ errors.push(error);
2129
+ },
2130
+ },
2131
+ });
2132
+
2133
+ // errors is an array of UnresolvableReferenceError instances
2134
+ ```
2135
+
2136
+ Each `UnresolvableReferenceError` (extends `DereferenceError`) carries structured context:
2137
+
2138
+ | Property | Type | Description |
2139
+ |---|---|---|
2140
+ | `message` | `string` | Contextual description (e.g., "Error while dereferencing Reference Object. Cannot resolve $ref ...") |
2141
+ | `type` | `string` | Element type that failed (e.g., `"reference"`, `"pathItem"`, `"schema"`, `"link"`, `"example"`) |
2142
+ | `uri` | `string` | Document URI where the error occurred |
2143
+ | `location` | `string` | JSON Pointer to the element within the document |
2144
+ | `codeFrame` | `string` | YAML snippet of the referencing element |
2145
+ | `refFieldName` | `string` | Reference field name (e.g., `"$ref"`, `"operationRef"`, `"externalValue"`) |
2146
+ | `refFieldValue` | `string` | Reference field value |
2147
+ | `trace` | `Array` | Chain of reference hops from entry document to the failure |
2148
+ | `cause` | `Error` | The underlying error |
2149
+
2150
+ Each entry in the `trace` array has the shape `{ uri, type, refFieldName, refFieldValue, location, codeFrame }`,
2151
+ representing one hop in the reference chain that led to the failure. The trace is ordered from outermost (entry document)
2152
+ to innermost (closest to the failing reference). For direct failures in the entry document, the trace is empty.
2153
+
2154
+ **Example output for a 3-hop chain** (`root.yaml → inventory.yaml → items.yaml → missing.yaml`):
2155
+
2156
+ ```
2157
+ error.uri = "items.yaml"
2158
+ error.location = "/ItemList/items"
2159
+ error.refFieldValue = "./missing.yaml#/Item"
2160
+ error.trace = [
2161
+ { uri: "root.yaml", location: "/paths/~1inventory/get/.../schema", refFieldValue: "./inventory.yaml#/InventorySchema" },
2162
+ { uri: "inventory.yaml", location: "/InventorySchema/properties/items", refFieldValue: "./items.yaml#/ItemList" },
2163
+ ]
2164
+ ```
2165
+
2166
+ If the callback **throws**, dereferencing stops immediately. This can be used to abort after a threshold:
2167
+
2168
+ ```js
2169
+ await dereference('/home/user/oas.json', {
2170
+ parse: { mediaType: 'application/openapi+json;version=3.1.2' },
2171
+ dereference: {
2172
+ continueOnError: (error) => {
2173
+ errors.push(error);
2174
+ if (errors.length >= 10) throw new Error('Too many errors');
2175
+ },
2176
+ },
2177
+ });
2178
+ ```
2179
+
2180
+ The structured error context enables rich, user-friendly error reporting with full traceability:
2181
+
2182
+ ```
2183
+ [1] schemas/items.yaml at #/ItemList/items ← where the broken $ref is (file + JSON Pointer)
2184
+
2185
+ Error while reading file "schemas/no-such-item.yaml" ← what went wrong (the cause)
2186
+
2187
+ | $ref: ./no-such-item.yaml#/Item ← code frame of the failing element
2188
+
2189
+ referenced from root.yaml at #/paths/.../schema ← trace: the entry document entry point
2190
+ | $ref: ./schemas/inventory.yaml#/InventorySchema ← code frame of the root reference
2191
+ referenced from schemas/inventory.yaml at #/.../properties/items ← trace: intermediate hop
2192
+ | $ref: ./items.yaml#/ItemList ← code frame of the intermediate reference
2193
+ ```
2194
+
2195
+ Reading top to bottom: the `$ref` at `/ItemList/items` in `schemas/items.yaml` cannot resolve `no-such-item.yaml`.
2196
+ We arrived there via: `root.yaml` referenced `inventory.yaml#/InventorySchema`, which referenced `items.yaml#/ItemList`,
2197
+ which contains the broken `$ref`.
2198
+
2102
2199
  ##### Creating new dereference strategy
2103
2200
 
2104
2201
  Dereference component can be extended by additional strategies. Every strategy is an object that