Skip to content

Commit f05bfec

Browse files
authored
Merge pull request #22 from JaredCE/correctly-handle-OpenAPI-parameters
Correctly handle open api parameters
2 parents 04e60e0 + b7961be commit f05bfec

39 files changed

+3083
-59
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ jq --arg password "$secret_password" '.workflowId1.password = $password' input.j
6363

6464
Obviously, if you have a lot of secret variables that need adding as inputs, then you might need to write a script that can alter the `input.json` file for you within your CI/CD runner.
6565

66+
## OpenAPI Parameters
67+
68+
OpenAPI Documents allow you to specify [`header`, `path` and `query` parameters](https://spec.openapis.org/oas/latest.html#parameter-object) in myriad of styles. This Arazzo Runner will respect your styling and send the format to the server as specified by your OpenAPI document.
69+
70+
It currently does not follow the `allowEmptyValue`, `allowReserved` or the `content` keywords currently.
71+
6672
## Logging And Reporting
6773

6874
### Logging
@@ -93,14 +99,18 @@ Work on Reporting still needs completeing.
9399

94100
## Still unsupported
95101

96-
### OpenAPI Params
102+
### PathOperation
97103

98-
OpenAPI parameter types with style and explode are not quite supported yet
104+
Accessing an OpenAPI operation by Operation Path `'{$sourceDescriptions.petstoreDescription.url}#/paths/~1pet~1findByStatus/get'` does not work currently
99105

100106
### OpenAPI Servers on various levels
101107

102108
This pulls from the top level servers object of an OpenAPI Document. Server variables do not work either.
103109

110+
### OpenAPI server variables
111+
112+
OpenAPI server variables currently do not work
113+
104114
### JSONPath and XPath criteria objects
105115

106116
Criteria Objects set as type JSON Path or XPath do not work

package-lock.json

Lines changed: 7 additions & 4 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
@@ -41,7 +41,7 @@
4141
"@swaggerexpert/json-pointer": "^2.10.2",
4242
"ajv": "^8.17.1",
4343
"jsonpath": "^1.1.1",
44-
"openapi-params": "^0.0.4",
44+
"openapi-params": "^0.0.5",
4545
"stream-chain": "^3.4.0",
4646
"stream-json": "^1.9.1"
4747
}

