Skip to content

Commit 2a3d856

Browse files
authored
Merge pull request #48 from JaredCE/test-outputs
Test outputs
2 parents d886ce0 + eb545e3 commit 2a3d856

File tree

8 files changed

+584
-14
lines changed

8 files changed

+584
-14
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arazzo-runner",
3-
"version": "0.0.17",
3+
"version": "0.0.18",
44
"description": "A runner to run through Arazzo Document workflows",
55
"main": "index.js",
66
"scripts": {

src/Arazzo.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,34 @@ class Arazzo extends Document {
230230

231231
if (this.openAPISteps) {
232232
await this.runOpenAPIStep();
233+
} else if (this.isAWorkflowId) {
234+
this.currentStepIndex = this.stepIndex;
235+
this.currentWorkflow = this.workflow;
236+
if (this.isExternalWorkflow) {
237+
await this.sourceDescriptionFile.runWorkflowById(this.step.workflowId)
238+
const sourceDesc = this.expression.context.sourceDescriptions[this.sourceDescriptionFile.name];
239+
if (!sourceDesc[this.step.workflowId]) {
240+
if (this.sourceDescriptionFile.expression?.context?.workflows?.[this.step.workflowId]?.outputs) {
241+
Object.assign(sourceDesc, { [this.step.workflowId]: { outputs: this.sourceDescriptionFile.expression.context.workflows[this.step.workflowId].outputs } });
242+
this.expression.context.sourceDescriptions[this.sourceDescriptionFile.name] = sourceDesc;
243+
}
244+
}
245+
} else {
246+
await this.runWorkflowById(this.step.workflowId);
247+
}
248+
this.stepIndex = this.currentStepIndex;
249+
this.workflow = this.currentWorkflow;
233250
}
234251

235252
this.isAnOperationId = false;
236253
this.isAWorkflowId = false;
254+
this.isExternalWorkflow = false;
237255
this.isAnOperationPath = false;
238256
this.openAPISteps = false;
239257

240258
this.logger.success(`Step ${step.stepId} completed`);
241259
return { noMoreSteps: false };
242260
} else {
243-
// this.logger.notice(`All steps in ${this.workflow.workflowId} have run`);
244-
245261
return { noMoreSteps: true };
246262
}
247263
}
@@ -653,11 +669,13 @@ class Arazzo extends Document {
653669
} else {
654670
let workflowIdArr = this.step?.workflowId?.split(".") || [];
655671

656-
if (workflowIdArr.length === 1) {
657-
await this.runWorkflowById(workflowIdArr.at(0));
658-
} else {
672+
if (workflowIdArr.length !== 1) {
673+
this.step.workflowId = workflowIdArr.at(-1)
674+
this.isExternalWorkflow = true;
675+
// await this.runWorkflowById(workflowIdArr.at(0));
676+
// } else {
659677
await this.sourceDescriptionFile.loadWorkflowData(this.inputFile);
660-
await this.sourceDescriptionFile.runWorkflowById(workflowIdArr.at(-1));
678+
// await this.sourceDescriptionFile.runWorkflowById(workflowIdArr.at(-1));
661679
}
662680
}
663681
}
@@ -673,6 +691,15 @@ class Arazzo extends Document {
673691
if (this.sourceDescriptions.length === 1) {
674692
return this.sourceDescriptions[0];
675693
} else {
694+
if (this.isAnOperationId) {
695+
const multipleOpenAPISourceDescriptions = this.sourceDescriptions.filter(obj => obj.type === 'openapi');
696+
if (multipleOpenAPISourceDescriptions.length > 1) {
697+
698+
} else {
699+
return multipleOpenAPISourceDescriptions[0]
700+
}
701+
}
702+
676703
const operationOrWorkflowPointerArr =
677704
operationOrWorkflowPointer.split(".");
678705

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"arazzo": "1.0.1",
3+
"info": {
4+
"title": "users",
5+
"description": "The Arazzo Workflow for a Pet Store User",
6+
"summary": "Araazo Workflow for Pet Store User",
7+
"version": "1.0.0"
8+
},
9+
"sourceDescriptions": [
10+
{
11+
"name": "users-openAPI",
12+
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/microservices/user.json",
13+
"type": "openapi"
14+
},
15+
{
16+
"name": "auth-arazzo",
17+
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/arazzo/arazzo-outputs/between-workflows.json",
18+
"type": "arazzo"
19+
}
20+
],
21+
"workflows": [
22+
{
23+
"workflowId": "LoginUser-apiKey",
24+
"summary": "Logs a user in",
25+
"description": "Logs the user in and then deletes them",
26+
"inputs": {
27+
"type": "object",
28+
"properties": {
29+
"username": {
30+
"type": "string"
31+
},
32+
"password": {
33+
"type": "string"
34+
}
35+
}
36+
},
37+
"steps": [
38+
{
39+
"stepId": "LoginExistingUser",
40+
"workflowId": "$sourceDescriptions.auth-arazzo.LoginUser-apiKey"
41+
},
42+
{
43+
"stepId": "deleteUser",
44+
"operationId": "deleteUser",
45+
"parameters": [
46+
{
47+
"name": "Authorization",
48+
"in": "header",
49+
"value": "$sourceDescriptions.auth-arazzo.LoginUser-apiKey.outputs.AccessToken"
50+
},
51+
{
52+
"name": "username",
53+
"in": "path",
54+
"value": "$inputs.username"
55+
}
56+
]
57+
}
58+
]
59+
}
60+
]
61+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"arazzo": "1.0.1",
3+
"info": {
4+
"title": "users",
5+
"description": "The Arazzo Workflow for a Pet Store User",
6+
"summary": "Araazo Workflow for Pet Store User",
7+
"version": "1.0.0"
8+
},
9+
"sourceDescriptions": [
10+
{
11+
"name": "users-openAPI",
12+
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/security/api-key/users-openapi.json",
13+
"type": "openapi"
14+
}
15+
],
16+
"workflows": [
17+
{
18+
"workflowId": "deleteCurrentUser-apiKey",
19+
"summary": "Deletes the current user",
20+
"description": "Logs the user in and then deletes them",
21+
"inputs": {
22+
"type": "object",
23+
"properties": {
24+
"username": {
25+
"type": "string"
26+
},
27+
"password": {
28+
"type": "string"
29+
}
30+
}
31+
},
32+
"steps": [
33+
{
34+
"stepId": "LoginExistingUser",
35+
"operationId": "loginUser",
36+
"requestBody": {
37+
"contentType": "application/json",
38+
"payload": {
39+
"username": "$inputs.username",
40+
"password": "$inputs.password"
41+
}
42+
},
43+
"outputs": {
44+
"AccessToken": "$response.body#/AccessToken"
45+
}
46+
},
47+
{
48+
"stepId": "deleteUser",
49+
"operationId": "deleteUser",
50+
"parameters": [
51+
{
52+
"name": "Authorization",
53+
"in": "header",
54+
"value": "$steps.LoginExistingUser.outputs.AccessToken"
55+
},
56+
{
57+
"name": "username",
58+
"in": "path",
59+
"value": "$inputs.username"
60+
}
61+
]
62+
}
63+
]
64+
}
65+
]
66+
}

test/mocks/arazzo/arazzo-outputs/between-workflows.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@
5454
"summary": "Deletes the current User",
5555
"description": "Deletes a current user",
5656
"inputs": {
57-
"username": {
58-
"type": "string"
59-
},
60-
"password": {
61-
"type": "string"
57+
"type": "object",
58+
"properties": {
59+
"username": {
60+
"type": "string"
61+
},
62+
"password": {
63+
"type": "string"
64+
}
6265
}
6366
},
6467
"steps": [
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"deleteCurrentUser-apiKey": {
3+
"username": "DannyB",
4+
"password": "P4ssW0rd"
5+
},
6+
"LoginUser-apiKey": {
7+
"username": "DannyB",
8+
"password": "P4ssW0rd"
9+
},
10+
"deleteCurrentUser": {
11+
"username": "DannyB",
12+
"password": "P4ssW0rd"
13+
}
14+
}

0 commit comments

Comments
 (0)