@jentic/arazzo-resolver 1.0.0-alpha.3 → 1.0.0-alpha.31
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 +157 -0
- package/NOTICE +8 -0
- package/README.md +496 -1
- package/dist/jentic-arazzo-resolver.browser.js +69363 -64800
- package/dist/jentic-arazzo-resolver.browser.min.js +1 -1
- package/package.json +16 -8
- package/src/{dereference.cjs → dereference/arazzo.cjs} +73 -44
- package/src/{dereference.mjs → dereference/arazzo.mjs} +78 -49
- package/src/dereference/openapi.cjs +224 -0
- package/src/dereference/openapi.mjs +216 -0
- package/src/index.cjs +9 -8
- package/src/index.mjs +2 -1
- package/types/arazzo-resolver.d.ts +134 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jentic/arazzo-resolver",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.31",
|
|
4
4
|
"description": "Resolver for Arazzo Documents.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arazzo",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public",
|
|
16
16
|
"registry": "https://registry.npmjs.org",
|
|
17
|
+
"provenance": true,
|
|
17
18
|
"tag": "latest"
|
|
18
19
|
},
|
|
19
20
|
"type": "module",
|
|
@@ -48,12 +49,18 @@
|
|
|
48
49
|
"license": "Apache-2.0",
|
|
49
50
|
"dependencies": {
|
|
50
51
|
"@babel/runtime-corejs3": "^7.28.4",
|
|
51
|
-
"@
|
|
52
|
-
"@speclynx/apidom-datamodel": "
|
|
53
|
-
"@speclynx/apidom-error": "
|
|
54
|
-
"@speclynx/apidom-ns-arazzo-1": "
|
|
55
|
-
"@speclynx/apidom-
|
|
56
|
-
"
|
|
52
|
+
"@jentic/arazzo-parser": "1.0.0-alpha.31",
|
|
53
|
+
"@speclynx/apidom-datamodel": "^4.10.0",
|
|
54
|
+
"@speclynx/apidom-error": "^4.10.0",
|
|
55
|
+
"@speclynx/apidom-ns-arazzo-1": "^4.10.0",
|
|
56
|
+
"@speclynx/apidom-ns-openapi-2": "^4.10.0",
|
|
57
|
+
"@speclynx/apidom-ns-openapi-3-0": "^4.10.0",
|
|
58
|
+
"@speclynx/apidom-ns-openapi-3-1": "^4.10.0",
|
|
59
|
+
"@speclynx/apidom-reference": "^4.10.0",
|
|
60
|
+
"type-fest": "^5.4.4"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@speclynx/apidom-core": "^4.10.0"
|
|
57
64
|
},
|
|
58
65
|
"files": [
|
|
59
66
|
"src/**/*.mjs",
|
|
@@ -64,5 +71,6 @@
|
|
|
64
71
|
"NOTICE",
|
|
65
72
|
"README.md",
|
|
66
73
|
"CHANGELOG.md"
|
|
67
|
-
]
|
|
74
|
+
],
|
|
75
|
+
"gitHead": "3e2d87af578cfe79c329894f3f28ee59f03c1606"
|
|
68
76
|
}
|
|
@@ -11,16 +11,12 @@ var _arazzo = _interopRequireDefault(require("@speclynx/apidom-reference/derefer
|
|
|
11
11
|
var _openapi = _interopRequireDefault(require("@speclynx/apidom-reference/dereference/strategies/openapi-2"));
|
|
12
12
|
var _openapi2 = _interopRequireDefault(require("@speclynx/apidom-reference/dereference/strategies/openapi-3-0"));
|
|
13
13
|
var _openapi3 = _interopRequireDefault(require("@speclynx/apidom-reference/dereference/strategies/openapi-3-1"));
|
|
14
|
-
var _arazzoJson = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/arazzo-json-1"));
|
|
15
|
-
var _arazzoYaml = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/arazzo-yaml-1"));
|
|
16
14
|
var _json = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/json"));
|
|
17
15
|
var _yaml = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/yaml-1-2"));
|
|
18
16
|
var _binary = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/binary"));
|
|
19
|
-
var _file = _interopRequireDefault(require("@speclynx/apidom-reference/resolve/resolvers/file"));
|
|
20
|
-
var _httpAxios = _interopRequireDefault(require("@speclynx/apidom-reference/resolve/resolvers/http-axios"));
|
|
21
17
|
var _apidomNsArazzo = require("@speclynx/apidom-ns-arazzo-1");
|
|
22
|
-
var
|
|
23
|
-
var _DereferenceError = _interopRequireDefault(require("
|
|
18
|
+
var _arazzoParser = require("@jentic/arazzo-parser");
|
|
19
|
+
var _DereferenceError = _interopRequireDefault(require("../errors/DereferenceError.cjs"));
|
|
24
20
|
/**
|
|
25
21
|
* Options for dereferencing Arazzo Documents.
|
|
26
22
|
* @public
|
|
@@ -32,67 +28,75 @@ var _DereferenceError = _interopRequireDefault(require("./errors/DereferenceErro
|
|
|
32
28
|
*/
|
|
33
29
|
const defaultOptions = exports.defaultOptions = {
|
|
34
30
|
resolve: {
|
|
35
|
-
resolvers: [
|
|
36
|
-
fileAllowList: ['*.json', '*.yaml', '*.yml']
|
|
37
|
-
}), new _httpAxios.default({
|
|
38
|
-
timeout: 5000,
|
|
39
|
-
redirects: 5,
|
|
40
|
-
withCredentials: false
|
|
41
|
-
})]
|
|
31
|
+
resolvers: [..._arazzoParser.defaultParseArazzoOptions.resolve.resolvers]
|
|
42
32
|
},
|
|
43
33
|
parse: {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
allowEmpty: false,
|
|
47
|
-
sourceMap: false
|
|
48
|
-
}), new _arazzoYaml.default({
|
|
49
|
-
allowEmpty: false,
|
|
50
|
-
sourceMap: false
|
|
51
|
-
}), new _json.default({
|
|
52
|
-
allowEmpty: false,
|
|
53
|
-
sourceMap: false
|
|
34
|
+
parsers: [..._arazzoParser.defaultParseArazzoOptions.parse.parsers, new _json.default({
|
|
35
|
+
allowEmpty: false
|
|
54
36
|
}), new _yaml.default({
|
|
55
|
-
allowEmpty: false
|
|
56
|
-
sourceMap: false
|
|
37
|
+
allowEmpty: false
|
|
57
38
|
}), new _binary.default({
|
|
58
|
-
allowEmpty: false
|
|
59
|
-
|
|
60
|
-
|
|
39
|
+
allowEmpty: false
|
|
40
|
+
})],
|
|
41
|
+
parserOpts: {
|
|
42
|
+
..._arazzoParser.defaultParseArazzoOptions.parse.parserOpts
|
|
43
|
+
}
|
|
61
44
|
},
|
|
62
45
|
dereference: {
|
|
63
46
|
strategies: [new _arazzo.default(), new _openapi.default(), new _openapi2.default(), new _openapi3.default()],
|
|
64
|
-
strategyOpts: {
|
|
47
|
+
strategyOpts: {
|
|
48
|
+
sourceDescriptions: false
|
|
49
|
+
}
|
|
65
50
|
}
|
|
66
51
|
};
|
|
67
52
|
|
|
68
53
|
/**
|
|
69
54
|
* Dereferences an Arazzo Document from a file system path or HTTP(S) URL.
|
|
70
55
|
*
|
|
71
|
-
* This function resolves all JSON References ($ref)
|
|
72
|
-
*
|
|
56
|
+
* This function resolves all JSON References ($ref) and Reusable Object references
|
|
57
|
+
* ($components.*) in the Arazzo Document.
|
|
58
|
+
*
|
|
59
|
+
* Source descriptions can optionally be dereferenced using strategy options:
|
|
60
|
+
* - `sourceDescriptions`: `true` (all) or `['name1', 'name2']` (specific names only)
|
|
61
|
+
* - `sourceDescriptionsMaxDepth`: Maximum recursion depth for nested Arazzo source descriptions (default: `+Infinity`)
|
|
62
|
+
*
|
|
63
|
+
* Options can be passed globally via `strategyOpts` or strategy-specific via `strategyOpts['arazzo-1']`.
|
|
73
64
|
*
|
|
74
65
|
* @param uri - A file system path or HTTP(S) URL to the Arazzo Document
|
|
75
66
|
* @param options - Reference options (uses defaultOptions when not provided)
|
|
76
67
|
* @returns A promise that resolves to the dereferenced Arazzo Document as ApiDOM element
|
|
77
|
-
* @throws DereferenceError - When dereferencing fails
|
|
68
|
+
* @throws DereferenceError - When dereferencing fails or document is not an Arazzo specification. The original error is available via the `cause` property.
|
|
78
69
|
*
|
|
79
70
|
* @example
|
|
80
71
|
* // Dereference from file
|
|
81
|
-
* const result = await
|
|
72
|
+
* const result = await dereferenceArazzo('/path/to/arazzo.json');
|
|
82
73
|
*
|
|
83
74
|
* @example
|
|
84
75
|
* // Dereference from URL
|
|
85
|
-
* const result = await
|
|
76
|
+
* const result = await dereferenceArazzo('https://example.com/arazzo.yaml');
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* Dereference with source descriptions
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const result = await dereferenceArazzo('/path/to/arazzo.json', {
|
|
82
|
+
* dereference: { strategyOpts: { sourceDescriptions: true } },
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
86
85
|
*
|
|
87
86
|
* @example
|
|
88
87
|
* // Dereference with custom options
|
|
89
|
-
* const result = await
|
|
88
|
+
* const result = await dereferenceArazzo('/path/to/arazzo.json', customReferenceOptions);
|
|
90
89
|
* @public
|
|
91
90
|
*/
|
|
92
91
|
async function dereference(uri, options = {}) {
|
|
93
92
|
const mergedOptions = (0, _empty.mergeOptions)(defaultOptions, options);
|
|
94
93
|
try {
|
|
95
94
|
const parseResult = await (0, _empty.dereference)(uri, mergedOptions);
|
|
95
|
+
|
|
96
|
+
// validate that the dereferenced document is an Arazzo specification
|
|
97
|
+
if (!(0, _apidomNsArazzo.isArazzoSpecification1Element)(parseResult.api)) {
|
|
98
|
+
throw new _empty.UnmatchedDereferenceStrategyError(`Could not find a dereference strategy that can dereference "${uri}" as an Arazzo specification`);
|
|
99
|
+
}
|
|
96
100
|
parseResult.meta.set('retrievalURI', uri);
|
|
97
101
|
return parseResult;
|
|
98
102
|
} catch (error) {
|
|
@@ -115,6 +119,12 @@ async function dereference(uri, options = {}) {
|
|
|
115
119
|
* requires `options.dereference.strategyOpts.parseResult` for component resolution,
|
|
116
120
|
* and `options.resolve.baseURI` if parseResult lacks retrievalURI metadata
|
|
117
121
|
*
|
|
122
|
+
* Source descriptions can optionally be dereferenced using strategy options:
|
|
123
|
+
* - `sourceDescriptions`: `true` (all) or `['name1', 'name2']` (specific names only)
|
|
124
|
+
* - `sourceDescriptionsMaxDepth`: Maximum recursion depth for nested Arazzo source descriptions (default: `+Infinity`)
|
|
125
|
+
*
|
|
126
|
+
* Options can be passed globally via `strategyOpts` or strategy-specific via `strategyOpts['arazzo-1']`.
|
|
127
|
+
*
|
|
118
128
|
* @param element - An ApiDOM element (ParseResultElement or child element like WorkflowElement)
|
|
119
129
|
* @param options - Reference options (uses defaultOptions when not provided)
|
|
120
130
|
* @returns A promise that resolves to the dereferenced element
|
|
@@ -123,17 +133,17 @@ async function dereference(uri, options = {}) {
|
|
|
123
133
|
* @example
|
|
124
134
|
* Dereference ParseResultElement with retrievalURI (from file parsing)
|
|
125
135
|
* ```typescript
|
|
126
|
-
* import {
|
|
136
|
+
* import { parseArazzo } from '@jentic/arazzo-parser';
|
|
127
137
|
*
|
|
128
|
-
* const parseResult = await
|
|
129
|
-
* const dereferenced = await
|
|
138
|
+
* const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
139
|
+
* const dereferenced = await dereferenceArazzoElement(parseResult);
|
|
130
140
|
* ```
|
|
131
141
|
*
|
|
132
142
|
* @example
|
|
133
143
|
* Dereference ParseResultElement without retrievalURI (from inline parsing)
|
|
134
144
|
* ```typescript
|
|
135
|
-
* const parseResult = await
|
|
136
|
-
* const dereferenced = await
|
|
145
|
+
* const parseResult = await parseArazzo({ arazzo: '1.0.1', ... });
|
|
146
|
+
* const dereferenced = await dereferenceArazzoElement(parseResult, {
|
|
137
147
|
* resolve: { baseURI: 'https://example.com/arazzo.json' },
|
|
138
148
|
* });
|
|
139
149
|
* ```
|
|
@@ -141,22 +151,35 @@ async function dereference(uri, options = {}) {
|
|
|
141
151
|
* @example
|
|
142
152
|
* Dereference child element (e.g., WorkflowElement)
|
|
143
153
|
* ```typescript
|
|
144
|
-
* const parseResult = await
|
|
154
|
+
* const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
145
155
|
* const workflow = parseResult.api.workflows.get(0);
|
|
146
|
-
* const dereferenced = await
|
|
156
|
+
* const dereferenced = await dereferenceArazzoElement(workflow, {
|
|
147
157
|
* dereference: { strategyOpts: { parseResult } },
|
|
148
158
|
* });
|
|
149
159
|
* ```
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* Dereference with source descriptions
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
165
|
+
* const dereferenced = await dereferenceArazzoElement(parseResult, {
|
|
166
|
+
* dereference: { strategyOpts: { sourceDescriptions: true } },
|
|
167
|
+
* });
|
|
168
|
+
* ```
|
|
150
169
|
* @public
|
|
151
170
|
*/
|
|
152
171
|
async function dereferenceElement(element, options = {}) {
|
|
153
172
|
const mergedOptions = (0, _empty.mergeOptions)(defaultOptions, options);
|
|
154
173
|
const refSet = mergedOptions.dereference?.refSet ?? new _empty.ReferenceSet();
|
|
155
174
|
let baseURI = mergedOptions.resolve?.baseURI;
|
|
175
|
+
let mediaType = 'text/plain';
|
|
156
176
|
if (refSet.size === 0) {
|
|
157
177
|
if ((0, _apidomDatamodel.isParseResultElement)(element)) {
|
|
178
|
+
if ((0, _apidomNsArazzo.isArazzoSpecification1Element)(element.api)) {
|
|
179
|
+
mediaType = _apidomNsArazzo.mediaTypes.latest();
|
|
180
|
+
}
|
|
158
181
|
if (element.hasMetaProperty('retrievalURI')) {
|
|
159
|
-
baseURI =
|
|
182
|
+
baseURI = element.meta.get('retrievalURI');
|
|
160
183
|
} else if (!baseURI) {
|
|
161
184
|
throw new _DereferenceError.default('baseURI option is required when dereferencing a ParseResultElement without retrievalURI metadata');
|
|
162
185
|
}
|
|
@@ -166,8 +189,11 @@ async function dereferenceElement(element, options = {}) {
|
|
|
166
189
|
parseResult
|
|
167
190
|
} = mergedOptions.dereference.strategyOpts;
|
|
168
191
|
let rootURI;
|
|
192
|
+
if ((0, _apidomNsArazzo.isArazzoSpecification1Element)(parseResult.api)) {
|
|
193
|
+
mediaType = _apidomNsArazzo.mediaTypes.latest();
|
|
194
|
+
}
|
|
169
195
|
if (parseResult.hasMetaProperty('retrievalURI')) {
|
|
170
|
-
rootURI =
|
|
196
|
+
rootURI = parseResult.meta.get('retrievalURI');
|
|
171
197
|
} else if (baseURI) {
|
|
172
198
|
rootURI = baseURI;
|
|
173
199
|
} else {
|
|
@@ -190,6 +216,9 @@ async function dereferenceElement(element, options = {}) {
|
|
|
190
216
|
resolve: {
|
|
191
217
|
baseURI
|
|
192
218
|
},
|
|
219
|
+
parse: {
|
|
220
|
+
mediaType
|
|
221
|
+
},
|
|
193
222
|
dereference: {
|
|
194
223
|
refSet
|
|
195
224
|
}
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { isParseResultElement, ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
2
|
-
import { dereference as dereferenceURI, dereferenceApiDOM as dereferenceApiDOMElement, mergeOptions, ReferenceSet, Reference } from '@speclynx/apidom-reference/configuration/empty';
|
|
2
|
+
import { dereference as dereferenceURI, dereferenceApiDOM as dereferenceApiDOMElement, mergeOptions, ReferenceSet, Reference, UnmatchedDereferenceStrategyError } from '@speclynx/apidom-reference/configuration/empty';
|
|
3
3
|
import Arazzo1DereferenceStrategy from '@speclynx/apidom-reference/dereference/strategies/arazzo-1';
|
|
4
4
|
import OpenAPI2DereferenceStrategy from '@speclynx/apidom-reference/dereference/strategies/openapi-2';
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import ArazzoJSON1Parser from '@speclynx/apidom-reference/parse/parsers/arazzo-json-1';
|
|
8
|
-
import ArazzoYAML1Parser from '@speclynx/apidom-reference/parse/parsers/arazzo-yaml-1';
|
|
5
|
+
import OpenAPI30DereferenceStrategy from '@speclynx/apidom-reference/dereference/strategies/openapi-3-0';
|
|
6
|
+
import OpenAPI31DereferenceStrategy from '@speclynx/apidom-reference/dereference/strategies/openapi-3-1';
|
|
9
7
|
import JSONParser from '@speclynx/apidom-reference/parse/parsers/json';
|
|
10
8
|
import YAMLParser from '@speclynx/apidom-reference/parse/parsers/yaml-1-2';
|
|
11
9
|
import BinaryParser from '@speclynx/apidom-reference/parse/parsers/binary';
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import { toValue } from '@speclynx/apidom-core';
|
|
16
|
-
import DereferenceError from "./errors/DereferenceError.mjs";
|
|
10
|
+
import { isArazzoSpecification1Element, mediaTypes } from '@speclynx/apidom-ns-arazzo-1';
|
|
11
|
+
import { defaultParseArazzoOptions as parserDefaultOptions } from '@jentic/arazzo-parser';
|
|
12
|
+
import DereferenceError from "../errors/DereferenceError.mjs";
|
|
17
13
|
/**
|
|
18
14
|
* Options for dereferencing Arazzo Documents.
|
|
19
15
|
* @public
|
|
@@ -24,67 +20,75 @@ import DereferenceError from "./errors/DereferenceError.mjs";
|
|
|
24
20
|
*/
|
|
25
21
|
export const defaultOptions = {
|
|
26
22
|
resolve: {
|
|
27
|
-
resolvers: [
|
|
28
|
-
fileAllowList: ['*.json', '*.yaml', '*.yml']
|
|
29
|
-
}), new HTTPResolverAxios({
|
|
30
|
-
timeout: 5000,
|
|
31
|
-
redirects: 5,
|
|
32
|
-
withCredentials: false
|
|
33
|
-
})]
|
|
23
|
+
resolvers: [...parserDefaultOptions.resolve.resolvers]
|
|
34
24
|
},
|
|
35
25
|
parse: {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
allowEmpty: false,
|
|
39
|
-
sourceMap: false
|
|
40
|
-
}), new ArazzoYAML1Parser({
|
|
41
|
-
allowEmpty: false,
|
|
42
|
-
sourceMap: false
|
|
43
|
-
}), new JSONParser({
|
|
44
|
-
allowEmpty: false,
|
|
45
|
-
sourceMap: false
|
|
26
|
+
parsers: [...parserDefaultOptions.parse.parsers, new JSONParser({
|
|
27
|
+
allowEmpty: false
|
|
46
28
|
}), new YAMLParser({
|
|
47
|
-
allowEmpty: false
|
|
48
|
-
sourceMap: false
|
|
29
|
+
allowEmpty: false
|
|
49
30
|
}), new BinaryParser({
|
|
50
|
-
allowEmpty: false
|
|
51
|
-
|
|
52
|
-
|
|
31
|
+
allowEmpty: false
|
|
32
|
+
})],
|
|
33
|
+
parserOpts: {
|
|
34
|
+
...parserDefaultOptions.parse.parserOpts
|
|
35
|
+
}
|
|
53
36
|
},
|
|
54
37
|
dereference: {
|
|
55
|
-
strategies: [new Arazzo1DereferenceStrategy(), new OpenAPI2DereferenceStrategy(), new
|
|
56
|
-
strategyOpts: {
|
|
38
|
+
strategies: [new Arazzo1DereferenceStrategy(), new OpenAPI2DereferenceStrategy(), new OpenAPI30DereferenceStrategy(), new OpenAPI31DereferenceStrategy()],
|
|
39
|
+
strategyOpts: {
|
|
40
|
+
sourceDescriptions: false
|
|
41
|
+
}
|
|
57
42
|
}
|
|
58
43
|
};
|
|
59
44
|
|
|
60
45
|
/**
|
|
61
46
|
* Dereferences an Arazzo Document from a file system path or HTTP(S) URL.
|
|
62
47
|
*
|
|
63
|
-
* This function resolves all JSON References ($ref)
|
|
64
|
-
*
|
|
48
|
+
* This function resolves all JSON References ($ref) and Reusable Object references
|
|
49
|
+
* ($components.*) in the Arazzo Document.
|
|
50
|
+
*
|
|
51
|
+
* Source descriptions can optionally be dereferenced using strategy options:
|
|
52
|
+
* - `sourceDescriptions`: `true` (all) or `['name1', 'name2']` (specific names only)
|
|
53
|
+
* - `sourceDescriptionsMaxDepth`: Maximum recursion depth for nested Arazzo source descriptions (default: `+Infinity`)
|
|
54
|
+
*
|
|
55
|
+
* Options can be passed globally via `strategyOpts` or strategy-specific via `strategyOpts['arazzo-1']`.
|
|
65
56
|
*
|
|
66
57
|
* @param uri - A file system path or HTTP(S) URL to the Arazzo Document
|
|
67
58
|
* @param options - Reference options (uses defaultOptions when not provided)
|
|
68
59
|
* @returns A promise that resolves to the dereferenced Arazzo Document as ApiDOM element
|
|
69
|
-
* @throws DereferenceError - When dereferencing fails
|
|
60
|
+
* @throws DereferenceError - When dereferencing fails or document is not an Arazzo specification. The original error is available via the `cause` property.
|
|
70
61
|
*
|
|
71
62
|
* @example
|
|
72
63
|
* // Dereference from file
|
|
73
|
-
* const result = await
|
|
64
|
+
* const result = await dereferenceArazzo('/path/to/arazzo.json');
|
|
74
65
|
*
|
|
75
66
|
* @example
|
|
76
67
|
* // Dereference from URL
|
|
77
|
-
* const result = await
|
|
68
|
+
* const result = await dereferenceArazzo('https://example.com/arazzo.yaml');
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* Dereference with source descriptions
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const result = await dereferenceArazzo('/path/to/arazzo.json', {
|
|
74
|
+
* dereference: { strategyOpts: { sourceDescriptions: true } },
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
78
77
|
*
|
|
79
78
|
* @example
|
|
80
79
|
* // Dereference with custom options
|
|
81
|
-
* const result = await
|
|
80
|
+
* const result = await dereferenceArazzo('/path/to/arazzo.json', customReferenceOptions);
|
|
82
81
|
* @public
|
|
83
82
|
*/
|
|
84
83
|
export async function dereference(uri, options = {}) {
|
|
85
84
|
const mergedOptions = mergeOptions(defaultOptions, options);
|
|
86
85
|
try {
|
|
87
86
|
const parseResult = await dereferenceURI(uri, mergedOptions);
|
|
87
|
+
|
|
88
|
+
// validate that the dereferenced document is an Arazzo specification
|
|
89
|
+
if (!isArazzoSpecification1Element(parseResult.api)) {
|
|
90
|
+
throw new UnmatchedDereferenceStrategyError(`Could not find a dereference strategy that can dereference "${uri}" as an Arazzo specification`);
|
|
91
|
+
}
|
|
88
92
|
parseResult.meta.set('retrievalURI', uri);
|
|
89
93
|
return parseResult;
|
|
90
94
|
} catch (error) {
|
|
@@ -107,6 +111,12 @@ export async function dereference(uri, options = {}) {
|
|
|
107
111
|
* requires `options.dereference.strategyOpts.parseResult` for component resolution,
|
|
108
112
|
* and `options.resolve.baseURI` if parseResult lacks retrievalURI metadata
|
|
109
113
|
*
|
|
114
|
+
* Source descriptions can optionally be dereferenced using strategy options:
|
|
115
|
+
* - `sourceDescriptions`: `true` (all) or `['name1', 'name2']` (specific names only)
|
|
116
|
+
* - `sourceDescriptionsMaxDepth`: Maximum recursion depth for nested Arazzo source descriptions (default: `+Infinity`)
|
|
117
|
+
*
|
|
118
|
+
* Options can be passed globally via `strategyOpts` or strategy-specific via `strategyOpts['arazzo-1']`.
|
|
119
|
+
*
|
|
110
120
|
* @param element - An ApiDOM element (ParseResultElement or child element like WorkflowElement)
|
|
111
121
|
* @param options - Reference options (uses defaultOptions when not provided)
|
|
112
122
|
* @returns A promise that resolves to the dereferenced element
|
|
@@ -115,17 +125,17 @@ export async function dereference(uri, options = {}) {
|
|
|
115
125
|
* @example
|
|
116
126
|
* Dereference ParseResultElement with retrievalURI (from file parsing)
|
|
117
127
|
* ```typescript
|
|
118
|
-
* import {
|
|
128
|
+
* import { parseArazzo } from '@jentic/arazzo-parser';
|
|
119
129
|
*
|
|
120
|
-
* const parseResult = await
|
|
121
|
-
* const dereferenced = await
|
|
130
|
+
* const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
131
|
+
* const dereferenced = await dereferenceArazzoElement(parseResult);
|
|
122
132
|
* ```
|
|
123
133
|
*
|
|
124
134
|
* @example
|
|
125
135
|
* Dereference ParseResultElement without retrievalURI (from inline parsing)
|
|
126
136
|
* ```typescript
|
|
127
|
-
* const parseResult = await
|
|
128
|
-
* const dereferenced = await
|
|
137
|
+
* const parseResult = await parseArazzo({ arazzo: '1.0.1', ... });
|
|
138
|
+
* const dereferenced = await dereferenceArazzoElement(parseResult, {
|
|
129
139
|
* resolve: { baseURI: 'https://example.com/arazzo.json' },
|
|
130
140
|
* });
|
|
131
141
|
* ```
|
|
@@ -133,22 +143,35 @@ export async function dereference(uri, options = {}) {
|
|
|
133
143
|
* @example
|
|
134
144
|
* Dereference child element (e.g., WorkflowElement)
|
|
135
145
|
* ```typescript
|
|
136
|
-
* const parseResult = await
|
|
146
|
+
* const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
137
147
|
* const workflow = parseResult.api.workflows.get(0);
|
|
138
|
-
* const dereferenced = await
|
|
148
|
+
* const dereferenced = await dereferenceArazzoElement(workflow, {
|
|
139
149
|
* dereference: { strategyOpts: { parseResult } },
|
|
140
150
|
* });
|
|
141
151
|
* ```
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* Dereference with source descriptions
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const parseResult = await parseArazzo('/path/to/arazzo.json');
|
|
157
|
+
* const dereferenced = await dereferenceArazzoElement(parseResult, {
|
|
158
|
+
* dereference: { strategyOpts: { sourceDescriptions: true } },
|
|
159
|
+
* });
|
|
160
|
+
* ```
|
|
142
161
|
* @public
|
|
143
162
|
*/
|
|
144
163
|
export async function dereferenceElement(element, options = {}) {
|
|
145
164
|
const mergedOptions = mergeOptions(defaultOptions, options);
|
|
146
165
|
const refSet = mergedOptions.dereference?.refSet ?? new ReferenceSet();
|
|
147
166
|
let baseURI = mergedOptions.resolve?.baseURI;
|
|
167
|
+
let mediaType = 'text/plain';
|
|
148
168
|
if (refSet.size === 0) {
|
|
149
169
|
if (isParseResultElement(element)) {
|
|
170
|
+
if (isArazzoSpecification1Element(element.api)) {
|
|
171
|
+
mediaType = mediaTypes.latest();
|
|
172
|
+
}
|
|
150
173
|
if (element.hasMetaProperty('retrievalURI')) {
|
|
151
|
-
baseURI =
|
|
174
|
+
baseURI = element.meta.get('retrievalURI');
|
|
152
175
|
} else if (!baseURI) {
|
|
153
176
|
throw new DereferenceError('baseURI option is required when dereferencing a ParseResultElement without retrievalURI metadata');
|
|
154
177
|
}
|
|
@@ -158,8 +181,11 @@ export async function dereferenceElement(element, options = {}) {
|
|
|
158
181
|
parseResult
|
|
159
182
|
} = mergedOptions.dereference.strategyOpts;
|
|
160
183
|
let rootURI;
|
|
184
|
+
if (isArazzoSpecification1Element(parseResult.api)) {
|
|
185
|
+
mediaType = mediaTypes.latest();
|
|
186
|
+
}
|
|
161
187
|
if (parseResult.hasMetaProperty('retrievalURI')) {
|
|
162
|
-
rootURI =
|
|
188
|
+
rootURI = parseResult.meta.get('retrievalURI');
|
|
163
189
|
} else if (baseURI) {
|
|
164
190
|
rootURI = baseURI;
|
|
165
191
|
} else {
|
|
@@ -182,6 +208,9 @@ export async function dereferenceElement(element, options = {}) {
|
|
|
182
208
|
resolve: {
|
|
183
209
|
baseURI
|
|
184
210
|
},
|
|
211
|
+
parse: {
|
|
212
|
+
mediaType
|
|
213
|
+
},
|
|
185
214
|
dereference: {
|
|
186
215
|
refSet
|
|
187
216
|
}
|