Skip to content

Commit 3095a93

Browse files
committed
Fixed body and header argument number for ApiClient generated with openapi-generator-6.1.0
1 parent 785475f commit 3095a93

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

lib/mcapi/mcapi-service.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ function Service(service, config) {
3535
function (original, outObj) {
3636
return function () {
3737
const endpoint = arguments[0];
38-
const header = arguments[5];
39-
const body = arguments[7];
38+
const header = arguments[arguments.length - 9];
39+
const body = arguments[arguments.length - 7];
4040
const cb = arguments[arguments.length - 1];
4141
if (body) {
4242
const encrypted = outObj.encryption.encrypt(endpoint, header, body);
43-
arguments[5] = encrypted.header;
44-
arguments[7] = encrypted.body;
43+
arguments[arguments.length - 9] = encrypted.header;
44+
arguments[arguments.length - 7] = encrypted.body;
4545
}
4646
arguments[arguments.length - 1] = function (error, data, response) {
4747
if (response && response.body) {

test/mcapi-service.test.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe("MC API Service", () => {
1919
}, /service should be a valid OpenAPI client./);
2020
});
2121

22-
it("callApi intercepted", function (done) {
22+
it("callApi intercepted for ApiClient with collectionQueryParams", function (done) {
2323
const postBody = {
2424
elem1: {
2525
encryptedData: {
@@ -51,6 +51,57 @@ describe("MC API Service", () => {
5151
{ test: "header" },
5252
null,
5353
postBody,
54+
null,
55+
null,
56+
null,
57+
null,
58+
null,
59+
function cb(error, data) {
60+
assert.ok(data.elem1.encryptedData);
61+
assert.ok(data.elem1.encryptedKey);
62+
assert.ok(data.elem1.publicKeyFingerprint);
63+
assert.ok(data.elem1.oaepHashingAlgorithm);
64+
done();
65+
}
66+
);
67+
});
68+
69+
it("callApi intercepted for ApiClient without collectionQueryParams", function (done) {
70+
const postBody = {
71+
elem1: {
72+
encryptedData: {
73+
accountNumber: "5123456789012345",
74+
},
75+
},
76+
};
77+
const service = {
78+
ApiClient: {
79+
instance: {
80+
callApi: function () {
81+
arguments[arguments.length - 1](null, arguments[6], {
82+
body: arguments[6],
83+
request: { url: "/resource" },
84+
});
85+
},
86+
},
87+
},
88+
};
89+
const mcService = new MCService(service, testConfig);
90+
// simulate callApi call from client
91+
service.ApiClient.instance.callApi.call(
92+
mcService,
93+
"/resource",
94+
"POST",
95+
null,
96+
null,
97+
{ test: "header" },
98+
null,
99+
postBody,
100+
null,
101+
null,
102+
null,
103+
null,
104+
null,
54105
function cb(error, data) {
55106
assert.ok(data.elem1.encryptedData);
56107
assert.ok(data.elem1.encryptedKey);

0 commit comments

Comments
 (0)