Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,27 @@ You will need to provide inputs for your clientId and clientSecret:

This can handle the encoding and sending of:

- application/json
- application/xml
- text/xml
- text/html
- text/plain
- application/x-www-form-urlencoded
- multipart/form-data
- application/octet-stream
- application/json
- application/xml
- text/xml
- text/html
- text/plain
- application/x-www-form-urlencoded
- multipart/form-data
- application/octet-stream

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.

## Response Bodies

This can handle response bodies of:

- application/json
- application/xml
- text/xml
- text/html
- text/plain

## Logging And Reporting

### Logging
Expand Down Expand Up @@ -254,7 +264,3 @@ Work on Reporting still needs completeing.
### PathOperation

Accessing an OpenAPI operation by Operation Path `'{$sourceDescriptions.petstoreDescription.url}#/paths/~1pet~1findByStatus/get'` does not work currently

### Non application/json Responses

Responses that do not conform to application/json do not work
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "arazzo-runner",
"version": "0.0.22",
"version": "0.0.23",
"description": "A runner to run through Arazzo Document workflows",
"main": "index.js",
"scripts": {
"test": "mocha --config './test/.mocharc.js'",
"test-specific": "mocha --config './test/.mocharc.js' --grep 'runs a dependsOn workflow belonging to another arazzo document first'",
"test-coverage": "nyc mocha --config './test/.mocharc.js'",
"prepare": "husky",
"start": "node cli.js"
Expand Down
84 changes: 63 additions & 21 deletions src/Arazzo.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class Arazzo extends Document {
if (this.workflow.dependsOn) {
await this.runDependsOnWorkflows();

this.workflow = workflow;
const currentContext = this.executionStack.current;
await this.restoreContextFromRetry(currentContext);
}

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

for await (const workflowId of this.workflow.dependsOn) {
const workflowIndex = this.findWorkflowIndexByWorkflowId(workflowId);
let workflowIdArr = workflowId?.split(".") || [];
let workflowIndex = -1;
if (workflowIdArr.length !== 1) {
const actualWorkflowId = workflowIdArr.at(-1);

const joinedoperationOrWorkflowPointer = `${workflowIdArr[0]}.${workflowIdArr[1]}`;

const sourceDescription = this.expression.resolveExpression(
joinedoperationOrWorkflowPointer,
);

await this.getSourceDescriptionFile(sourceDescription);
await this.sourceDescriptionFile.loadWorkflowData(this.inputFile);

workflowIndex = this.sourceDescriptionFile.findWorkflowIndexByWorkflowId(actualWorkflowId)

if (workflowIndex !== -1) {
await this.sourceDescriptionFile.runWorkflow(workflowIndex);
const sourceDesc = this.expression.context.sourceDescriptions[this.sourceDescriptionFile.name];
if (!sourceDesc[actualWorkflowId]) {
if (this.sourceDescriptionFile.expression?.context?.workflows?.[actualWorkflowId]?.outputs) {
Object.assign(sourceDesc, { [actualWorkflowId]: { outputs: this.sourceDescriptionFile.expression.context.workflows[actualWorkflowId].outputs } });
this.expression.context.sourceDescriptions[this.sourceDescriptionFile.name] = sourceDesc;
}
}
}
} else {
workflowIndex = this.findWorkflowIndexByWorkflowId(workflowId);

if (workflowIndex !== -1) {
await this.runWorkflow(workflowIndex);
if (workflowIndex !== -1) {
await this.runWorkflow(workflowIndex);
}
}


}

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

if (!this.loadedSourceDescriptions[this.sourceDescription.name]) {
this.logger.notice(
`Getting Source Description for: ${this.sourceDescription.name}`,
);

this.sourceDescriptionFile = await this.docFactory.buildDocument(
this.sourceDescription.type,
this.sourceDescription.url,
this.sourceDescription.name,
{ logger: this.logger, config: this.config },
);

Object.assign(this.loadedSourceDescriptions, {
[this.sourceDescription.name]: true,
});
}
await this.getSourceDescriptionFile(this.sourceDescription)

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

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

async getSourceDescriptionFile(sourceDescription) {
if (!this.loadedSourceDescriptions[sourceDescription.name]) {
this.logger.notice(
`Getting Source Description for: ${sourceDescription.name}`,
);

this.sourceDescriptionFile = await this.docFactory.buildDocument(
sourceDescription.type,
sourceDescription.url,
sourceDescription.name,
{ logger: this.logger, config: this.config },
);

Object.assign(this.loadedSourceDescriptions, {
[sourceDescription.name]: { loaded: true, filePath: this.sourceDescriptionFile.filePath },

});
} else {
this.sourceDescriptionFile = await this.docFactory.buildDocument(
sourceDescription.type,
this.loadedSourceDescriptions[this.sourceDescription.name].filePath,
sourceDescription.name,
{ logger: this.logger, config: this.config },
);
}
}

/**
* @private
* @returns
Expand Down
4 changes: 2 additions & 2 deletions src/DocFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Arazzo = require("./Arazzo");
const OpenAPI = require("./OpenAPI");

class DocumentFactory {
constructor() {}
constructor() { }

/**
* Tests whether a string is a URL or not
Expand Down Expand Up @@ -40,7 +40,7 @@ class DocumentFactory {

if (this.isUrl(path)) {
await document.loadDocument();
} else document.setMainArazzo();
} else document.setFilePath();

return document;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Document {
this.config = config;
}

setFilePath() {
this.filePath = path.resolve(this.url);
}

async loadDocument() {
let headers = new Headers();
let fetchURL = new URL(this.url);
Expand Down
60 changes: 60 additions & 0 deletions test/mocks/arazzo/arazzo-dependsOn/external-workflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"arazzo": "1.0.1",
"info": {
"title": "users",
"description": "The Arazzo Workflow for a Pet Store User",
"summary": "Araazo Workflow for Pet Store User",
"version": "1.0.0"
},
"sourceDescriptions": [
{
"name": "users-openAPI",
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/microservices/user.json",
"type": "openapi"
},
{
"name": "auth-arazzo",
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/arazzo/arazzo-outputs/between-workflows.json",
"type": "arazzo"
}
],
"workflows": [
{
"workflowId": "LoginUser-apiKey",
"summary": "Logs a user in",
"description": "Logs the user in and then deletes them",
"dependsOn": [
"$sourceDescriptions.auth-arazzo.LoginUser-apiKey"
],
"inputs": {
"type": "object",
"properties": {
"username": {
"type": "string"
},
"password": {
"type": "string"
}
}
},
"steps": [
{
"stepId": "deleteUser",
"operationId": "deleteUser",
"parameters": [
{
"name": "Authorization",
"in": "header",
"value": "$sourceDescriptions.auth-arazzo.LoginUser-apiKey.outputs.AccessToken"
},
{
"name": "username",
"in": "path",
"value": "$inputs.username"
}
]
}
]
}
]
}
Loading