diff --git a/src/execute/oas3/build-request.js b/src/execute/oas3/build-request.js index 0b928c415..a2182c285 100644 --- a/src/execute/oas3/build-request.js +++ b/src/execute/oas3/build-request.js @@ -55,36 +55,9 @@ export default function (options, req) { req.form = {} Object.keys(requestBody).forEach((k) => { const val = requestBody[k] - let newVal - - let isFile - - if (typeof File !== 'undefined') { - isFile = val instanceof File // eslint-disable-line no-undef - } - - if (typeof Blob !== 'undefined') { - isFile = isFile || val instanceof Blob // eslint-disable-line no-undef - } - - if (typeof Buffer !== 'undefined') { - isFile = isFile || Buffer.isBuffer(val) - } - - if (typeof val === 'object' && !isFile) { - if (Array.isArray(val)) { - newVal = val.toString() - } - else { - newVal = JSON.stringify(val) - } - } - else { - newVal = val - } req.form[k] = { - value: newVal + value: toPartContent(val, true) } }) } @@ -105,6 +78,34 @@ export default function (options, req) { return req } +function toPartContent(val, inspectArrays){ + if (inspectArrays && Array.isArray(val)) { + // setting 'inspectArrays' to false to avoid cycles in arrays that contain themselves + return val.map(v => toPartContent(v, false)) + } + + let isFile + + if (typeof File !== 'undefined') { + isFile = val instanceof File // eslint-disable-line no-undef + } + + if (typeof Blob !== 'undefined') { + isFile = isFile || val instanceof Blob // eslint-disable-line no-undef + } + + if (typeof Buffer !== 'undefined') { + isFile = isFile || Buffer.isBuffer(val) + } + + if (typeof val === 'object' && !isFile) { + return JSON.stringify(val) + } + else { + return val + } +} + // Add security values, to operations - that declare their need on them // Adapted from the Swagger2 implementation export function applySecurities({request, securities = {}, operation = {}, spec}) { diff --git a/src/http.js b/src/http.js index 934baecd7..1d1313481 100644 --- a/src/http.js +++ b/src/http.js @@ -254,7 +254,12 @@ export function mergeInQueryOrForm(req = {}) { const FormData = require('isomorphic-form-data') // eslint-disable-line global-require req.body = new FormData() Object.keys(form).forEach((key) => { - req.body.append(key, formatValue(form[key], true)) + const val = form[key] + if (Array.isArray(val.value)){ + val.value.forEach(v => req.body.append(key, formatValue({value: v}, true))) + } else { + req.body.append(key, formatValue(val, true)) + } }) } else {