@usearazzo/runner 1.0.1-alpha.28 → 1.0.1-alpha.30
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 +18 -0
- package/README.md +29 -54
- package/dist/arazzo-runner.browser.js +328 -181
- package/dist/arazzo-runner.browser.min.js +1 -1
- package/package.json +4 -4
- package/src/errors/ExecutionError.cjs +3 -1
- package/src/errors/ExecutionError.mjs +3 -1
- package/src/executor/OpenAPIOperationExecutor.cjs +92 -22
- package/src/executor/OpenAPIOperationExecutor.mjs +90 -22
- package/src/executor/OpenAPIOperationLocatorNormalizer.cjs +31 -4
- package/src/executor/OpenAPIOperationLocatorNormalizer.mjs +30 -4
- package/src/executor/StepExecutor.cjs +19 -7
- package/src/executor/StepExecutor.mjs +19 -7
- package/src/executor/WorkflowExecutor.cjs +50 -16
- package/src/executor/WorkflowExecutor.mjs +51 -17
- package/types/runner.d.ts +153 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usearazzo/runner",
|
|
3
|
-
"version": "1.0.1-alpha.
|
|
3
|
+
"version": "1.0.1-alpha.30",
|
|
4
4
|
"description": "Runner for Arazzo Workflows.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arazzo",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"@swaggerexpert/json-pointer": "^3.0.2",
|
|
74
74
|
"@swaggerexpert/jsonpath": "^4.0.5",
|
|
75
75
|
"@swaggerexpert/media-types": "^1.0.2",
|
|
76
|
-
"@usearazzo/parser": "1.0.1-alpha.
|
|
77
|
-
"@usearazzo/resolver": "1.0.1-alpha.
|
|
76
|
+
"@usearazzo/parser": "1.0.1-alpha.30",
|
|
77
|
+
"@usearazzo/resolver": "1.0.1-alpha.30",
|
|
78
78
|
"@xmldom/xmldom": "^0.9.12",
|
|
79
79
|
"fontoxpath": "^3.34.0",
|
|
80
80
|
"ramda": "^0.32.0",
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"swagger-client": "^3.39.0"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "7b79e517626548f30ae1ae3fa6c689b59ccc26fa"
|
|
98
98
|
}
|
|
@@ -17,6 +17,8 @@ var _ArazzoRunnerError = _interopRequireDefault(require("./ArazzoRunnerError.cjs
|
|
|
17
17
|
class ExecutionError extends _ArazzoRunnerError.default {
|
|
18
18
|
/** The run was cancelled through its `AbortSignal`; the signal's reason is the `cause`. */
|
|
19
19
|
static Aborted = 'aborted';
|
|
20
|
+
/** Two `executeOptions` entries name source descriptions that point at the same document. */
|
|
21
|
+
static AmbiguousExecuteOptions = 'ambiguous-execute-options';
|
|
20
22
|
/** A step or a `goto`/`retry` action declares more than one mutually exclusive target. */
|
|
21
23
|
static AmbiguousTarget = 'ambiguous-target';
|
|
22
24
|
/** The `dependsOn` edges alone form a cycle between workflows. */
|
|
@@ -51,7 +53,7 @@ class ExecutionError extends _ArazzoRunnerError.default {
|
|
|
51
53
|
static StepBudget = 'step-budget';
|
|
52
54
|
/** An action declares a `type` other than `end`, `goto` or `retry`. */
|
|
53
55
|
static UnknownActionType = 'unknown-action-type';
|
|
54
|
-
/** `execute` received an option it does not know. */
|
|
56
|
+
/** `execute` received an option it does not know, or an `executeOptions` entry that is not an object. */
|
|
55
57
|
static UnknownExecuteOption = 'unknown-execute-option';
|
|
56
58
|
/** A step produced a transition the workflow executor does not recognize. */
|
|
57
59
|
static UnknownTransitionKind = 'unknown-transition-kind';
|
|
@@ -10,6 +10,8 @@ import ArazzoRunnerError from "./ArazzoRunnerError.mjs";
|
|
|
10
10
|
class ExecutionError extends ArazzoRunnerError {
|
|
11
11
|
/** The run was cancelled through its `AbortSignal`; the signal's reason is the `cause`. */
|
|
12
12
|
static Aborted = 'aborted';
|
|
13
|
+
/** Two `executeOptions` entries name source descriptions that point at the same document. */
|
|
14
|
+
static AmbiguousExecuteOptions = 'ambiguous-execute-options';
|
|
13
15
|
/** A step or a `goto`/`retry` action declares more than one mutually exclusive target. */
|
|
14
16
|
static AmbiguousTarget = 'ambiguous-target';
|
|
15
17
|
/** The `dependsOn` edges alone form a cycle between workflows. */
|
|
@@ -44,7 +46,7 @@ class ExecutionError extends ArazzoRunnerError {
|
|
|
44
46
|
static StepBudget = 'step-budget';
|
|
45
47
|
/** An action declares a `type` other than `end`, `goto` or `retry`. */
|
|
46
48
|
static UnknownActionType = 'unknown-action-type';
|
|
47
|
-
/** `execute` received an option it does not know. */
|
|
49
|
+
/** `execute` received an option it does not know, or an `executeOptions` entry that is not an object. */
|
|
48
50
|
static UnknownExecuteOption = 'unknown-execute-option';
|
|
49
51
|
/** A step produced a transition the workflow executor does not recognize. */
|
|
50
52
|
static UnknownTransitionKind = 'unknown-transition-kind';
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
+
var _ramda = require("ramda");
|
|
8
9
|
var _apidomCore = require("@speclynx/apidom-core");
|
|
9
10
|
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
10
11
|
var _empty = require("@speclynx/apidom-reference/configuration/empty");
|
|
@@ -22,12 +23,42 @@ var _OpenAPIDocumentAssembler = _interopRequireDefault(require("../assembler/Ope
|
|
|
22
23
|
var _ClientError = _interopRequireDefault(require("../errors/ClientError.cjs"));
|
|
23
24
|
// @ts-expect-error vendored swagger-client bundle has no type declarations
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* The Arazzo step a request is issued for: its `stepId`, and the `workflowId`
|
|
28
|
+
* of the workflow it belongs to when the caller names one (step ids are only
|
|
29
|
+
* unique within a workflow).
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Identifies the request a {@link RequestInterceptor} receives, so an
|
|
35
|
+
* interceptor can target one operation or one step without matching on the
|
|
36
|
+
* expanded URL.
|
|
37
|
+
*
|
|
38
|
+
* `operation` is always present: it is the operation's locator — its canonical
|
|
39
|
+
* OpenAPI document URI, the JSON Pointer to it and, when the locator carries
|
|
40
|
+
* one, the source description it was located through — plus the `operationId`
|
|
41
|
+
* the document declares, if any. `step` is present only when the request is
|
|
42
|
+
* issued for an Arazzo step, i.e. through the step executor (and so the runner); an
|
|
43
|
+
* {@link OpenAPIOperationExecutor} used on its own receives it only when its
|
|
44
|
+
* caller passes `step` in the execute options. Absent fields are omitted, never
|
|
45
|
+
* `undefined`.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
|
|
25
49
|
/**
|
|
26
50
|
* Decorates the built request before it is handed to the {@link HTTPClient}.
|
|
27
51
|
*
|
|
28
52
|
* Receives the finalized {@link OpenAPIOperationRequest} and may mutate it in
|
|
29
53
|
* place or return a replacement; returning nothing keeps the received request.
|
|
30
|
-
* May be synchronous or asynchronous.
|
|
54
|
+
* May be synchronous or asynchronous. The second argument identifies what the
|
|
55
|
+
* request is for (see {@link RequestContext}); an interceptor that has no use
|
|
56
|
+
* for it may declare only the first.
|
|
57
|
+
*
|
|
58
|
+
* Interceptors run after the body is serialized (a plain-object or array body
|
|
59
|
+
* is already a JSON string, so a signature covers the exact bytes sent) and
|
|
60
|
+
* after newlines in header values are squashed, and before the request is
|
|
61
|
+
* captured for `$request.*` and handed to the transport.
|
|
31
62
|
* @public
|
|
32
63
|
*/
|
|
33
64
|
|
|
@@ -46,6 +77,22 @@ const UNDECLARED_LOCATIONS = new Set(['header', 'query', 'cookie', 'path']);
|
|
|
46
77
|
// the header parameters OpenAPI 3 says SHALL be ignored, which buildRequest drops
|
|
47
78
|
const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
|
|
48
79
|
|
|
80
|
+
/**
|
|
81
|
+
* The credential for one security scheme, in the form the vendored
|
|
82
|
+
* swagger-client applies it: the key or token itself (or `{ value }`) for an
|
|
83
|
+
* `apiKey` or an `http` bearer scheme, `{ username, password }` for an `http`
|
|
84
|
+
* basic scheme, and `{ token: { access_token, token_type } }` for an `oauth2`
|
|
85
|
+
* or `openIdConnect` scheme.
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Credentials for the security schemes of an OpenAPI document, keyed by the
|
|
91
|
+
* scheme name under `components.securitySchemes` (`securityDefinitions` in
|
|
92
|
+
* OpenAPI 2.0).
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
|
|
49
96
|
/**
|
|
50
97
|
* Options for executing an OpenAPI operation.
|
|
51
98
|
*
|
|
@@ -55,11 +102,14 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
|
|
|
55
102
|
* building the request and sending it.
|
|
56
103
|
*
|
|
57
104
|
* Typed here are the options the runner itself drives and the ones callers
|
|
58
|
-
* routinely reach for. The rest of `buildRequest`'s surface (`
|
|
59
|
-
* `
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
105
|
+
* routinely reach for. The rest of `buildRequest`'s surface (`scheme`,
|
|
106
|
+
* `parameterBuilders`, `attachContentTypeForEmptyPayload`, …) is deliberately
|
|
107
|
+
* left untyped and passes through the bag's open tail unchanged — see
|
|
108
|
+
* {@link OpenAPIOperationExecuteOptionsBag}.
|
|
109
|
+
*
|
|
110
|
+
* Arazzo is auth-agnostic, so credentials come from outside the workflow:
|
|
111
|
+
* static ones for the security schemes the OpenAPI document declares go in
|
|
112
|
+
* `securities`, and anything computed per request is applied with a
|
|
63
113
|
* {@link RequestInterceptor}.
|
|
64
114
|
* @public
|
|
65
115
|
*/
|
|
@@ -72,18 +122,16 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
|
|
|
72
122
|
* the rest of `buildRequest`'s surface (`scheme`, `parameterBuilders`,
|
|
73
123
|
* `attachContentTypeForEmptyPayload`, …) passes through untouched.
|
|
74
124
|
*
|
|
75
|
-
* Nothing routine belongs in the tail.
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* standing in for a document fetched over HTTP, or credentials applied from the
|
|
79
|
-
* document's own security schemes.
|
|
125
|
+
* Nothing routine belongs in the tail. `server` covers every case that once
|
|
126
|
+
* needed a `contextUrl`, so reaching for that here means an edge case: tests
|
|
127
|
+
* standing in for a document fetched over HTTP.
|
|
80
128
|
*
|
|
81
|
-
* Two kinds of entry are
|
|
129
|
+
* Two kinds of entry are dropped rather than honored, since the executor owns
|
|
82
130
|
* what they used to control. The operation target always comes from the
|
|
83
131
|
* locator, so `operationId`/`operationPath` have no effect; and the options
|
|
84
132
|
* only swagger-client's `execute()` ever read — `userFetch` and
|
|
85
133
|
* `responseInterceptor`, which the runner replaces with `httpClient` and
|
|
86
|
-
* `responseNormalizer` — reach `buildRequest
|
|
134
|
+
* `responseNormalizer` — never reach `buildRequest`.
|
|
87
135
|
* @public
|
|
88
136
|
*/
|
|
89
137
|
|
|
@@ -151,14 +199,36 @@ class OpenAPIOperationExecutor {
|
|
|
151
199
|
const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
|
|
152
200
|
const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
|
|
153
201
|
|
|
154
|
-
// the interceptor
|
|
155
|
-
// locator,
|
|
202
|
+
// the interceptor and step are consumed here, the target always comes from
|
|
203
|
+
// the locator, and the transport is the httpClient, so none of these
|
|
204
|
+
// reach buildRequest
|
|
156
205
|
const {
|
|
157
206
|
requestInterceptor,
|
|
158
|
-
|
|
159
|
-
operationPath: __,
|
|
160
|
-
...rest
|
|
207
|
+
step
|
|
161
208
|
} = executeOptions;
|
|
209
|
+
const rest = (0, _ramda.omit)(['requestInterceptor', 'step', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
|
|
210
|
+
const declaredOperationId = (0, _apidomCore.toValue)(operation.operationId);
|
|
211
|
+
const context = {
|
|
212
|
+
operation: {
|
|
213
|
+
documentURI: locator.document.uri,
|
|
214
|
+
jsonPointer: locator.jsonPointer,
|
|
215
|
+
...(typeof declaredOperationId === 'string' ? {
|
|
216
|
+
operationId: declaredOperationId
|
|
217
|
+
} : {}),
|
|
218
|
+
...(locator.sourceDescription === undefined ? {} : {
|
|
219
|
+
sourceDescription: {
|
|
220
|
+
...locator.sourceDescription
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
},
|
|
224
|
+
// a copy, so an interceptor editing it cannot rewrite the caller's object
|
|
225
|
+
// (the step executor reuses it to attribute errors)
|
|
226
|
+
...(step === undefined ? {} : {
|
|
227
|
+
step: {
|
|
228
|
+
...step
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
};
|
|
162
232
|
|
|
163
233
|
// each step derives the next options rather than editing in place
|
|
164
234
|
const withServer = this.#applyServerOptions(rest, normalizedOperation, locator.document);
|
|
@@ -189,7 +259,7 @@ class OpenAPIOperationExecutor {
|
|
|
189
259
|
request.headers['Content-Type'] = authoredContentType;
|
|
190
260
|
}
|
|
191
261
|
this.#deliverHeadersAndCookies(request, undeclared);
|
|
192
|
-
request = await this.#finalizeRequest(request, requestInterceptor);
|
|
262
|
+
request = await this.#finalizeRequest(request, requestInterceptor, context);
|
|
193
263
|
|
|
194
264
|
// capture the request as sent, so `$url` / `$method` / `$request.*` can be
|
|
195
265
|
// evaluated after execution; headers are copied so a transport-side
|
|
@@ -566,7 +636,7 @@ class OpenAPIOperationExecutor {
|
|
|
566
636
|
* `http()`, which also fetch and throw on a non-2xx. Diff against those two
|
|
567
637
|
* when bumping swagger-client.
|
|
568
638
|
*/
|
|
569
|
-
async #finalizeRequest(request, perCallInterceptor) {
|
|
639
|
+
async #finalizeRequest(request, perCallInterceptor, context) {
|
|
570
640
|
let finalized = request;
|
|
571
641
|
|
|
572
642
|
// JSON-encode plain-object and array bodies, exactly as swagger-client's
|
|
@@ -585,8 +655,8 @@ class OpenAPIOperationExecutor {
|
|
|
585
655
|
finalized.headers[headerName] = value.replace(/\n+/g, ' ');
|
|
586
656
|
}
|
|
587
657
|
});
|
|
588
|
-
finalized = (await this.#requestInterceptor?.(finalized)) ?? finalized;
|
|
589
|
-
finalized = (await perCallInterceptor?.(finalized)) ?? finalized;
|
|
658
|
+
finalized = (await this.#requestInterceptor?.(finalized, context)) ?? finalized;
|
|
659
|
+
finalized = (await perCallInterceptor?.(finalized, context)) ?? finalized;
|
|
590
660
|
|
|
591
661
|
// for multipart/form-data, remove the built content-type so the transport
|
|
592
662
|
// sets one carrying the correct boundary
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { omit } from 'ramda';
|
|
1
2
|
import { toValue } from '@speclynx/apidom-core';
|
|
2
3
|
import { isArrayElement, isObjectElement } from '@speclynx/apidom-datamodel';
|
|
3
4
|
import { url as urlUtils } from '@speclynx/apidom-reference/configuration/empty';
|
|
@@ -15,12 +16,40 @@ import OpenAPIOperationExtractor from "../extractor/OpenAPIOperationExtractor.mj
|
|
|
15
16
|
import OpenAPIOperationNormalizer from "../normalizer/OpenAPIOperationNormalizer.mjs";
|
|
16
17
|
import OpenAPIDocumentAssembler from "../assembler/OpenAPIDocumentAssembler.mjs";
|
|
17
18
|
import ClientError from "../errors/ClientError.mjs";
|
|
19
|
+
/**
|
|
20
|
+
* The Arazzo step a request is issued for: its `stepId`, and the `workflowId`
|
|
21
|
+
* of the workflow it belongs to when the caller names one (step ids are only
|
|
22
|
+
* unique within a workflow).
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Identifies the request a {@link RequestInterceptor} receives, so an
|
|
27
|
+
* interceptor can target one operation or one step without matching on the
|
|
28
|
+
* expanded URL.
|
|
29
|
+
*
|
|
30
|
+
* `operation` is always present: it is the operation's locator — its canonical
|
|
31
|
+
* OpenAPI document URI, the JSON Pointer to it and, when the locator carries
|
|
32
|
+
* one, the source description it was located through — plus the `operationId`
|
|
33
|
+
* the document declares, if any. `step` is present only when the request is
|
|
34
|
+
* issued for an Arazzo step, i.e. through the step executor (and so the runner); an
|
|
35
|
+
* {@link OpenAPIOperationExecutor} used on its own receives it only when its
|
|
36
|
+
* caller passes `step` in the execute options. Absent fields are omitted, never
|
|
37
|
+
* `undefined`.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
18
40
|
/**
|
|
19
41
|
* Decorates the built request before it is handed to the {@link HTTPClient}.
|
|
20
42
|
*
|
|
21
43
|
* Receives the finalized {@link OpenAPIOperationRequest} and may mutate it in
|
|
22
44
|
* place or return a replacement; returning nothing keeps the received request.
|
|
23
|
-
* May be synchronous or asynchronous.
|
|
45
|
+
* May be synchronous or asynchronous. The second argument identifies what the
|
|
46
|
+
* request is for (see {@link RequestContext}); an interceptor that has no use
|
|
47
|
+
* for it may declare only the first.
|
|
48
|
+
*
|
|
49
|
+
* Interceptors run after the body is serialized (a plain-object or array body
|
|
50
|
+
* is already a JSON string, so a signature covers the exact bytes sent) and
|
|
51
|
+
* after newlines in header values are squashed, and before the request is
|
|
52
|
+
* captured for `$request.*` and handed to the transport.
|
|
24
53
|
* @public
|
|
25
54
|
*/
|
|
26
55
|
/**
|
|
@@ -36,6 +65,22 @@ const UNDECLARED_LOCATIONS = new Set(['header', 'query', 'cookie', 'path']);
|
|
|
36
65
|
// the header parameters OpenAPI 3 says SHALL be ignored, which buildRequest drops
|
|
37
66
|
const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
|
|
38
67
|
|
|
68
|
+
/**
|
|
69
|
+
* The credential for one security scheme, in the form the vendored
|
|
70
|
+
* swagger-client applies it: the key or token itself (or `{ value }`) for an
|
|
71
|
+
* `apiKey` or an `http` bearer scheme, `{ username, password }` for an `http`
|
|
72
|
+
* basic scheme, and `{ token: { access_token, token_type } }` for an `oauth2`
|
|
73
|
+
* or `openIdConnect` scheme.
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Credentials for the security schemes of an OpenAPI document, keyed by the
|
|
79
|
+
* scheme name under `components.securitySchemes` (`securityDefinitions` in
|
|
80
|
+
* OpenAPI 2.0).
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
|
|
39
84
|
/**
|
|
40
85
|
* Options for executing an OpenAPI operation.
|
|
41
86
|
*
|
|
@@ -45,11 +90,14 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
|
|
|
45
90
|
* building the request and sending it.
|
|
46
91
|
*
|
|
47
92
|
* Typed here are the options the runner itself drives and the ones callers
|
|
48
|
-
* routinely reach for. The rest of `buildRequest`'s surface (`
|
|
49
|
-
* `
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
93
|
+
* routinely reach for. The rest of `buildRequest`'s surface (`scheme`,
|
|
94
|
+
* `parameterBuilders`, `attachContentTypeForEmptyPayload`, …) is deliberately
|
|
95
|
+
* left untyped and passes through the bag's open tail unchanged — see
|
|
96
|
+
* {@link OpenAPIOperationExecuteOptionsBag}.
|
|
97
|
+
*
|
|
98
|
+
* Arazzo is auth-agnostic, so credentials come from outside the workflow:
|
|
99
|
+
* static ones for the security schemes the OpenAPI document declares go in
|
|
100
|
+
* `securities`, and anything computed per request is applied with a
|
|
53
101
|
* {@link RequestInterceptor}.
|
|
54
102
|
* @public
|
|
55
103
|
*/
|
|
@@ -62,18 +110,16 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
|
|
|
62
110
|
* the rest of `buildRequest`'s surface (`scheme`, `parameterBuilders`,
|
|
63
111
|
* `attachContentTypeForEmptyPayload`, …) passes through untouched.
|
|
64
112
|
*
|
|
65
|
-
* Nothing routine belongs in the tail.
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* standing in for a document fetched over HTTP, or credentials applied from the
|
|
69
|
-
* document's own security schemes.
|
|
113
|
+
* Nothing routine belongs in the tail. `server` covers every case that once
|
|
114
|
+
* needed a `contextUrl`, so reaching for that here means an edge case: tests
|
|
115
|
+
* standing in for a document fetched over HTTP.
|
|
70
116
|
*
|
|
71
|
-
* Two kinds of entry are
|
|
117
|
+
* Two kinds of entry are dropped rather than honored, since the executor owns
|
|
72
118
|
* what they used to control. The operation target always comes from the
|
|
73
119
|
* locator, so `operationId`/`operationPath` have no effect; and the options
|
|
74
120
|
* only swagger-client's `execute()` ever read — `userFetch` and
|
|
75
121
|
* `responseInterceptor`, which the runner replaces with `httpClient` and
|
|
76
|
-
* `responseNormalizer` — reach `buildRequest
|
|
122
|
+
* `responseNormalizer` — never reach `buildRequest`.
|
|
77
123
|
* @public
|
|
78
124
|
*/
|
|
79
125
|
|
|
@@ -141,14 +187,36 @@ class OpenAPIOperationExecutor {
|
|
|
141
187
|
const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
|
|
142
188
|
const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
|
|
143
189
|
|
|
144
|
-
// the interceptor
|
|
145
|
-
// locator,
|
|
190
|
+
// the interceptor and step are consumed here, the target always comes from
|
|
191
|
+
// the locator, and the transport is the httpClient, so none of these
|
|
192
|
+
// reach buildRequest
|
|
146
193
|
const {
|
|
147
194
|
requestInterceptor,
|
|
148
|
-
|
|
149
|
-
operationPath: __,
|
|
150
|
-
...rest
|
|
195
|
+
step
|
|
151
196
|
} = executeOptions;
|
|
197
|
+
const rest = omit(['requestInterceptor', 'step', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
|
|
198
|
+
const declaredOperationId = toValue(operation.operationId);
|
|
199
|
+
const context = {
|
|
200
|
+
operation: {
|
|
201
|
+
documentURI: locator.document.uri,
|
|
202
|
+
jsonPointer: locator.jsonPointer,
|
|
203
|
+
...(typeof declaredOperationId === 'string' ? {
|
|
204
|
+
operationId: declaredOperationId
|
|
205
|
+
} : {}),
|
|
206
|
+
...(locator.sourceDescription === undefined ? {} : {
|
|
207
|
+
sourceDescription: {
|
|
208
|
+
...locator.sourceDescription
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
},
|
|
212
|
+
// a copy, so an interceptor editing it cannot rewrite the caller's object
|
|
213
|
+
// (the step executor reuses it to attribute errors)
|
|
214
|
+
...(step === undefined ? {} : {
|
|
215
|
+
step: {
|
|
216
|
+
...step
|
|
217
|
+
}
|
|
218
|
+
})
|
|
219
|
+
};
|
|
152
220
|
|
|
153
221
|
// each step derives the next options rather than editing in place
|
|
154
222
|
const withServer = this.#applyServerOptions(rest, normalizedOperation, locator.document);
|
|
@@ -179,7 +247,7 @@ class OpenAPIOperationExecutor {
|
|
|
179
247
|
request.headers['Content-Type'] = authoredContentType;
|
|
180
248
|
}
|
|
181
249
|
this.#deliverHeadersAndCookies(request, undeclared);
|
|
182
|
-
request = await this.#finalizeRequest(request, requestInterceptor);
|
|
250
|
+
request = await this.#finalizeRequest(request, requestInterceptor, context);
|
|
183
251
|
|
|
184
252
|
// capture the request as sent, so `$url` / `$method` / `$request.*` can be
|
|
185
253
|
// evaluated after execution; headers are copied so a transport-side
|
|
@@ -556,7 +624,7 @@ class OpenAPIOperationExecutor {
|
|
|
556
624
|
* `http()`, which also fetch and throw on a non-2xx. Diff against those two
|
|
557
625
|
* when bumping swagger-client.
|
|
558
626
|
*/
|
|
559
|
-
async #finalizeRequest(request, perCallInterceptor) {
|
|
627
|
+
async #finalizeRequest(request, perCallInterceptor, context) {
|
|
560
628
|
let finalized = request;
|
|
561
629
|
|
|
562
630
|
// JSON-encode plain-object and array bodies, exactly as swagger-client's
|
|
@@ -575,8 +643,8 @@ class OpenAPIOperationExecutor {
|
|
|
575
643
|
finalized.headers[headerName] = value.replace(/\n+/g, ' ');
|
|
576
644
|
}
|
|
577
645
|
});
|
|
578
|
-
finalized = (await this.#requestInterceptor?.(finalized)) ?? finalized;
|
|
579
|
-
finalized = (await perCallInterceptor?.(finalized)) ?? finalized;
|
|
646
|
+
finalized = (await this.#requestInterceptor?.(finalized, context)) ?? finalized;
|
|
647
|
+
finalized = (await perCallInterceptor?.(finalized, context)) ?? finalized;
|
|
580
648
|
|
|
581
649
|
// for multipart/form-data, remove the built content-type so the transport
|
|
582
650
|
// sets one carrying the correct boundary
|
|
@@ -25,6 +25,13 @@ var _SourceDescriptionsLocatorNormalizer = _interopRequireDefault(require("./Sou
|
|
|
25
25
|
* @public
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* A source description as an Arazzo document declares it: its `name`, and the
|
|
30
|
+
* URI of the Arazzo document that declares it. Names are local to their
|
|
31
|
+
* document, so the pair identifies one source description across a run.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
|
|
28
35
|
/**
|
|
29
36
|
* Normalizes a step's OpenAPI operation locator to a canonical
|
|
30
37
|
* {@link OpenAPIOperationLocator} — the OpenAPI document and a JSON Pointer to
|
|
@@ -89,8 +96,11 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
|
|
|
89
96
|
* locate an operation in the acquired OpenAPI document.
|
|
90
97
|
*/
|
|
91
98
|
async normalizeOperationPath(operationPath, document, scope) {
|
|
99
|
+
let sourceName;
|
|
92
100
|
for (const expression of (0, _arazzoRuntimeExpression.extract)(operationPath) ?? []) {
|
|
93
101
|
const parsed = this.parseSourceDescriptionsExpression(expression);
|
|
102
|
+
// only the source whose url the path is built from names its document
|
|
103
|
+
if (parsed?.reference === 'url') sourceName ??= parsed.sourceName;
|
|
94
104
|
if (parsed !== undefined && document.resolveSourceDescriptionURI(parsed.sourceName) === undefined) {
|
|
95
105
|
throw new _ExecutionError.default(`operationPath "${operationPath}" names source description "${parsed.sourceName}", which the Arazzo document at "${document.uri}" does not define`, {
|
|
96
106
|
...scope,
|
|
@@ -139,7 +149,13 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
|
|
|
139
149
|
}
|
|
140
150
|
return {
|
|
141
151
|
document: source,
|
|
142
|
-
jsonPointer
|
|
152
|
+
jsonPointer,
|
|
153
|
+
...(sourceName === undefined ? {} : {
|
|
154
|
+
sourceDescription: {
|
|
155
|
+
name: sourceName,
|
|
156
|
+
documentURI: document.uri
|
|
157
|
+
}
|
|
158
|
+
})
|
|
143
159
|
};
|
|
144
160
|
}
|
|
145
161
|
async #resolveSourced(expression, document, scope) {
|
|
@@ -164,7 +180,11 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
|
|
|
164
180
|
}
|
|
165
181
|
return {
|
|
166
182
|
document: openapiDocument,
|
|
167
|
-
jsonPointer
|
|
183
|
+
jsonPointer,
|
|
184
|
+
sourceDescription: {
|
|
185
|
+
name: sourceName,
|
|
186
|
+
documentURI: document.uri
|
|
187
|
+
}
|
|
168
188
|
};
|
|
169
189
|
}
|
|
170
190
|
|
|
@@ -181,7 +201,10 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
|
|
|
181
201
|
* until the first OpenAPI source is reached.
|
|
182
202
|
*/
|
|
183
203
|
async #resolvePlainOperationId(operationId, document, scope) {
|
|
184
|
-
for (const
|
|
204
|
+
for (const [name, {
|
|
205
|
+
uri
|
|
206
|
+
}] of document.sourceDescriptionIndex) {
|
|
207
|
+
if (uri === undefined) continue;
|
|
185
208
|
const source = await this.registry.acquire(uri);
|
|
186
209
|
if (!_OpenAPIDocument.default.is(source)) continue;
|
|
187
210
|
const jsonPointer = source.operationIndex.get(operationId);
|
|
@@ -193,7 +216,11 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
|
|
|
193
216
|
}
|
|
194
217
|
return {
|
|
195
218
|
document: source,
|
|
196
|
-
jsonPointer
|
|
219
|
+
jsonPointer,
|
|
220
|
+
sourceDescription: {
|
|
221
|
+
name,
|
|
222
|
+
documentURI: document.uri
|
|
223
|
+
}
|
|
197
224
|
};
|
|
198
225
|
}
|
|
199
226
|
|
|
@@ -17,6 +17,12 @@ import SourceDescriptionsLocatorNormalizer from "./SourceDescriptionsLocatorNorm
|
|
|
17
17
|
* single canonical form.
|
|
18
18
|
* @public
|
|
19
19
|
*/
|
|
20
|
+
/**
|
|
21
|
+
* A source description as an Arazzo document declares it: its `name`, and the
|
|
22
|
+
* URI of the Arazzo document that declares it. Names are local to their
|
|
23
|
+
* document, so the pair identifies one source description across a run.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
20
26
|
/**
|
|
21
27
|
* Normalizes a step's OpenAPI operation locator to a canonical
|
|
22
28
|
* {@link OpenAPIOperationLocator} — the OpenAPI document and a JSON Pointer to
|
|
@@ -81,8 +87,11 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
|
|
|
81
87
|
* locate an operation in the acquired OpenAPI document.
|
|
82
88
|
*/
|
|
83
89
|
async normalizeOperationPath(operationPath, document, scope) {
|
|
90
|
+
let sourceName;
|
|
84
91
|
for (const expression of extract(operationPath) ?? []) {
|
|
85
92
|
const parsed = this.parseSourceDescriptionsExpression(expression);
|
|
93
|
+
// only the source whose url the path is built from names its document
|
|
94
|
+
if (parsed?.reference === 'url') sourceName ??= parsed.sourceName;
|
|
86
95
|
if (parsed !== undefined && document.resolveSourceDescriptionURI(parsed.sourceName) === undefined) {
|
|
87
96
|
throw new ExecutionError(`operationPath "${operationPath}" names source description "${parsed.sourceName}", which the Arazzo document at "${document.uri}" does not define`, {
|
|
88
97
|
...scope,
|
|
@@ -131,7 +140,13 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
|
|
|
131
140
|
}
|
|
132
141
|
return {
|
|
133
142
|
document: source,
|
|
134
|
-
jsonPointer
|
|
143
|
+
jsonPointer,
|
|
144
|
+
...(sourceName === undefined ? {} : {
|
|
145
|
+
sourceDescription: {
|
|
146
|
+
name: sourceName,
|
|
147
|
+
documentURI: document.uri
|
|
148
|
+
}
|
|
149
|
+
})
|
|
135
150
|
};
|
|
136
151
|
}
|
|
137
152
|
async #resolveSourced(expression, document, scope) {
|
|
@@ -156,7 +171,11 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
|
|
|
156
171
|
}
|
|
157
172
|
return {
|
|
158
173
|
document: openapiDocument,
|
|
159
|
-
jsonPointer
|
|
174
|
+
jsonPointer,
|
|
175
|
+
sourceDescription: {
|
|
176
|
+
name: sourceName,
|
|
177
|
+
documentURI: document.uri
|
|
178
|
+
}
|
|
160
179
|
};
|
|
161
180
|
}
|
|
162
181
|
|
|
@@ -173,7 +192,10 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
|
|
|
173
192
|
* until the first OpenAPI source is reached.
|
|
174
193
|
*/
|
|
175
194
|
async #resolvePlainOperationId(operationId, document, scope) {
|
|
176
|
-
for (const
|
|
195
|
+
for (const [name, {
|
|
196
|
+
uri
|
|
197
|
+
}] of document.sourceDescriptionIndex) {
|
|
198
|
+
if (uri === undefined) continue;
|
|
177
199
|
const source = await this.registry.acquire(uri);
|
|
178
200
|
if (!OpenAPIDocument.is(source)) continue;
|
|
179
201
|
const jsonPointer = source.operationIndex.get(operationId);
|
|
@@ -185,7 +207,11 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
|
|
|
185
207
|
}
|
|
186
208
|
return {
|
|
187
209
|
document: source,
|
|
188
|
-
jsonPointer
|
|
210
|
+
jsonPointer,
|
|
211
|
+
sourceDescription: {
|
|
212
|
+
name,
|
|
213
|
+
documentURI: document.uri
|
|
214
|
+
}
|
|
189
215
|
};
|
|
190
216
|
}
|
|
191
217
|
|
|
@@ -65,6 +65,13 @@ const STEP_TARGET_FIELDS = exports.STEP_TARGET_FIELDS = ['operationId', 'operati
|
|
|
65
65
|
* @internal
|
|
66
66
|
*/
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* The execute options of a step: the opaque bag forwarded to the operation
|
|
70
|
+
* executor, or a function returning it for the operation the step was located
|
|
71
|
+
* to.
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
|
|
68
75
|
/**
|
|
69
76
|
* Executes a single Arazzo step that invokes an OpenAPI operation.
|
|
70
77
|
*
|
|
@@ -127,7 +134,9 @@ class StepExecutor {
|
|
|
127
134
|
* `executeOptions` is an opaque bag passed through to the operation executor
|
|
128
135
|
* (e.g. a `server` to run the step against, or an `AbortSignal`). The
|
|
129
136
|
* Arazzo-derived options (`operationId`, `parameters`, `requestBody`) always
|
|
130
|
-
* take precedence over it.
|
|
137
|
+
* take precedence over it. A function is called with the operation the step
|
|
138
|
+
* was located to and returns the bag, for options that depend on which API
|
|
139
|
+
* the step calls.
|
|
131
140
|
*
|
|
132
141
|
* A `signal` in that bag is honored here and not only at the transport: an
|
|
133
142
|
* already-aborted signal throws with reason `ExecutionError.Aborted` instead of issuing a
|
|
@@ -169,6 +178,7 @@ class StepExecutor {
|
|
|
169
178
|
// Pointer) locator that the operation executor extracts, normalizes,
|
|
170
179
|
// assembles into a standalone doc, and runs.
|
|
171
180
|
const locator = await this.#locateOperation(step, scope);
|
|
181
|
+
const operationOptions = typeof executeOptions === 'function' ? executeOptions(locator) : executeOptions;
|
|
172
182
|
|
|
173
183
|
// resolve parameters and request body against the pre-request context.
|
|
174
184
|
// keyed by '{in}.{name}' rather than bare name, so two parameters that
|
|
@@ -182,18 +192,20 @@ class StepExecutor {
|
|
|
182
192
|
// still reach this line — and this is the last moment before the step has a
|
|
183
193
|
// live side effect. The signal stays in the bag, so a request already in
|
|
184
194
|
// flight is aborted by the transport as before.
|
|
185
|
-
const signal = (0, _abort.readAbortSignal)(
|
|
195
|
+
const signal = (0, _abort.readAbortSignal)(operationOptions);
|
|
186
196
|
(0, _abort.throwIfAborted)(signal, scope);
|
|
187
197
|
|
|
188
|
-
// the Arazzo-derived parameters
|
|
189
|
-
// executeOptions bag so they take precedence over it. the
|
|
190
|
-
// then forces the operation target on top of this
|
|
198
|
+
// the Arazzo-derived parameters, request body and step identity are spread
|
|
199
|
+
// after the opaque executeOptions bag so they take precedence over it. the
|
|
200
|
+
// operation executor then forces the operation target on top of this
|
|
201
|
+
// before executing.
|
|
191
202
|
let response;
|
|
192
203
|
try {
|
|
193
204
|
response = await this.#operationExecutor.execute(locator, {
|
|
194
|
-
...
|
|
205
|
+
...operationOptions,
|
|
195
206
|
parameters,
|
|
196
|
-
...this.#requestBodyOptions(requestBody)
|
|
207
|
+
...this.#requestBodyOptions(requestBody),
|
|
208
|
+
step: scope
|
|
197
209
|
});
|
|
198
210
|
} catch (error) {
|
|
199
211
|
// a transport that honors the signal rejects the request it was told to
|