Skip to content

Commit

Permalink
Merge pull request #43 from aleh-douhi/feature/support-openapi-genera…
Browse files Browse the repository at this point in the history
…tor-610

Fix body and header argument number for ApiClient generated with openapi-generator 6.1.0
  • Loading branch information
rfeelin committed Sep 28, 2022
2 parents 785475f + 3095a93 commit 92af2e9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/mcapi/mcapi-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ function Service(service, config) {
function (original, outObj) {
return function () {
const endpoint = arguments[0];
const header = arguments[5];
const body = arguments[7];
const header = arguments[arguments.length - 9];
const body = arguments[arguments.length - 7];
const cb = arguments[arguments.length - 1];
if (body) {
const encrypted = outObj.encryption.encrypt(endpoint, header, body);
arguments[5] = encrypted.header;
arguments[7] = encrypted.body;
arguments[arguments.length - 9] = encrypted.header;
arguments[arguments.length - 7] = encrypted.body;
}
arguments[arguments.length - 1] = function (error, data, response) {
if (response && response.body) {
Expand Down
53 changes: 52 additions & 1 deletion test/mcapi-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("MC API Service", () => {
}, /service should be a valid OpenAPI client./);
});

it("callApi intercepted", function (done) {
it("callApi intercepted for ApiClient with collectionQueryParams", function (done) {
const postBody = {
elem1: {
encryptedData: {
Expand Down Expand Up @@ -51,6 +51,57 @@ describe("MC API Service", () => {
{ test: "header" },
null,
postBody,
null,
null,
null,
null,
null,
function cb(error, data) {
assert.ok(data.elem1.encryptedData);
assert.ok(data.elem1.encryptedKey);
assert.ok(data.elem1.publicKeyFingerprint);
assert.ok(data.elem1.oaepHashingAlgorithm);
done();
}
);
});

it("callApi intercepted for ApiClient without collectionQueryParams", function (done) {
const postBody = {
elem1: {
encryptedData: {
accountNumber: "5123456789012345",
},
},
};
const service = {
ApiClient: {
instance: {
callApi: function () {
arguments[arguments.length - 1](null, arguments[6], {
body: arguments[6],
request: { url: "/resource" },
});
},
},
},
};
const mcService = new MCService(service, testConfig);
// simulate callApi call from client
service.ApiClient.instance.callApi.call(
mcService,
"/resource",
"POST",
null,
null,
{ test: "header" },
null,
postBody,
null,
null,
null,
null,
null,
function cb(error, data) {
assert.ok(data.elem1.encryptedData);
assert.ok(data.elem1.encryptedKey);
Expand Down

0 comments on commit 92af2e9

Please sign in to comment.