Skip to content

Commit c33b5a6

Browse files
authored
minor fixes to ts nestjs generator (#8622)
1 parent e6cee8e commit c33b5a6

5 files changed

Lines changed: 22 additions & 35 deletions

File tree

bin/configs/typescript-nestjs-v6-provided-in-root.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
generatorName: typescript-nestjs
22
outputDir: samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default
33
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/typescript-nestjs
45
additionalProperties:
56
nestVersion: 6.0.0
67
"npmName": "@openapitools/typescript-nestjs-petstore"

modules/openapi-generator/src/main/resources/typescript-nestjs/api.service.mustache

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class {{classname}} {
107107
{{/isListContainer}}
108108
{{^isListContainer}}
109109
if ({{paramName}} !== undefined && {{paramName}} !== null) {
110-
headers['{{baseName}}'] String({{paramName}});
110+
headers['{{baseName}}'] = String({{paramName}});
111111
}
112112
{{/isListContainer}}
113113
{{/headerParams}}
@@ -147,7 +147,7 @@ export class {{classname}} {
147147
// to determine the Accept header
148148
let httpHeaderAccepts: string[] = [
149149
{{#produces}}
150-
'{{{mediaType}}}'{{#hasMore}},{{/hasMore}}
150+
'{{{mediaType}}}'{{^-last}},{{/-last}}
151151
{{/produces}}
152152
];
153153
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -158,7 +158,7 @@ export class {{classname}} {
158158
// to determine the Content-Type header
159159
const consumes: string[] = [
160160
{{#consumes}}
161-
'{{{mediaType}}}'{{#hasMore}},{{/hasMore}}
161+
'{{{mediaType}}}'{{^-last}},{{/-last}}
162162
{{/consumes}}
163163
];
164164
{{#bodyParam}}
@@ -167,15 +167,16 @@ export class {{classname}} {
167167
headers['Content-Type'] = httpContentTypeSelected;
168168
}
169169
{{/bodyParam}}
170-
171170
{{#hasFormParams}}
171+
172172
const canConsumeForm = this.canConsumeForm(consumes);
173173

174174
let formParams: { append(param: string, value: any): void; };
175175
let useForm = false;
176176
let convertFormParamsToString = false;
177177
{{#formParams}}
178178
{{#isFile}}
179+
179180
// use FormData to transmit files using content-type "multipart/form-data"
180181
// see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data
181182
useForm = canConsumeForm;
@@ -186,8 +187,8 @@ export class {{classname}} {
186187
} else {
187188
// formParams = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()});
188189
}
189-
190190
{{#formParams}}
191+
191192
{{#isListContainer}}
192193
if ({{paramName}}) {
193194
{{#isCollectionFormatMulti}}

samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/pet.service.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class PetService {
6767

6868
// to determine the Accept header
6969
let httpHeaderAccepts: string[] = [
70-
'application/xml'
70+
'application/xml',
7171
'application/json'
7272
];
7373
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -77,14 +77,13 @@ export class PetService {
7777

7878
// to determine the Content-Type header
7979
const consumes: string[] = [
80-
'application/json'
80+
'application/json',
8181
'application/xml'
8282
];
8383
const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
8484
if (httpContentTypeSelected != undefined) {
8585
headers['Content-Type'] = httpContentTypeSelected;
8686
}
87-
8887
return this.httpClient.post<Pet>(`${this.basePath}/pet`,
8988
pet,
9089
{
@@ -111,7 +110,7 @@ export class PetService {
111110

112111
let headers = this.defaultHeaders;
113112
if (apiKey !== undefined && apiKey !== null) {
114-
headers['api_key'] String(apiKey);
113+
headers['api_key'] = String(apiKey);
115114
}
116115

117116
// authentication (petstore_auth) required
@@ -133,7 +132,6 @@ export class PetService {
133132
// to determine the Content-Type header
134133
const consumes: string[] = [
135134
];
136-
137135
return this.httpClient.delete<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
138136
{
139137
withCredentials: this.configuration.withCredentials,
@@ -172,7 +170,7 @@ export class PetService {
172170

173171
// to determine the Accept header
174172
let httpHeaderAccepts: string[] = [
175-
'application/xml'
173+
'application/xml',
176174
'application/json'
177175
];
178176
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -183,7 +181,6 @@ export class PetService {
183181
// to determine the Content-Type header
184182
const consumes: string[] = [
185183
];
186-
187184
return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByStatus`,
188185
{
189186
params: queryParameters,
@@ -223,7 +220,7 @@ export class PetService {
223220

224221
// to determine the Accept header
225222
let httpHeaderAccepts: string[] = [
226-
'application/xml'
223+
'application/xml',
227224
'application/json'
228225
];
229226
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -234,7 +231,6 @@ export class PetService {
234231
// to determine the Content-Type header
235232
const consumes: string[] = [
236233
];
237-
238234
return this.httpClient.get<Array<Pet>>(`${this.basePath}/pet/findByTags`,
239235
{
240236
params: queryParameters,
@@ -266,7 +262,7 @@ export class PetService {
266262

267263
// to determine the Accept header
268264
let httpHeaderAccepts: string[] = [
269-
'application/xml'
265+
'application/xml',
270266
'application/json'
271267
];
272268
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -277,7 +273,6 @@ export class PetService {
277273
// to determine the Content-Type header
278274
const consumes: string[] = [
279275
];
280-
281276
return this.httpClient.get<Pet>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
282277
{
283278
withCredentials: this.configuration.withCredentials,
@@ -311,7 +306,7 @@ export class PetService {
311306

312307
// to determine the Accept header
313308
let httpHeaderAccepts: string[] = [
314-
'application/xml'
309+
'application/xml',
315310
'application/json'
316311
];
317312
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -321,14 +316,13 @@ export class PetService {
321316

322317
// to determine the Content-Type header
323318
const consumes: string[] = [
324-
'application/json'
319+
'application/json',
325320
'application/xml'
326321
];
327322
const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
328323
if (httpContentTypeSelected != undefined) {
329324
headers['Content-Type'] = httpContentTypeSelected;
330325
}
331-
332326
return this.httpClient.put<Pet>(`${this.basePath}/pet`,
333327
pet,
334328
{
@@ -392,6 +386,7 @@ export class PetService {
392386
if (name !== undefined) {
393387
formParams.append('name', <any>name);
394388
}
389+
395390
if (status !== undefined) {
396391
formParams.append('status', <any>status);
397392
}
@@ -451,6 +446,7 @@ export class PetService {
451446
let formParams: { append(param: string, value: any): void; };
452447
let useForm = false;
453448
let convertFormParamsToString = false;
449+
454450
// use FormData to transmit files using content-type "multipart/form-data"
455451
// see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data
456452
useForm = canConsumeForm;
@@ -463,6 +459,7 @@ export class PetService {
463459
if (additionalMetadata !== undefined) {
464460
formParams.append('additionalMetadata', <any>additionalMetadata);
465461
}
462+
466463
if (file !== undefined) {
467464
formParams.append('file', <any>file);
468465
}

samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/store.service.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export class StoreService {
6767
// to determine the Content-Type header
6868
const consumes: string[] = [
6969
];
70-
7170
return this.httpClient.delete<any>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
7271
{
7372
withCredentials: this.configuration.withCredentials,
@@ -103,7 +102,6 @@ export class StoreService {
103102
// to determine the Content-Type header
104103
const consumes: string[] = [
105104
];
106-
107105
return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`,
108106
{
109107
withCredentials: this.configuration.withCredentials,
@@ -129,7 +127,7 @@ export class StoreService {
129127

130128
// to determine the Accept header
131129
let httpHeaderAccepts: string[] = [
132-
'application/xml'
130+
'application/xml',
133131
'application/json'
134132
];
135133
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -140,7 +138,6 @@ export class StoreService {
140138
// to determine the Content-Type header
141139
const consumes: string[] = [
142140
];
143-
144141
return this.httpClient.get<Order>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
145142
{
146143
withCredentials: this.configuration.withCredentials,
@@ -166,7 +163,7 @@ export class StoreService {
166163

167164
// to determine the Accept header
168165
let httpHeaderAccepts: string[] = [
169-
'application/xml'
166+
'application/xml',
170167
'application/json'
171168
];
172169
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -182,7 +179,6 @@ export class StoreService {
182179
if (httpContentTypeSelected != undefined) {
183180
headers['Content-Type'] = httpContentTypeSelected;
184181
}
185-
186182
return this.httpClient.post<Order>(`${this.basePath}/store/order`,
187183
order,
188184
{

samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/api/user.service.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export class UserService {
7777
if (httpContentTypeSelected != undefined) {
7878
headers['Content-Type'] = httpContentTypeSelected;
7979
}
80-
8180
return this.httpClient.post<any>(`${this.basePath}/user`,
8281
user,
8382
{
@@ -123,7 +122,6 @@ export class UserService {
123122
if (httpContentTypeSelected != undefined) {
124123
headers['Content-Type'] = httpContentTypeSelected;
125124
}
126-
127125
return this.httpClient.post<any>(`${this.basePath}/user/createWithArray`,
128126
user,
129127
{
@@ -169,7 +167,6 @@ export class UserService {
169167
if (httpContentTypeSelected != undefined) {
170168
headers['Content-Type'] = httpContentTypeSelected;
171169
}
172-
173170
return this.httpClient.post<any>(`${this.basePath}/user/createWithList`,
174171
user,
175172
{
@@ -210,7 +207,6 @@ export class UserService {
210207
// to determine the Content-Type header
211208
const consumes: string[] = [
212209
];
213-
214210
return this.httpClient.delete<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
215211
{
216212
withCredentials: this.configuration.withCredentials,
@@ -236,7 +232,7 @@ export class UserService {
236232

237233
// to determine the Accept header
238234
let httpHeaderAccepts: string[] = [
239-
'application/xml'
235+
'application/xml',
240236
'application/json'
241237
];
242238
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -247,7 +243,6 @@ export class UserService {
247243
// to determine the Content-Type header
248244
const consumes: string[] = [
249245
];
250-
251246
return this.httpClient.get<User>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
252247
{
253248
withCredentials: this.configuration.withCredentials,
@@ -286,7 +281,7 @@ export class UserService {
286281

287282
// to determine the Accept header
288283
let httpHeaderAccepts: string[] = [
289-
'application/xml'
284+
'application/xml',
290285
'application/json'
291286
];
292287
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
@@ -297,7 +292,6 @@ export class UserService {
297292
// to determine the Content-Type header
298293
const consumes: string[] = [
299294
];
300-
301295
return this.httpClient.get<string>(`${this.basePath}/user/login`,
302296
{
303297
params: queryParameters,
@@ -333,7 +327,6 @@ export class UserService {
333327
// to determine the Content-Type header
334328
const consumes: string[] = [
335329
];
336-
337330
return this.httpClient.get<any>(`${this.basePath}/user/logout`,
338331
{
339332
withCredentials: this.configuration.withCredentials,
@@ -383,7 +376,6 @@ export class UserService {
383376
if (httpContentTypeSelected != undefined) {
384377
headers['Content-Type'] = httpContentTypeSelected;
385378
}
386-
387379
return this.httpClient.put<any>(`${this.basePath}/user/${encodeURIComponent(String(username))}`,
388380
user,
389381
{

0 commit comments

Comments
 (0)