UNPKG

@apideck/portman

Version:

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

38 lines 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRawLanguageFromContentType = exports.getRequestBodyExample = void 0; var getRequestBodyExample = function (reqBody, contentType) { if (!(reqBody === null || reqBody === void 0 ? void 0 : reqBody.content)) return undefined; var content = reqBody.content[contentType]; if (!content) return undefined; if (content.example !== undefined) { return typeof content.example === 'string' ? content.example : JSON.stringify(content.example, null, 2); } if (content.examples) { var exKey = Object.keys(content.examples)[0]; var exampleObj = content.examples[exKey]; var val = exampleObj === null || exampleObj === void 0 ? void 0 : exampleObj.value; if (val !== undefined) { return typeof val === 'string' ? val : JSON.stringify(val, null, 2); } } if (content.schema && content.schema.example !== undefined) { var val = content.schema.example; return typeof val === 'string' ? val : JSON.stringify(val, null, 2); } return undefined; }; exports.getRequestBodyExample = getRequestBodyExample; var getRawLanguageFromContentType = function (contentType) { if (contentType.includes('json')) return 'json'; if (contentType.includes('xml')) return 'xml'; return 'text'; }; exports.getRawLanguageFromContentType = getRawLanguageFromContentType; //# sourceMappingURL=getRequestBodyExample.js.map