@speclynx/apidom-reference 3.0.0 → 3.2.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 (53) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +97 -0
  3. package/dist/apidom-reference.browser.js +3862 -3241
  4. package/dist/apidom-reference.browser.min.js +1 -1
  5. package/package.json +48 -25
  6. package/src/dereference/index.cjs +4 -0
  7. package/src/dereference/index.mjs +4 -0
  8. package/src/dereference/strategies/apidom/visitor.cjs +139 -59
  9. package/src/dereference/strategies/apidom/visitor.mjs +142 -62
  10. package/src/dereference/strategies/arazzo-1/index.cjs +1 -4
  11. package/src/dereference/strategies/arazzo-1/index.mjs +2 -4
  12. package/src/dereference/strategies/arazzo-1/visitor.cjs +289 -199
  13. package/src/dereference/strategies/arazzo-1/visitor.mjs +292 -203
  14. package/src/dereference/strategies/asyncapi-2/index.cjs +1 -4
  15. package/src/dereference/strategies/asyncapi-2/index.mjs +2 -4
  16. package/src/dereference/strategies/asyncapi-2/visitor.cjs +325 -229
  17. package/src/dereference/strategies/asyncapi-2/visitor.mjs +328 -233
  18. package/src/dereference/strategies/openapi-2/index.cjs +1 -4
  19. package/src/dereference/strategies/openapi-2/index.mjs +2 -4
  20. package/src/dereference/strategies/openapi-2/visitor.cjs +420 -318
  21. package/src/dereference/strategies/openapi-2/visitor.mjs +425 -324
  22. package/src/dereference/strategies/openapi-3-0/index.cjs +1 -4
  23. package/src/dereference/strategies/openapi-3-0/index.mjs +2 -4
  24. package/src/dereference/strategies/openapi-3-0/visitor.cjs +405 -286
  25. package/src/dereference/strategies/openapi-3-0/visitor.mjs +409 -291
  26. package/src/dereference/strategies/openapi-3-1/index.cjs +1 -4
  27. package/src/dereference/strategies/openapi-3-1/index.mjs +2 -4
  28. package/src/dereference/strategies/openapi-3-1/visitor.cjs +598 -484
  29. package/src/dereference/strategies/openapi-3-1/visitor.mjs +602 -489
  30. package/src/errors/DereferenceError.cjs +1 -1
  31. package/src/errors/DereferenceError.mjs +2 -2
  32. package/src/errors/ResolveError.cjs +1 -1
  33. package/src/errors/ResolveError.mjs +2 -2
  34. package/src/errors/UnresolvableReferenceError.cjs +11 -0
  35. package/src/errors/UnresolvableReferenceError.mjs +6 -0
  36. package/src/index.cjs +3 -1
  37. package/src/index.mjs +1 -0
  38. package/src/options/index.cjs +10 -1
  39. package/src/options/index.mjs +10 -1
  40. package/src/util/plugins.cjs +1 -6
  41. package/src/util/plugins.mjs +2 -5
  42. package/types/apidom-reference.d.ts +10 -2
  43. package/types/dereference/strategies/apidom/visitor.d.ts +10 -0
  44. package/types/dereference/strategies/arazzo-1/visitor.d.ts +19 -5
  45. package/types/dereference/strategies/asyncapi-2/visitor.d.ts +21 -7
  46. package/types/dereference/strategies/openapi-2/visitor.d.ts +21 -8
  47. package/types/dereference/strategies/openapi-3-0/visitor.d.ts +21 -7
  48. package/types/dereference/strategies/openapi-3-1/visitor.d.ts +21 -7
  49. package/types/errors/DereferenceError.d.ts +2 -2
  50. package/types/errors/ResolveError.d.ts +2 -2
  51. package/types/errors/UnresolvableReferenceError.d.ts +7 -0
  52. package/types/index.d.ts +1 -0
  53. 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.2.0](https://github.com/speclynx/apidom/compare/v3.1.0...v3.2.0) (2026-03-08)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **referece:** fix indirection leak in dereference strategies ([#141](https://github.com/speclynx/apidom/issues/141)) ([57ec415](https://github.com/speclynx/apidom/commit/57ec4153baade728681e43223d058ef35b707212))
11
+
12
+ ### Features
13
+
14
+ - add keywords to all package.json files for npm search discoverability ([#142](https://github.com/speclynx/apidom/issues/142)) ([f6c2b38](https://github.com/speclynx/apidom/commit/f6c2b387db48427f0f12e3019e1bdb8d7e05dd00))
15
+
16
+ # [3.1.0](https://github.com/speclynx/apidom/compare/v3.0.0...v3.1.0) (2026-03-08)
17
+
18
+ ### Features
19
+
20
+ - **reference:** introduce continueOnError option for dereferencing ([#140](https://github.com/speclynx/apidom/issues/140)) ([a4b21fe](https://github.com/speclynx/apidom/commit/a4b21fe1ea7b6330d0f05c8bbbd713a0579b5115))
21
+
6
22
  # [3.0.0](https://github.com/speclynx/apidom/compare/v2.13.1...v3.0.0) (2026-03-05)
7
23
 
8
24
  ### Features
package/README.md CHANGED
@@ -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