Skip to content

Commit

Permalink
Added a function to put additional parameters into body if schema con…
Browse files Browse the repository at this point in the history
…tains them
  • Loading branch information
SvenHoeffler committed Dec 12, 2024
1 parent 83d835a commit fe46950
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion templates/lib/actions/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

const spec = require("../spec.json");
const { mapFieldNames, getMetadata, mapFormDataBody, executeCall } = require("../utils/helpers");
const { mapFieldNames, getMetadata, mapFormDataBody, putAdditionalParamsInBody, executeCall } = require("../utils/helpers");
const componentJson = require("../../component.json");

async function processAction(msg, cfg, snapshot, incomingMessageHeaders, tokenData) {
Expand Down Expand Up @@ -53,6 +53,11 @@ async function processAction(msg, cfg, snapshot, incomingMessageHeaders, tokenDa
specPathParameters.push(...specPathGeneralParams);

let body = msg.data;

if (cfg && cfg.additionalParameters) {
body = putAdditionalParamsInBody(this, action, body, cfg.additionalParameters)
}

mapFieldNames(body);
if (requestContentType === "multipart/form-data") {
logger.info("requestContentType multipart/form-data is defined");
Expand Down
17 changes: 16 additions & 1 deletion templates/lib/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ const mapFormDataBody = async function (action, body) {
return body;
};

const putAdditionalParamsInBody = async function (action, body, additionalParameters) {
const newBody = body;
const inputMetadataSchema = getInputMetadataSchema(action.metadata.in);

for (let property in additionalParameters) {
if (property in inputMetadataSchema && !(property in body)) {
body[property] = additionalParameters[property];
}
}

return newBody;
};

function compareDate(a, b) {
return dayjs(a).isAfter(b);
}
Expand Down Expand Up @@ -289,5 +302,7 @@ module.exports = {
mapFormDataBody,
isMicrosoftJsonDate,
executeCall,
getInitialSnapshotValue
getInitialSnapshotValue,
getInputMetadataSchema,
putAdditionalParamsInBody
};

0 comments on commit fe46950

Please sign in to comment.