From 1b206232dfcbd5803e53c6b4dda72edf91ee2fe4 Mon Sep 17 00:00:00 2001
From: William Cheng <wing328hk@gmail.com>
Date: Fri, 5 Feb 2021 18:40:29 +0800
Subject: [PATCH] minor fixes to ts nestjs generator

---
 ...typescript-nestjs-v6-provided-in-root.yaml |  1 +
 .../typescript-nestjs/api.service.mustache    | 11 ++++----
 .../builds/default/api/pet.service.ts         | 25 ++++++++-----------
 .../builds/default/api/store.service.ts       |  8 ++----
 .../builds/default/api/user.service.ts        | 12 ++-------
 5 files changed, 22 insertions(+), 35 deletions(-)

diff --git a/bin/configs/typescript-nestjs-v6-provided-in-root.yaml b/bin/configs/typescript-nestjs-v6-provided-in-root.yaml
index 4fb999ef170..d5ca0d52431 100644
--- a/bin/configs/typescript-nestjs-v6-provided-in-root.yaml
+++ b/bin/configs/typescript-nestjs-v6-provided-in-root.yaml
@@ -1,6 +1,7 @@
 generatorName: typescript-nestjs
 outputDir: samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default
 inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
+templateDir: modules/openapi-generator/src/main/resources/typescript-nestjs
 additionalProperties:
   nestVersion: 6.0.0
   "npmName": "@openapitools/typescript-nestjs-petstore"
