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..6eb0dbaed87 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-axios/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-axios/api.mustache @@ -25,25 +25,45 @@ 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}} + {{#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) 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