@apideck/portman
Version:
Port OpenAPI Spec to Postman Collection, with contract & variation tests included
241 lines • 15.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var yargs_1 = tslib_1.__importDefault(require("yargs"));
var Portman_1 = require("./Portman");
var promptInit_1 = require("./utils/promptInit");
var oas_1 = require("./oas");
require('dotenv').config();
(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var options, cliOptions, oaf, cliOptionsFilePath, err_1, newmanOptionsFilePath, _a, err_2, newmanRunOptionsArg, oaUrl, oaLocal, baseUrl, includeTests, bundleContractTests, runNewman, newmanData, syncToPostman, portmanConfigFile, portmanConfigPath, postmanConfigFile, postmanConfigPath, envFile, filterFile, oaOutput, collectionName, logAssignVariables, warn, extraUnknownFormats, syncPostmanCollectionIds, portman;
var _b, _c, _d, _e;
return tslib_1.__generator(this, function (_f) {
switch (_f.label) {
case 0:
options = yargs_1.default
.usage('Usage: -u <url> -l <local> -b <baseUrl> -t <includeTests>')
.option('u', {
alias: 'url',
describe: 'URL of OAS to port to Postman collection',
type: 'string'
})
.option('l', {
alias: 'local',
describe: 'Use local OAS to port to Postman collection',
type: 'string'
})
.option('b', {
alias: 'baseUrl',
describe: 'Override spec baseUrl to use in Postman',
type: 'string'
})
.option('o', {
alias: 'output',
describe: 'Write the Postman collection to an output file',
type: 'string'
})
.option('n', {
alias: 'runNewman',
describe: 'Run Newman on newly created collection',
type: 'boolean'
})
.option('newmanRunOptions', {
describe: 'JSON stringified object to pass options for configuring Newman',
type: 'string'
})
.option('newmanOptionsFile', {
describe: 'Path/URL to Newman options file to pass options for configuring Newman',
type: 'string'
})
.option('d', {
alias: 'newmanIterationData',
describe: 'Iteration data to run Newman with newly created collection',
type: 'string'
})
.option('localPostman', {
describe: 'Use local Postman collection, skips OpenAPI conversion',
type: 'string'
})
.option('syncPostman', {
alias: 'syncPostman',
describe: 'Upload generated collection to Postman, after conversion',
type: 'boolean'
})
.option('postmanFastSync', {
describe: 'Postman sync creates new collection (new UID), instead of update',
type: 'boolean'
})
.option('postmanRefreshCache', {
describe: 'Postman sync will refresh all local cached Postman API data',
type: 'boolean'
})
.option('p', {
alias: 'postmanUid',
describe: 'Postman collection UID to upload with the generated Postman collection',
type: 'string'
})
.option('postmanWorkspaceName', {
describe: 'Postman Workspace name to target the upload of the generated Postman collection',
type: 'string'
})
.option('uploadOnly', {
alias: 'uploadOnly',
describe: 'Upload generated collection to Postman',
type: 'boolean'
})
.option('ignoreCircularRefs', {
alias: 'ignoreCircularRefs',
describe: 'Ignore circular references in OpenAPI spec (default: false)',
type: 'boolean'
})
.option('t', {
alias: 'includeTests',
describe: 'Inject Portman test suite (default: true)',
type: 'boolean'
})
.option('bundleContractTests', {
describe: 'Bundle Portman contract tests in a separate folder in Postman (default: false)',
type: 'boolean'
})
.option('c', {
alias: 'portmanConfigFile',
describe: 'Path/URL to Portman settings config file (portman-config.json)',
type: 'string'
})
.option('s', {
alias: 'postmanConfigFile',
describe: 'Path to openapi-to-postman config file (postman-config.json)',
type: 'string'
})
.option('filterFile', {
describe: 'Path/URL to openapi-format config file (oas-format-filter.json)',
type: 'string'
})
.option('oaOutput', {
describe: 'Write the (filtered) OpenAPI file to an output file',
type: 'string'
})
.option('collectionName', {
describe: 'Overwrite OpenAPI title to set the Postman collection name',
type: 'string'
})
.option('envFile', {
describe: 'Path to the .env file to inject environment variables',
type: 'string'
})
.option('cliOptionsFile', {
describe: 'Path to Portman CLI options file',
type: 'string'
})
.option('logAssignVariables', {
describe: 'Toggle logging of assigned variables',
type: 'boolean'
})
.option('warn', {
describe: 'Toggle warnings for missing openApiOperationIds',
type: 'boolean'
})
.option('init', {
describe: 'Initialize Portman and generate a Portman CLI configuration file',
type: 'boolean'
})
.option('extraUnknownFormats', {
describe: 'Add extra unknown formats to json schema tests',
type: 'array'
})
.option('syncPostmanCollectionIds', {
describe: "Synchronises the IDs of newly created postman collections with those already on Postman, \n useful when you want to use Postman pull request (default: false)",
type: 'boolean'
})
.strict().argv;
cliOptions = {};
if (!options.init) return [3, 2];
console.log('\x1b[32m', "\n \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2557\n \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\n \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\n \u2588\u2588\u2554\u2550\u2550\u2550\u255D \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\n \u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\n \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D\n\n ");
return [4, (0, promptInit_1.promptInit)()];
case 1:
_f.sent();
process.exit();
_f.label = 2;
case 2:
oaf = new oas_1.OpenApiFormatter();
if (!options.cliOptionsFile) return [3, 6];
_f.label = 3;
case 3:
_f.trys.push([3, 5, , 6]);
cliOptionsFilePath = options.cliOptionsFile;
return [4, oaf.parseFile(cliOptionsFilePath)];
case 4:
cliOptions = (_f.sent());
return [3, 6];
case 5:
err_1 = _f.sent();
console.error('\x1b[31m', 'Portman CLI Config error - no such file or directory "' + options.cliOptionsFile + '"');
process.exit(1);
return [3, 6];
case 6:
cliOptions.newmanOptionsFile = (options === null || options === void 0 ? void 0 : options.newmanOptionsFile)
? options.newmanOptionsFile
: cliOptions.newmanOptionsFile;
if (!cliOptions.newmanOptionsFile) return [3, 10];
_f.label = 7;
case 7:
_f.trys.push([7, 9, , 10]);
newmanOptionsFilePath = cliOptions.newmanOptionsFile;
_a = cliOptions;
return [4, oaf.parseFile(newmanOptionsFilePath)];
case 8:
_a.newmanRunOptions = (_f.sent());
return [3, 10];
case 9:
err_2 = _f.sent();
console.error('\x1b[31m', 'Newman Options error - no such file or directory "' + options.newmanOptionsFile + '"');
process.exit(1);
return [3, 10];
case 10:
if (options.newmanRunOptions) {
try {
newmanRunOptionsArg = JSON.parse(options.newmanRunOptions);
options.newmanRunOptions = (cliOptions === null || cliOptions === void 0 ? void 0 : cliOptions.newmanRunOptions)
? tslib_1.__assign(tslib_1.__assign({}, cliOptions.newmanRunOptions), newmanRunOptionsArg) : newmanRunOptionsArg;
}
catch (error) {
console.error('\x1b[31m', 'Portman CLI Config error - newmanRunOptions: ' + error + '"');
process.exit(1);
}
}
options = tslib_1.__assign(tslib_1.__assign({}, cliOptions), options);
oaUrl = (options === null || options === void 0 ? void 0 : options.url) || '';
oaLocal = (options === null || options === void 0 ? void 0 : options.local) || '';
baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || '';
includeTests = (_b = options === null || options === void 0 ? void 0 : options.includeTests) !== null && _b !== void 0 ? _b : true;
bundleContractTests = (_c = options === null || options === void 0 ? void 0 : options.bundleContractTests) !== null && _c !== void 0 ? _c : false;
runNewman = options === null || options === void 0 ? void 0 : options.runNewman;
newmanData = (options === null || options === void 0 ? void 0 : options.newmanIterationData) || '';
syncToPostman = (options === null || options === void 0 ? void 0 : options.syncPostman) || false;
portmanConfigFile = options === null || options === void 0 ? void 0 : options.portmanConfigFile;
portmanConfigPath = (_d = options === null || options === void 0 ? void 0 : options.portmanConfigFile) !== null && _d !== void 0 ? _d : __dirname + '/../portman-config.default.json';
postmanConfigFile = options === null || options === void 0 ? void 0 : options.postmanConfigFile;
postmanConfigPath = (_e = options === null || options === void 0 ? void 0 : options.postmanConfigFile) !== null && _e !== void 0 ? _e : __dirname + '/../postman-config.default.json';
envFile = (options === null || options === void 0 ? void 0 : options.envFile) || '.env';
filterFile = options.filterFile;
oaOutput = options.oaOutput || '';
collectionName = options.collectionName || '';
logAssignVariables = options === null || options === void 0 ? void 0 : options.logAssignVariables;
warn = (options === null || options === void 0 ? void 0 : options.warn) || true;
extraUnknownFormats = (options === null || options === void 0 ? void 0 : options.extraUnknownFormats) || [];
syncPostmanCollectionIds = (options === null || options === void 0 ? void 0 : options.syncPostmanCollectionIds) || false;
portman = new Portman_1.Portman(tslib_1.__assign(tslib_1.__assign({}, options), { oaUrl: oaUrl, oaLocal: oaLocal, baseUrl: baseUrl, includeTests: includeTests, bundleContractTests: bundleContractTests, runNewman: runNewman, newmanIterationData: newmanData, syncPostman: syncToPostman, portmanConfigFile: portmanConfigFile, portmanConfigPath: portmanConfigPath, postmanConfigFile: postmanConfigFile, postmanConfigPath: postmanConfigPath, envFile: envFile, filterFile: filterFile, oaOutput: oaOutput, collectionName: collectionName, logAssignVariables: logAssignVariables, warn: warn, extraUnknownFormats: extraUnknownFormats, syncPostmanCollectionIds: syncPostmanCollectionIds }));
if (!options.uploadOnly) return [3, 12];
return [4, portman.uploadOnly()];
case 11:
_f.sent();
return [3, 14];
case 12: return [4, portman.run()];
case 13:
_f.sent();
_f.label = 14;
case 14: return [2];
}
});
}); })();
//# sourceMappingURL=index.js.map