Skip to content

Commit 72e272e

Browse files
authored
Merge pull request #56 from JaredCE/dependsOn-tests
dependsOn tests
2 parents 3f7ba4f + 43c65d1 commit 72e272e

File tree

10 files changed

+697
-38
lines changed

10 files changed

+697
-38
lines changed

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,27 @@ You will need to provide inputs for your clientId and clientSecret:
210210

211211
This can handle the encoding and sending of:
212212

213-
- application/json
214-
- application/xml
215-
- text/xml
216-
- text/html
217-
- text/plain
218-
- application/x-www-form-urlencoded
219-
- multipart/form-data
220-
- application/octet-stream
213+
- application/json
214+
- application/xml
215+
- text/xml
216+
- text/html
217+
- text/plain
218+
- application/x-www-form-urlencoded
219+
- multipart/form-data
220+
- application/octet-stream
221221

222222
For anything outside of this range, it will attempt to encode as JSON if you specify an object, otherwise it will encode as plain text.
223223

224+
## Response Bodies
225+
226+
This can handle response bodies of:
227+
228+
- application/json
229+
- application/xml
230+
- text/xml
231+
- text/html
232+
- text/plain
233+
224234
## Logging And Reporting
225235

226236
### Logging
@@ -254,7 +264,3 @@ Work on Reporting still needs completeing.
254264
### PathOperation
255265