src/Arazzo.js

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class Arazzo extends Document {
6868
} catch (err) {
6969
if (err.name === "AbortError") {
7070
if (err.goto) {
71-
// console.log("goto error");
7271
await this.handleGotoRule(err.goto);
7372
}
7473
} else {
@@ -692,8 +691,6 @@ class Arazzo extends Document {
692691

693692
if (this.retryLimits[whatNext.name] === 0)
694693
this.retrySet.delete(whatNext.name);
695-
696-
// console.log("I need to return here after retrying");
697694
}
698695

699696
/**
@@ -738,41 +735,76 @@ class Arazzo extends Document {
738735
* @private
739736
*/
740737
mapParameters() {
741-
const headers = new Headers();
742-
const queryParams = new URLSearchParams();
743-
const pathParams = {};
738+
const headersObj = new Headers();
739+
const headers = new URLParams();
740+
const queryParams = new URLParams();
741+
const pathParams = new URLParams();
744742

745743
for (const param of this.step?.parameters || []) {
746744
const operationDetailParam =
747-
this.sourceDescription.operationDetails?.parameters
745+
this.sourceDescriptionFile.operationDetails?.parameters
748746
.filter((obj) => obj.name === param.name && obj.in === param.in)
749747
.at(0);
750748

751749
const value = this.expression.resolveExpression(param.value);
752750

753751
switch (param.in) {
754752
case "header":
755-
headers.append(param.name, value);
753+
const headerStyle = operationDetailParam?.style || "simple";
754+
const headerExplode = operationDetailParam?.explode || false;
755+
headers.append(param.name, value, {
756+
style: headerStyle,
757+
explode: headerExplode,
758+
});
759+
for (const [header, value] of headers) {
760+
if (header === param.name) {
761+
headersObj.append(param.name, value);
762+
}
763+
}
756764

757765
break;
758766

759767
case "path":
760768
for (const operation of this.operations) {
761-
operation.url = operation.url.replace(`{${param.name}}`, value);
762-
Object.assign(pathParams, { [param.name]: value });
769+
const pathStyle = operationDetailParam?.style || "simple";
770+
const pathExplode = operationDetailParam?.explode || false;
771+
pathParams.append(param.name, value, {
772+
style: pathStyle,
773+
explode: pathExplode,
774+
});
775+
for (const [name, value] of pathParams.entries()) {
776+
operation.url = operation.url.replace(`{${name}}`, value);
777+
}
778+
// operation.url = operation.url.replace(`{${param.name}}`, value);
779+
// Object.assign(pathParams, { [param.name]: value });
763780
}
764781
break;
765782

766783
case "query":
767-
queryParams.append(param.name, value);
784+
// queryParams.append(param.name, value);
785+
const style = operationDetailParam?.style || "form";
786+
let explode = false;
787+
if (Object.hasOwn(operationDetailParam, "explode")) {
788+
explode = operationDetailParam.explode;
789+
} else {
790+
if (style === "form") {
791+
explode = true;
792+
}
793+
}
794+
// const explode = operationDetailParam?.explode || false;
795+
queryParams.append(param.name, value, {
796+
style: style,
797+
explode: explode,
798+
});
768799
break;
769800
}
770801
}
771802

772-
this.expression.addToContext("request.path", pathParams);
803+
this.addParamsToContext(pathParams, "path", "request");
804+
// this.expression.addToContext("request.path", pathParams);
773805

774806
for (const operation of this.operations) {
775-
operation.headers = headers;
807+
operation.headers = headersObj;
776808
operation.queryParams = queryParams;
777809
}
778810
}

test/mocks/arazzo/openapi-parameter-tests/path/label/array-exploded.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"sourceDescriptions": [
1111
{
1212
"name": "pets-openAPI",
13-
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/parameter-styles/path/label/simple-array-exploded.json",
13+
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/parameter-styles/path/label/array-exploded.json",
1414
"type": "openapi"
1515
}
1616
],

test/mocks/arazzo/openapi-parameter-tests/path/label/array.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"sourceDescriptions": [
1111
{
1212
"name": "pets-openAPI",
13-
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/parameter-styles/path/label/simple-array-exploded.json",
13+
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/parameter-styles/path/label/array.json",
1414
"type": "openapi"
1515
}
1616
],

test/mocks/arazzo/openapi-parameter-tests/path/label/object-exploded.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"sourceDescriptions": [
1111
{
1212
"name": "pets-openAPI",
13-
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/parameter-styles/path/label/simple-array-exploded.json",
13+
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/parameter-styles/path/label/object-exploded.json",
1414
"type": "openapi"
1515
}
1616
],

test/mocks/arazzo/openapi-parameter-tests/path/label/object.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"sourceDescriptions": [
1111
{
1212
"name": "pets-openAPI",
13-
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/parameter-styles/path/label/simple-array-exploded.json",
13+
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/parameter-styles/path/label/object.json",
1414
"type": "openapi"
1515
}
1616
],

test/mocks/arazzo/openapi-parameter-tests/path/label/primitive-exploded.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"sourceDescriptions": [
1111
{
1212
"name": "pets-openAPI",
13-
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/parameter-styles/path/label/simple-array-exploded.json",
13+
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/parameter-styles/path/label/primitive-exploded.json",
1414
"type": "openapi"
1515
}
1616
],
@@ -23,7 +23,7 @@
2323
"type": "object",
2424
"properties": {
2525
"petId": {
26-
"type": "integer"
26+
"type": "string"
2727
}
2828
}
2929
},

test/mocks/arazzo/openapi-parameter-tests/path/label/primitive.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"sourceDescriptions": [
1111
{
1212
"name": "pets-openAPI",
13-
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/parameter-styles/path/label/simple-array-exploded.json",
13+
"url": "https://raw.githubusercontent.com/JaredCE/Arazzo-Runner/refs/heads/main/test/mocks/openapi/parameter-styles/path/label/primitive.json",
1414
"type": "openapi"
1515
}
1616
],
@@ -23,7 +23,7 @@
2323
"type": "object",
2424
"properties": {
2525
"petId": {
26-
"type": "integer"
26+
"type": "string"
2727
}
2828
}
2929
},

0 commit comments

Comments
 (0)