diff --git a/lib/process.js b/lib/process.js index 28c3e6a..eb3b4d7 100644 --- a/lib/process.js +++ b/lib/process.js @@ -217,6 +217,11 @@ function processTransactions(api, parentOp, parentPath, topLevel, options) { for (let index = 0; index < count; index++) { var params = processParams(res.statusCode, parentOp, parentPath, options, index) var expected = processResponse(res, parentOp.method, parentPath.path, options, index) + var requestBody = processRequestBody(res.pathToDefinition, options) + + if (requestBody && Object.keys(params.body).length === 0 ){ + params.body = requestBody + } var hasValue = options.samples if (expected.custom) { @@ -595,3 +600,24 @@ function replaceNewlines(str) { function escapeSingleQuotes(str) { return str.replace(/'/g, "\\'") } + +/** + * + * @param {} pathToDefinition Definition array with [ path, defPath, method, response, code] + * @param {*} options + * @returns + */ +function processRequestBody( pathToDefinition, options ){ + const [ path, defPath, method, response, code ] = pathToDefinition + let requestBody = null + + if (['post', 'patch', 'put'].includes(method)){ + if ( options.customValues + && options.customValues[defPath] + && options.customValues[defPath][method] + && options.customValues[defPath][method][code]){ + requestBody = options.customValues[defPath][method][code]['requestBody'] + } + } + return requestBody +} \ No newline at end of file