From 00b46e8a94d94f798475e537b8b72db6934d8971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20C=C3=B4t=C3=A9?= Date: Wed, 9 Aug 2017 05:05:00 -0400 Subject: [PATCH] [Typescript-Jquery] Fix file upload (#6262) * Fix a bug with the file upload that was not working * Prevent unnecessary append to the FormData --- .../src/main/resources/typescript-jquery/api.mustache | 4 +++- .../petstore/typescript-jquery/default/api/PetApi.ts | 8 +------- .../client/petstore/typescript-jquery/npm/api/PetApi.ts | 8 +------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache index b3697917496..5acab55f344 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-jquery/api.mustache @@ -103,7 +103,9 @@ export class {{classname}} { {{#formParams}} {{#isFile}} reqHasFile = true; + formParams = {{paramName}}; {{/isFile}} +{{^isFile}} {{#isListContainer}} if ({{paramName}}) { {{#isCollectionFormatMulti}} @@ -121,7 +123,7 @@ export class {{classname}} { formParams.append('{{baseName}}', {{paramName}}); } {{/isListContainer}} - +{{/isFile}} {{/formParams}} {{#headerParams}} {{#isListContainer}} diff --git a/samples/client/petstore/typescript-jquery/default/api/PetApi.ts b/samples/client/petstore/typescript-jquery/default/api/PetApi.ts index 8b720012525..ef7f615f690 100644 --- a/samples/client/petstore/typescript-jquery/default/api/PetApi.ts +++ b/samples/client/petstore/typescript-jquery/default/api/PetApi.ts @@ -433,11 +433,9 @@ export class PetApi { if (name !== null && name !== undefined) { formParams.append('name', name); } - if (status !== null && status !== undefined) { formParams.append('status', status); } - // to determine the Content-Type header let consumes: string[] = [ 'application/x-www-form-urlencoded' @@ -515,12 +513,8 @@ export class PetApi { if (additionalMetadata !== null && additionalMetadata !== undefined) { formParams.append('additionalMetadata', additionalMetadata); } - reqHasFile = true; - if (file !== null && file !== undefined) { - formParams.append('file', file); - } - + formParams = file; // to determine the Content-Type header let consumes: string[] = [ 'multipart/form-data' diff --git a/samples/client/petstore/typescript-jquery/npm/api/PetApi.ts b/samples/client/petstore/typescript-jquery/npm/api/PetApi.ts index 8b720012525..ef7f615f690 100644 --- a/samples/client/petstore/typescript-jquery/npm/api/PetApi.ts +++ b/samples/client/petstore/typescript-jquery/npm/api/PetApi.ts @@ -433,11 +433,9 @@ export class PetApi { if (name !== null && name !== undefined) { formParams.append('name', name); } - if (status !== null && status !== undefined) { formParams.append('status', status); } - // to determine the Content-Type header let consumes: string[] = [ 'application/x-www-form-urlencoded' @@ -515,12 +513,8 @@ export class PetApi { if (additionalMetadata !== null && additionalMetadata !== undefined) { formParams.append('additionalMetadata', additionalMetadata); } - reqHasFile = true; - if (file !== null && file !== undefined) { - formParams.append('file', file); - } - + formParams = file; // to determine the Content-Type header let consumes: string[] = [ 'multipart/form-data'