UNPKG

@apideck/portman

Version:

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

47 lines 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OasMappedOperation = void 0; var tslib_1 = require("tslib"); var OasMappedOperation = (function () { function OasMappedOperation(path, method, operation) { var _a, _b; this.schema = tslib_1.__assign({}, operation); this.id = (_a = this.schema) === null || _a === void 0 ? void 0 : _a.operationId; this.method = method.toUpperCase(); this.path = path; this.pathRef = "".concat(this.method, "::").concat(path); this.requestHeaders = this.mapParameters('header'); this.pathParams = this.mapParameters('path'); this.queryParams = this.mapParameters('query'); this.cookieParams = this.mapParameters('cookie'); this.responseCodes = this.mapResponseCodes(); this.tags = (_b = this.schema) === null || _b === void 0 ? void 0 : _b.tags; } OasMappedOperation.prototype.mapParameters = function (paramIn) { var _a; if (!((_a = this.schema) === null || _a === void 0 ? void 0 : _a.parameters)) return []; return (this.schema.parameters.filter(function (parameter) { return parameter.in === paramIn; }) || []); }; OasMappedOperation.prototype.requestBody = function () { var _a; return (_a = this.schema) === null || _a === void 0 ? void 0 : _a.requestBody; }; OasMappedOperation.prototype.requestBodySchema = function (mediaType) { var _a, _b; var requestBody = this.requestBody(); if (!requestBody || !((_b = (_a = requestBody === null || requestBody === void 0 ? void 0 : requestBody.content) === null || _a === void 0 ? void 0 : _a[mediaType]) === null || _b === void 0 ? void 0 : _b.schema)) return; return requestBody.content[mediaType].schema; }; OasMappedOperation.prototype.mapResponseCodes = function () { var _a, _b; if ((_a = this === null || this === void 0 ? void 0 : this.schema) === null || _a === void 0 ? void 0 : _a.responses) { return Object.keys((_b = this.schema) === null || _b === void 0 ? void 0 : _b.responses); } return []; }; return OasMappedOperation; }()); exports.OasMappedOperation = OasMappedOperation; //# sourceMappingURL=OasMappedOperation.js.map