diff --git a/packages/core/src/getters/res-req-types.ts b/packages/core/src/getters/res-req-types.ts index d01022c10..6b354dc7d 100644 --- a/packages/core/src/getters/res-req-types.ts +++ b/packages/core/src/getters/res-req-types.ts @@ -342,7 +342,24 @@ const getSchemaFormDataAndUrlEncoded = ({ } if (schema.type === 'array') { - return `${form}${propName}.forEach(value => ${variableName}.append('data', value))\n`; + let valueStr = 'value'; + if (schema.items) { + const { schema: itemSchema } = resolveRef( + schema.items, + context, + ); + if (itemSchema.type === 'object' || itemSchema.type === 'array') { + valueStr = 'JSON.stringify(value)'; + } else if ( + itemSchema.type === 'number' || + itemSchema.type === 'integer' || + itemSchema.type === 'boolean' + ) { + valueStr = 'value.toString()'; + } + } + + return `${form}${propName}.forEach(value => ${variableName}.append('data', ${valueStr}))\n`; } if ( @@ -390,7 +407,23 @@ const resolveSchemaPropertiesToFormData = ({ if (property.type === 'object') { formDataValue = `${variableName}.append('${key}', JSON.stringify(${nonOptionalValueKey}));\n`; } else if (property.type === 'array') { - formDataValue = `${nonOptionalValueKey}.forEach(value => ${variableName}.append('${key}', value));\n`; + let valueStr = 'value'; + if (property.items) { + const { schema: itemSchema } = resolveRef( + property.items, + context, + ); + if (itemSchema.type === 'object' || itemSchema.type === 'array') { + valueStr = 'JSON.stringify(value)'; + } else if ( + itemSchema.type === 'number' || + itemSchema.type === 'integer' || + itemSchema.type === 'boolean' + ) { + valueStr = 'value.toString()'; + } + } + formDataValue = `${valueKey}.forEach(value => ${variableName}.append('${key}', ${valueStr}));\n`; } else if ( property.type === 'number' || property.type === 'integer' ||