From c26b836a446fd3b185cb464b90373fe6d1c9cfe2 Mon Sep 17 00:00:00 2001 From: Ian White Date: Thu, 28 Jun 2018 18:02:20 -0400 Subject: [PATCH 1/2] passing Partial to parameters, to make it easier to do update/create operations on required field types --- .../src/main/resources/typescript-axios/api.mustache | 2 +- .../src/main/resources/typescript-axios/model.mustache | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-axios/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-axios/api.mustache index 2e38b72ace4..7d4d0c57f78 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-axios/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-axios/api.mustache @@ -25,7 +25,7 @@ export class {{classname}}Resource { * {{notes}} {{#allParams}}* @param {{paramName}} {{description}} {{/allParams}}*/ - public {{nickname}}({{#allParams}}{{^isQueryParam}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/isQueryParam}}{{/allParams}}{{#hasQueryParams}}query?: { {{#queryParams}}{{paramName}}{{^required}}?{{/required}}: {{dataType}}{{^-last}},{{/-last}} {{/queryParams}}}, {{/hasQueryParams}}axiosConfig?: AxiosRequestConfig): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { + public {{nickname}}({{#allParams}}{{^isQueryParam}}{{paramName}}{{^required}}?{{/required}}: Partial<{{{dataType}}}>, {{/isQueryParam}}{{/allParams}}{{#hasQueryParams}}query?: { {{#queryParams}}{{paramName}}{{^required}}?{{/required}}: {{dataType}}{{^-last}},{{/-last}} {{/queryParams}}}, {{/hasQueryParams}}axiosConfig?: AxiosRequestConfig): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { const reqPath = '{{path}}'{{#pathParams}} .replace('{' + '{{baseName}}}', String({{paramName}}{{#isDateTime}}.toISOString(){{/isDateTime}})){{/pathParams}}; {{#hasFormParams}} diff --git a/modules/swagger-codegen/src/main/resources/typescript-axios/model.mustache b/modules/swagger-codegen/src/main/resources/typescript-axios/model.mustache index 186b003bc8f..41eeb1a0a8b 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-axios/model.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-axios/model.mustache @@ -4,8 +4,6 @@ {{#tsImports}} import { {{classname}} } from './{{filename}}'; {{/tsImports}}{{#description}} -/** -* {{{description}}} -*/{{/description}}{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>modelGeneric}}{{/isEnum}} +/* {{{description}}} */{{/description}}{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>modelGeneric}}{{/isEnum}} {{/model}} {{/models}} \ No newline at end of file From c273a50548f4af0556154fed99dd2d87c477478b Mon Sep 17 00:00:00 2001 From: jack Date: Mon, 11 Feb 2019 13:38:11 -0500 Subject: [PATCH 2/2] Add support for multipart/form-data when file is present --- .../resources/typescript-axios/api.mustache | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-axios/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-axios/api.mustache index 7d4d0c57f78..6eb0dbaed87 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-axios/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-axios/api.mustache @@ -28,22 +28,42 @@ export class {{classname}}Resource { public {{nickname}}({{#allParams}}{{^isQueryParam}}{{paramName}}{{^required}}?{{/required}}: Partial<{{{dataType}}}>, {{/isQueryParam}}{{/allParams}}{{#hasQueryParams}}query?: { {{#queryParams}}{{paramName}}{{^required}}?{{/required}}: {{dataType}}{{^-last}},{{/-last}} {{/queryParams}}}, {{/hasQueryParams}}axiosConfig?: AxiosRequestConfig): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { const reqPath = '{{path}}'{{#pathParams}} .replace('{' + '{{baseName}}}', String({{paramName}}{{#isDateTime}}.toISOString(){{/isDateTime}})){{/pathParams}}; -{{#hasFormParams}} + {{#hasFormParams}} + let hasFile = false; + {{#formParams}} + {{#isFile}}hasFile = true; + {{/isFile}} + {{/formParams}} + let reqFormParams = { -{{#formParams}} + {{#formParams}} {{baseName}}: {{paramName}}{{^-last}},{{/-last}} -{{/formParams}} + {{/formParams}} }; -{{/hasFormParams}} + + let headers: any; + let data: any; + + if (hasFile) { + headers = { 'Content-Type': 'multipart/form-data' }; + data = new FormData(); + Object.keys(reqFormParams).forEach((key) => { + data.append(key, reqFormParams[key]); + }); + } else { + headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; + data = stringify(reqFormParams); + } + {{/hasFormParams}} let reqConfig = { ...axiosConfig, method: '{{httpMethod}}', url: reqPath{{#hasQueryParams}}, params: query{{/hasQueryParams}}{{#bodyParam}}, data: {{paramName}}{{/bodyParam}}{{#hasFormParams}}, - headers: { 'Content-Type': 'application/x-www-form-urlencoded'}, - data: stringify(reqFormParams) -{{/hasFormParams}} + headers: headers, + data: data + {{/hasFormParams}} }; return axios.request(reqConfig)