From 047e544755a72bdd48f9176a70f667292d147210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Mets=C3=A4l=C3=A4?= Date: Mon, 12 Oct 2020 23:38:05 +0300 Subject: [PATCH] [typescript-fetch] serialize complex type in multipart/form-data as JSON (#7658) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Complex types need to be serialized as JSON to avoid FormData.append() from converting them into strings through .toString(). The generated ToJSON mapper is used in case the value name has underscores or other unusual characters. Signed-off-by: Andreas Metsälä --- .../src/main/resources/typescript-fetch/apis.mustache | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache index 056e0dbb2677..4f30b1f679b7 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache @@ -238,7 +238,12 @@ export class {{classname}} extends runtime.BaseAPI { {{/isListContainer}} {{^isListContainer}} if (requestParameters.{{paramName}} !== undefined) { + {{#isPrimitiveType}} formParams.append('{{baseName}}', requestParameters.{{paramName}} as any); + {{/isPrimitiveType}} + {{^isPrimitiveType}} + formParams.append('{{baseName}}', new Blob([JSON.stringify({{{dataType}}}ToJSON(requestParameters.{{paramName}}))], { type: "application/json", })); + {{/isPrimitiveType}} } {{/isListContainer}}