diff --git a/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache b/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache
index 3bc043bddb1..7e1fc2514b6 100644
--- a/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache
+++ b/modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache
@@ -107,7 +107,7 @@ export class {{classname}} {
         {{/isListContainer}}
         {{^isListContainer}}
         if ({{paramName}} !== undefined && {{paramName}} !== null) {
-            headers['{{baseName}}'] String({{paramName}});
+            headers['{{baseName}}'] = String({{paramName}});
         }
         {{/isListContainer}}
 {{/headerParams}}
@@ -147,7 +147,7 @@ export class {{classname}} {
         // to determine the Accept header
         let httpHeaderAccepts: string[] = [
             {{#produces}}
-            '{{{mediaType}}}'{{#hasMore}},{{/hasMore}}
+            '{{{mediaType}}}'{{^-last}},{{/-last}}
             {{/produces}}
         ];
         const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -158,7 +158,7 @@ export class {{classname}} {
         // to determine the Content-Type header
         const consumes: string[] = [
             {{#consumes}}
-            '{{{mediaType}}}'{{#hasMore}},{{/hasMore}}
+            '{{{mediaType}}}'{{^-last}},{{/-last}}
             {{/consumes}}
         ];
 {{#bodyParam}}
@@ -167,8 +167,8 @@ export class {{classname}} {
             headers['Content-Type'] = httpContentTypeSelected;
         }
 {{/bodyParam}}
-
 {{#hasFormParams}}
+
         const canConsumeForm = this.canConsumeForm(consumes);
 
         let formParams: { append(param: string, value: any): void; };
@@ -176,6 +176,7 @@ export class {{classname}} {
         let convertFormParamsToString = false;
 {{#formParams}}
 {{#isFile}}
+
         // use FormData to transmit files using content-type "multipart/form-data"
         // see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data
         useForm = canConsumeForm;
@@ -186,8 +187,8 @@ export class {{classname}} {
         } else {
             // formParams = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()});
         }
-
 {{#formParams}}
+
         {{#isListContainer}}
         if ({{paramName}}) {
         {{#isCollectionFormatMulti}}
diff --git a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts
index 554608d8f0d..7662f505df7 100644
--- a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts
+++ b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts
@@ -67,7 +67,7 @@ export class PetService {
 
         // to determine the Accept header
         let httpHeaderAccepts: string[] = [
-            'application/xml'
+            'application/xml',
             'application/json'
         ];
         const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -77,14 +77,13 @@ export class PetService {
 
         // to determine the Content-Type header
         const consumes: string[] = [
-            'application/json'
+            'application/json',
             'application/xml'
         ];
         const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
         if (httpContentTypeSelected != undefined) {
             headers['Content-Type'] = httpContentTypeSelected;
         }
-
         return this.httpClient.post<Pet>(`${this.basePath}/pet`,
             pet,
             {
@@ -111,7 +110,7 @@ export class PetService {
 
         let headers = this.defaultHeaders;
         if (apiKey !== undefined && apiKey !== null) {
-            headers['api_key'] String(apiKey);
+            headers['api_key'] = String(apiKey);
         }
 
         // authentication (petstore_auth) required
@@ -133,7 +132,6 @@ export class PetService {
         // to determine the Content-Type header
         const consumes: string[] = [
         ];
-
         return this.httpClient.delete<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
             {
                 withCredentials: this.configuration.withCredentials,
@@ -172,7 +170,7 @@ export class PetService {
 
         // to determine the Accept header
         let httpHeaderAccepts: string[] = [
-            'application/xml'
+            'application/xml',
             'application/json'
         ];
         const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -183,7 +181,6 @@ export class PetService {
         // to determine the Content-Type header
         const consumes: string[] = [
         ];
-
         return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByStatus`,
             {
                 params: queryParameters,
@@ -223,7 +220,7 @@ export class PetService {
 
         // to determine the Accept header
         let httpHeaderAccepts: string[] = [
-            'application/xml'
+            'application/xml',
             'application/json'
         ];
         const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -234,7 +231,6 @@ export class PetService {
         // to determine the Content-Type header
         const consumes: string[] = [
         ];
-
         return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByTags`,
             {
                 params: queryParameters,
@@ -266,7 +262,7 @@ export class PetService {
 
         // to determine the Accept header
         let httpHeaderAccepts: string[] = [
-            'application/xml'
+            'application/xml',
             'application/json'
         ];
         const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -277,7 +273,6 @@ export class PetService {
         // to determine the Content-Type header
         const consumes: string[] = [
         ];
-
         return this.httpClient.get<Pet>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
             {
                 withCredentials: this.configuration.withCredentials,
@@ -311,7 +306,7 @@ export class PetService {
 
         // to determine the Accept header
         let httpHeaderAccepts: string[] = [
-            'application/xml'
+            'application/xml',
             'application/json'
         ];
         const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -321,14 +316,13 @@ export class PetService {
 
         // to determine the Content-Type header
         const consumes: string[] = [
-            'application/json'
+            'application/json',
             'application/xml'
         ];
         const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
         if (httpContentTypeSelected != undefined) {
             headers['Content-Type'] = httpContentTypeSelected;
         }
-
         return this.httpClient.put<Pet>(`${this.basePath}/pet`,
             pet,
             {
@@ -392,6 +386,7 @@ export class PetService {
         if (name !== undefined) {
             formParams.append('name', <any>name);
         }
+
         if (status !== undefined) {
             formParams.append('status', <any>status);
         }
@@ -451,6 +446,7 @@ export class PetService {
         let formParams: { append(param: string, value: any): void; };
         let useForm = false;
         let convertFormParamsToString = false;
+
         // use FormData to transmit files using content-type "multipart/form-data"
         // see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data
         useForm = canConsumeForm;
@@ -463,6 +459,7 @@ export class PetService {
         if (additionalMetadata !== undefined) {
             formParams.append('additionalMetadata', <any>additionalMetadata);
         }
+
         if (file !== undefined) {
             formParams.append('file', <any>file);
         }
diff --git a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/store.service.ts b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/store.service.ts
index 2d5a23a5662..fd616d69018 100644
--- a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/store.service.ts
+++ b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/store.service.ts
@@ -67,7 +67,6 @@ export class StoreService {
         // to determine the Content-Type header
         const consumes: string[] = [
         ];
-
         return this.httpClient.delete<any>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
             {
                 withCredentials: this.configuration.withCredentials,
@@ -103,7 +102,6 @@ export class StoreService {
         // to determine the Content-Type header
         const consumes: string[] = [
         ];
-
         return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`,
             {
                 withCredentials: this.configuration.withCredentials,
@@ -129,7 +127,7 @@ export class StoreService {
 
         // to determine the Accept header
         let httpHeaderAccepts: string[] = [
-            'application/xml'
+            'application/xml',
             'application/json'
         ];
         const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -140,7 +138,6 @@ export class StoreService {
         // to determine the Content-Type header
         const consumes: string[] = [
         ];
-
         return this.httpClient.get<Order>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
             {
                 withCredentials: this.configuration.withCredentials,
@@ -166,7 +163,7 @@ export class StoreService {
 
         // to determine the Accept header
         let httpHeaderAccepts: string[] = [
-            'application/xml'
+            'application/xml',
             'application/json'
         ];
         const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -182,7 +179,6 @@ export class StoreService {
         if (httpContentTypeSelected != undefined) {
             headers['Content-Type'] = httpContentTypeSelected;
         }
-
         return this.httpClient.post<Order>(`${this.basePath}/store/order`,
             order,
             {
diff --git a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/user.service.ts b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/user.service.ts
index e2d7034ec8d..c4fc9fcf79a 100644
--- a/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/user.service.ts
+++ b/samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/user.service.ts
@@ -77,7 +77,6 @@ export class UserService {
         if (httpContentTypeSelected != undefined) {
             headers['Content-Type'] = httpContentTypeSelected;
         }
-
         return this.httpClient.post<any>(`${this.basePath}/user`,
             user,
             {
@@ -123,7 +122,6 @@ export class UserService {
         if (httpContentTypeSelected != undefined) {
             headers['Content-Type'] = httpContentTypeSelected;
         }
-
         return this.httpClient.post<any>(`${this.basePath}/user/createWithArray`,
             user,
             {
@@ -169,7 +167,6 @@ export class UserService {
         if (httpContentTypeSelected != undefined) {
             headers['Content-Type'] = httpContentTypeSelected;
         }
-
         return this.httpClient.post<any>(`${this.basePath}/user/createWithList`,
             user,
             {
@@ -210,7 +207,6 @@ export class UserService {
         // to determine the Content-Type header
         const consumes: string[] = [
         ];
-
         return this.httpClient.delete<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
             {
                 withCredentials: this.configuration.withCredentials,
@@ -236,7 +232,7 @@ export class UserService {
 
         // to determine the Accept header
         let httpHeaderAccepts: string[] = [
-            'application/xml'
+            'application/xml',
             'application/json'
         ];
         const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -247,7 +243,6 @@ export class UserService {
         // to determine the Content-Type header
         const consumes: string[] = [
         ];
-
         return this.httpClient.get<User>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
             {
                 withCredentials: this.configuration.withCredentials,
@@ -286,7 +281,7 @@ export class UserService {
 
         // to determine the Accept header
         let httpHeaderAccepts: string[] = [
-            'application/xml'
+            'application/xml',
             'application/json'
         ];
         const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -297,7 +292,6 @@ export class UserService {
         // to determine the Content-Type header
         const consumes: string[] = [
         ];
-
         return this.httpClient.get<string>(`${this.basePath}/user/login`,
             {
                 params: queryParameters,
@@ -333,7 +327,6 @@ export class UserService {
         // to determine the Content-Type header
         const consumes: string[] = [
         ];
-
         return this.httpClient.get<any>(`${this.basePath}/user/logout`,
             {
                 withCredentials: this.configuration.withCredentials,
@@ -383,7 +376,6 @@ export class UserService {
         if (httpContentTypeSelected != undefined) {
             headers['Content-Type'] = httpContentTypeSelected;
         }
-
         return this.httpClient.put<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
             user,
             {
-- 
GitLab