UNPKG

@apideck/portman

Version:

Port OpenAPI Spec to Postman Collection, with contract & variation tests included

74 lines 3.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OpenApiFormatter = void 0; var tslib_1 = require("tslib"); var openapi_format_1 = tslib_1.__importDefault(require("openapi-format")); var OpenApiFormatter = (function () { function OpenApiFormatter() { } OpenApiFormatter.prototype.filter = function (options) { return tslib_1.__awaiter(this, void 0, void 0, function () { var inputFilePath, filterFilePath, filterOptions, _a, filterSet, resFilter; return tslib_1.__generator(this, function (_b) { switch (_b.label) { case 0: inputFilePath = options.inputFile; filterFilePath = options.filterFile; filterOptions = {}; _a = this; return [4, openapi_format_1.default.parseFile(inputFilePath, { bundle: true })]; case 1: _a.oas = (_b.sent()); return [4, openapi_format_1.default.parseFile(filterFilePath)]; case 2: filterSet = (_b.sent()); filterOptions.filterSet = filterSet; return [4, openapi_format_1.default.openapiFilter(this.oas, filterOptions)]; case 3: resFilter = _b.sent(); this.oas = resFilter.data; if (!options.outputFile) return [3, 5]; return [4, openapi_format_1.default.writeFile(options.outputFile, this.oas, { format: 'yaml' })]; case 4: _b.sent(); _b.label = 5; case 5: return [2, this.oas]; } }); }); }; OpenApiFormatter.prototype.parseFile = function (filePath) { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, openapi_format_1.default.parseFile(filePath)]; case 1: return [2, _a.sent()]; } }); }); }; OpenApiFormatter.prototype.writeFile = function (filePath, data, options) { if (data === void 0) { data = {}; } if (options === void 0) { options = {}; } return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, openapi_format_1.default.writeFile(filePath, data, options)]; case 1: return [2, _a.sent()]; } }); }); }; OpenApiFormatter.prototype.changeCase = function (valueAsString, caseType) { if (caseType === 'lowerCase') return valueAsString.toLowerCase(); if (caseType === 'upperCase') return valueAsString.toUpperCase(); return openapi_format_1.default.changeCase(valueAsString, caseType); }; return OpenApiFormatter; }()); exports.OpenApiFormatter = OpenApiFormatter; //# sourceMappingURL=OpenApiFormat.js.map