256266
Accessing an OpenAPI operation by Operation Path `'{$sourceDescriptions.petstoreDescription.url}#/paths/~1pet~1findByStatus/get'` does not work currently
257-
258-
### Non application/json Responses
259-
260-
Responses that do not conform to application/json do not work

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "arazzo-runner",
3-
"version": "0.0.22",
3+
"version": "0.0.23",
44
"description": "A runner to run through Arazzo Document workflows",
55
"main": "index.js",
66
"scripts": {
77
"test": "mocha --config './test/.mocharc.js'",
8+
"test-specific": "mocha --config './test/.mocharc.js' --grep 'runs a dependsOn workflow belonging to another arazzo document first'",
89
"test-coverage": "nyc mocha --config './test/.mocharc.js'",
910
"prepare": "husky",
1011
"start": "node cli.js"

src/Arazzo.js

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ class Arazzo extends Document {
127127
if (this.workflow.dependsOn) {
128128
await this.runDependsOnWorkflows();
129129

130-
this.workflow = workflow;
130+
const currentContext = this.executionStack.current;
131+
await this.restoreContextFromRetry(currentContext);
131132
}
132133

133134
// this.inputs = await this.inputFile.getWorkflowInputs(
@@ -204,11 +205,41 @@ class Arazzo extends Document {
204205
this.logger.notice("Running Workflows from dependsOn");
205206

206207
for await (const workflowId of this.workflow.dependsOn) {
207-
const workflowIndex = this.findWorkflowIndexByWorkflowId(workflowId);
208+
let workflowIdArr = workflowId?.split(".") || [];
209+
let workflowIndex = -1;
210+
if (workflowIdArr.length !== 1) {
211+
const actualWorkflowId = workflowIdArr.at(-1);
212+
213+
const joinedoperationOrWorkflowPointer = `${workflowIdArr[0]}.${workflowIdArr[1]}`;
214+
215+
const sourceDescription = this.expression.resolveExpression(
216+
joinedoperationOrWorkflowPointer,
217+
);
218+
219+
await this.getSourceDescriptionFile(sourceDescription);
220+
await this.sourceDescriptionFile.loadWorkflowData(this.inputFile);
221+
222+
workflowIndex = this.sourceDescriptionFile.findWorkflowIndexByWorkflowId(actualWorkflowId)
223+
224+
if (workflowIndex !== -1) {
225+
await this.sourceDescriptionFile.runWorkflow(workflowIndex);
226+
const sourceDesc = this.expression.context.sourceDescriptions[this.sourceDescriptionFile.name];
227+
if (!sourceDesc[actualWorkflowId]) {
228+
if (this.sourceDescriptionFile.expression?.context?.workflows?.[actualWorkflowId]?.outputs) {
229+
Object.assign(sourceDesc, { [actualWorkflowId]: { outputs: this.sourceDescriptionFile.expression.context.workflows[actualWorkflowId].outputs } });
230+
this.expression.context.sourceDescriptions[this.sourceDescriptionFile.name] = sourceDesc;
231+
}
232+
}
233+
}
234+
} else {
235+
workflowIndex = this.findWorkflowIndexByWorkflowId(workflowId);
208236

209-
if (workflowIndex !== -1) {
210-
await this.runWorkflow(workflowIndex);
237+
if (workflowIndex !== -1) {
238+
await this.runWorkflow(workflowIndex);
239+
}
211240
}
241+
242+
212243
}
213244

214245
this.logger.success("All Workflows from dependsOn have run");
@@ -806,25 +837,9 @@ class Arazzo extends Document {
806837
async loadOperationData() {
807838
this.sourceDescription = this.getOperationIdSourceDescription();
808839

809-
if (!this.loadedSourceDescriptions[this.sourceDescription.name]) {
810-
this.logger.notice(
811-
`Getting Source Description for: ${this.sourceDescription.name}`,
812-
);
813-
814-
this.sourceDescriptionFile = await this.docFactory.buildDocument(
815-
this.sourceDescription.type,
816-
this.sourceDescription.url,
817-
this.sourceDescription.name,
818-
{ logger: this.logger, config: this.config },
819-
);
820-
821-
Object.assign(this.loadedSourceDescriptions, {
822-
[this.sourceDescription.name]: true,
823-
});
824-
}
840+
await this.getSourceDescriptionFile(this.sourceDescription)
825841

826842
if (this.isAnOperationId) {
827-
// this.logger.notice(`Getting OperationId: ${this.step.operationId}`);
828843
let operationId = this.step.operationId;
829844

830845
operationId = operationId.split(".").at(-1);
@@ -843,6 +858,33 @@ class Arazzo extends Document {
843858
}
844859
}
845860

861+
async getSourceDescriptionFile(sourceDescription) {
862+
if (!this.loadedSourceDescriptions[sourceDescription.name]) {
863+
this.logger.notice(
864+
`Getting Source Description for: ${sourceDescription.name}`,
865+
);
866+
867+
this.sourceDescriptionFile = await this.docFactory.buildDocument(
868+
sourceDescription.type,
869+
sourceDescription.url,
870+
sourceDescription.name,
871+
{ logger: this.logger, config: this.config },
872+
);
873+
874+
Object.assign(this.loadedSourceDescriptions, {
875+
[sourceDescription.name]: { loaded: true, filePath: this.sourceDescriptionFile.filePath },
876+
877+
});
878+
} else {
879+
this.sourceDescriptionFile = await this.docFactory.buildDocument(
880+
sourceDescription.type,
881+
this.loadedSourceDescriptions[this.sourceDescription.name].filePath,
882+
sourceDescription.name,
883+
{ logger: this.logger, config: this.config },
884+
);
885+
}
886+
}
887+
846888
/**
847889
* @private
848890
* @returns

src/DocFactory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Arazzo = require("./Arazzo");
44
const OpenAPI = require("./OpenAPI");
55

66
class DocumentFactory {
7-
constructor() {}
7+
constructor() { }
88

99
/**
1010
* Tests whether a string is a URL or not
@@ -40,7 +40,7 @@ class DocumentFactory {
4040

4141
if (this.isUrl(path)) {
4242
await document.loadDocument();
43-
} else document.setMainArazzo();
43+
} else document.setFilePath();
4444

4545
return document;
4646
}

src/Document.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class Document {
2222
this.config = config;
2323
}
2424

25+
setFilePath() {
26+
this.filePath = path.resolve(this.url);
27+
}
28+
2529
async loadDocument() {
2630
let headers = new Headers();
2731
let fetchURL = new URL(this.url);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
"dependsOn": [
27+
"$sourceDescriptions.auth-arazzo.LoginUser-apiKey"
28+
],
29+
"inputs": {
30+
"type": "object",
31+
"properties": {
32+
"username": {
33+
"type": "string"
34+
},
35+
"password": {
36+
"type": "string"
37+
}
38+
}
39+
},
40+
"steps": [
41+
{
42+
"stepId": "deleteUser",
43+
"operationId": "deleteUser",
44+
"parameters": [
45+
{
46+
"name": "Authorization",
47+
"in": "header",
48+
"value": "$sourceDescriptions.auth-arazzo.LoginUser-apiKey.outputs.AccessToken"
49+
},
50+
{
51+
"name": "username",
52+
"in": "path",
53+
"value": "$inputs.username"
54+
}
55+
]
56+
}
57+
]
58+
}
59+
]
60+
}

0 commit comments

Comments
 (0)