@apideck/portman
Version:
Port OpenAPI Spec to Postman Collection, with contract & variation tests included
32 lines • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeOperationPreRequestScript = void 0;
var postman_collection_1 = require("postman-collection");
var writeOperationPreRequestScript = function (pmOperation, preRequestScript, overwrite, append) {
var _a;
if (overwrite === void 0) { overwrite = false; }
if (append === void 0) { append = true; }
var pmPreRequestEvent = pmOperation.item.events.find(function (e) { return (e === null || e === void 0 ? void 0 : e.listen) === 'prerequest'; }, null);
if (pmPreRequestEvent === undefined) {
pmOperation.item.events.add(new postman_collection_1.Event({
listen: 'prerequest',
script: {
exec: [preRequestScript],
type: 'text/javascript'
}
}));
return pmOperation;
}
if (!((_a = pmPreRequestEvent === null || pmPreRequestEvent === void 0 ? void 0 : pmPreRequestEvent.script) === null || _a === void 0 ? void 0 : _a.exec) || overwrite) {
pmPreRequestEvent.script.exec = [];
}
if (append) {
pmPreRequestEvent.script.exec.push(preRequestScript);
}
else {
pmPreRequestEvent.script.exec.unshift(preRequestScript);
}
return pmOperation;
};
exports.writeOperationPreRequestScript = writeOperationPreRequestScript;
//# sourceMappingURL=writeOperationPreRequestScript.js.map