@speclynx/apidom-reference 3.0.0 → 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.
- package/CHANGELOG.md +6 -0
- package/README.md +97 -0
- package/dist/apidom-reference.browser.js +3854 -3241
- package/dist/apidom-reference.browser.min.js +1 -1
- package/package.json +25 -25
- package/src/dereference/index.cjs +4 -0
- package/src/dereference/index.mjs +4 -0
- package/src/dereference/strategies/apidom/visitor.cjs +139 -59
- package/src/dereference/strategies/apidom/visitor.mjs +142 -62
- package/src/dereference/strategies/arazzo-1/index.cjs +1 -4
- package/src/dereference/strategies/arazzo-1/index.mjs +2 -4
- package/src/dereference/strategies/arazzo-1/visitor.cjs +288 -199
- package/src/dereference/strategies/arazzo-1/visitor.mjs +291 -203
- package/src/dereference/strategies/asyncapi-2/index.cjs +1 -4
- package/src/dereference/strategies/asyncapi-2/index.mjs +2 -4
- package/src/dereference/strategies/asyncapi-2/visitor.cjs +323 -229
- package/src/dereference/strategies/asyncapi-2/visitor.mjs +326 -233
- package/src/dereference/strategies/openapi-2/index.cjs +1 -4
- package/src/dereference/strategies/openapi-2/index.mjs +2 -4
- package/src/dereference/strategies/openapi-2/visitor.cjs +417 -318
- package/src/dereference/strategies/openapi-2/visitor.mjs +422 -324
- package/src/dereference/strategies/openapi-3-0/index.cjs +1 -4
- package/src/dereference/strategies/openapi-3-0/index.mjs +2 -4
- package/src/dereference/strategies/openapi-3-0/visitor.cjs +403 -286
- package/src/dereference/strategies/openapi-3-0/visitor.mjs +407 -291
- package/src/dereference/strategies/openapi-3-1/index.cjs +1 -4
- package/src/dereference/strategies/openapi-3-1/index.mjs +2 -4
- package/src/dereference/strategies/openapi-3-1/visitor.cjs +598 -484
- package/src/dereference/strategies/openapi-3-1/visitor.mjs +602 -489
- package/src/errors/DereferenceError.cjs +1 -1
- package/src/errors/DereferenceError.mjs +2 -2
- package/src/errors/ResolveError.cjs +1 -1
- package/src/errors/ResolveError.mjs +2 -2
- package/src/errors/UnresolvableReferenceError.cjs +11 -0
- package/src/errors/UnresolvableReferenceError.mjs +6 -0
- package/src/index.cjs +3 -1
- package/src/index.mjs +1 -0
- package/src/options/index.cjs +10 -1
- package/src/options/index.mjs +10 -1
- package/src/util/plugins.cjs +1 -6
- package/src/util/plugins.mjs +2 -5
- package/types/apidom-reference.d.ts +10 -2
- package/types/dereference/strategies/apidom/visitor.d.ts +10 -0
- package/types/dereference/strategies/arazzo-1/visitor.d.ts +19 -5
- package/types/dereference/strategies/asyncapi-2/visitor.d.ts +21 -7
- package/types/dereference/strategies/openapi-2/visitor.d.ts +21 -8
- package/types/dereference/strategies/openapi-3-0/visitor.d.ts +21 -7
- package/types/dereference/strategies/openapi-3-1/visitor.d.ts +21 -7
- package/types/errors/DereferenceError.d.ts +2 -2
- package/types/errors/ResolveError.d.ts +2 -2
- package/types/errors/UnresolvableReferenceError.d.ts +7 -0
- package/types/index.d.ts +1 -0
- package/types/options/index.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
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
|
+
|
|
6
12
|
# [3.0.0](https://github.com/speclynx/apidom/compare/v2.13.1...v3.0.0) (2026-03-05)
|
|
7
13
|
|
|
8
14
|
### 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
|