Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit f773ac7

Browse files
authored
[typescript-angular] Support body for DELETE requests (#13457)
* [typescript-angular] Update api template to use HttpClient#request instead of its http-method-specific wrappers * update expected output for integration tests * regenerate samples
1 parent c4a3866 commit f773ac7

File tree

30 files changed

+262
-259
lines changed

30 files changed

+262
-259
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,19 @@ export class {{classname}} {
366366

367367
{{/isResponseFile}}
368368
let localVarPath = `{{{path}}}`;
369-
return this.httpClient.{{httpMethod}}{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}(`${this.configuration.basePath}${localVarPath}`,{{#isBodyAllowed}}
370-
{{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}{{#hasFormParams}}localVarConvertFormParamsToString ? localVarFormParams.toString() : localVarFormParams{{/hasFormParams}}{{^hasFormParams}}null{{/hasFormParams}}{{/bodyParam}},{{/isBodyAllowed}}
369+
return this.httpClient.request{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}('{{httpMethod}}', `${this.configuration.basePath}${localVarPath}`,
371370
{
372371
{{#httpContextInOptions}}
373372
context: localVarHttpContext,
374373
{{/httpContextInOptions}}
374+
{{#bodyParam}}
375+
body: {{paramName}},
376+
{{/bodyParam}}
377+
{{^bodyParam}}
378+
{{#hasFormParams}}
379+
body: localVarConvertFormParamsToString ? localVarFormParams.toString() : localVarFormParams,
380+
{{/hasFormParams}}
381+
{{/bodyParam}}
375382
{{#hasQueryParamsOrAuth}}
376383
params: localVarQueryParameters,
377384
{{/hasQueryParamsOrAuth}}

modules/openapi-generator/src/test/resources/integrationtests/typescript/additional-properties-expected/api/user.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ export class UserService {
142142
}
143143

144144
let localVarPath = `/user`;
145-
return this.httpClient.post<any>(`${this.configuration.basePath}${localVarPath}`,
146-
body,
145+
return this.httpClient.request<any>('post', `${this.configuration.basePath}${localVarPath}`,
147146
{
148147
context: localVarHttpContext,
148+
body: body,
149149
responseType: <any>responseType_,
150150
withCredentials: this.configuration.withCredentials,
151151
headers: localVarHeaders,
@@ -206,10 +206,10 @@ export class UserService {
206206
}
207207

208208
let localVarPath = `/user`;
209-
return this.httpClient.put<any>(`${this.configuration.basePath}${localVarPath}`,
210-
body,
209+
return this.httpClient.request<any>('put', `${this.configuration.basePath}${localVarPath}`,
211210
{
212211
context: localVarHttpContext,
212+
body: body,
213213
responseType: <any>responseType_,
214214
withCredentials: this.configuration.withCredentials,
215215
headers: localVarHeaders,

modules/openapi-generator/src/test/resources/integrationtests/typescript/array-and-object-expected/api/project.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ export class ProjectService {
185185
}
186186

187187
let localVarPath = `/projects`;
188-
return this.httpClient.post<ProjectEntity>(`${this.configuration.basePath}${localVarPath}`,
189-
localVarConvertFormParamsToString ? localVarFormParams.toString() : localVarFormParams,
188+
return this.httpClient.request<ProjectEntity>('post', `${this.configuration.basePath}${localVarPath}`,
190189
{
191190
context: localVarHttpContext,
191+
body: localVarConvertFormParamsToString ? localVarFormParams.toString() : localVarFormParams,
192192
responseType: <any>responseType_,
193193
withCredentials: this.configuration.withCredentials,
194194
headers: localVarHeaders,
@@ -245,7 +245,7 @@ export class ProjectService {
245245
}
246246

247247
let localVarPath = `/projects/${this.configuration.encodeParam({name: "id", value: id, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int32"})}`;
248-
return this.httpClient.delete<any>(`${this.configuration.basePath}${localVarPath}`,
248+
return this.httpClient.request<any>('delete', `${this.configuration.basePath}${localVarPath}`,
249249
{
250250
context: localVarHttpContext,
251251
responseType: <any>responseType_,
@@ -304,7 +304,7 @@ export class ProjectService {
304304
}
305305

306306
let localVarPath = `/projects/${this.configuration.encodeParam({name: "id", value: id, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int32"})}`;
307-
return this.httpClient.get<ProjectEntity>(`${this.configuration.basePath}${localVarPath}`,
307+
return this.httpClient.request<ProjectEntity>('get', `${this.configuration.basePath}${localVarPath}`,
308308
{
309309
context: localVarHttpContext,
310310
responseType: <any>responseType_,
@@ -401,7 +401,7 @@ export class ProjectService {
401401
}
402402

403403
let localVarPath = `/projects`;
404-
return this.httpClient.get<ProjectList>(`${this.configuration.basePath}${localVarPath}`,
404+
return this.httpClient.request<ProjectList>('get', `${this.configuration.basePath}${localVarPath}`,
405405
{
406406
context: localVarHttpContext,
407407
params: localVarQueryParameters,
@@ -503,10 +503,10 @@ export class ProjectService {
503503
}
504504

505505
let localVarPath = `/projects/${this.configuration.encodeParam({name: "id", value: id, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int32"})}`;
506-
return this.httpClient.put<ProjectEntity>(`${this.configuration.basePath}${localVarPath}`,
507-
localVarConvertFormParamsToString ? localVarFormParams.toString() : localVarFormParams,
506+
return this.httpClient.request<ProjectEntity>('put', `${this.configuration.basePath}${localVarPath}`,
508507
{
509508
context: localVarHttpContext,
509+
body: localVarConvertFormParamsToString ? localVarFormParams.toString() : localVarFormParams,
510510
responseType: <any>responseType_,
511511
withCredentials: this.configuration.withCredentials,
512512
headers: localVarHeaders,

modules/openapi-generator/src/test/resources/integrationtests/typescript/custom-path-params-expected/api/matrixParams.service.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ export class MatrixParamsService {
132132
}
133133

134134
let localVarPath = `/complexMatrixParamExploded${this.configuration.encodeParam({name: "matrixParamExploded", value: matrixParamExploded, in: "path", style: "matrix", explode: true, dataType: "ComplexParams", dataFormat: undefined})}`;
135-
return this.httpClient.put<any>(`${this.configuration.basePath}${localVarPath}`,
136-
null,
135+
return this.httpClient.request<any>('put', `${this.configuration.basePath}${localVarPath}`,
137136
{
138137
context: localVarHttpContext,
139138
responseType: <any>responseType_,
@@ -186,8 +185,7 @@ export class MatrixParamsService {
186185
}
187186

188187
let localVarPath = `/complexMatrixParamFlat${this.configuration.encodeParam({name: "matrixParamFlat", value: matrixParamFlat, in: "path", style: "matrix", explode: false, dataType: "ComplexParams", dataFormat: undefined})}`;
189-
return this.httpClient.put<any>(`${this.configuration.basePath}${localVarPath}`,
190-
null,
188+
return this.httpClient.request<any>('put', `${this.configuration.basePath}${localVarPath}`,
191189
{
192190
context: localVarHttpContext,
193191
responseType: <any>responseType_,
@@ -240,8 +238,7 @@ export class MatrixParamsService {
240238
}
241239

242240
let localVarPath = `/plainMatrixParamFlat${this.configuration.encodeParam({name: "plainParamFlat", value: plainParamFlat, in: "path", style: "matrix", explode: false, dataType: "string", dataFormat: undefined})}`;
243-
return this.httpClient.put<any>(`${this.configuration.basePath}${localVarPath}`,
244-
null,
241+
return this.httpClient.request<any>('put', `${this.configuration.basePath}${localVarPath}`,
245242
{
246243
context: localVarHttpContext,
247244
responseType: <any>responseType_,
@@ -294,8 +291,7 @@ export class MatrixParamsService {
294291
}
295292

296293
let localVarPath = `/date-timeMatrixParamFlat${this.configuration.encodeParam({name: "dateTimeParamFlat", value: dateTimeParamFlat, in: "path", style: "matrix", explode: false, dataType: "string", dataFormat: "date-time"})}`;
297-
return this.httpClient.put<any>(`${this.configuration.basePath}${localVarPath}`,
298-
null,
294+
return this.httpClient.request<any>('put', `${this.configuration.basePath}${localVarPath}`,
299295
{
300296
context: localVarHttpContext,
301297
responseType: <any>responseType_,

modules/openapi-generator/src/test/resources/integrationtests/typescript/petstore-expected/api/pet.service.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ export class PetService {
168168
}
169169

170170
let localVarPath = `/pet`;
171-
return this.httpClient.post<any>(`${this.configuration.basePath}${localVarPath}`,
172-
body,
171+
return this.httpClient.request<any>('post', `${this.configuration.basePath}${localVarPath}`,
173172
{
174173
context: localVarHttpContext,
174+
body: body,
175175
responseType: <any>responseType_,
176176
withCredentials: this.configuration.withCredentials,
177177
headers: localVarHeaders,
@@ -237,7 +237,7 @@ export class PetService {
237237
}
238238

239239
let localVarPath = `/pet/${this.configuration.encodeParam({name: "petId", value: petId, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int64"})}`;
240-
return this.httpClient.delete<any>(`${this.configuration.basePath}${localVarPath}`,
240+
return this.httpClient.request<any>('delete', `${this.configuration.basePath}${localVarPath}`,
241241
{
242242
context: localVarHttpContext,
243243
responseType: <any>responseType_,
@@ -310,7 +310,7 @@ export class PetService {
310310
}
311311

312312
let localVarPath = `/pet/findByStatus`;
313-
return this.httpClient.get<Array<Pet>>(`${this.configuration.basePath}${localVarPath}`,
313+
return this.httpClient.request<Array<Pet>>('get', `${this.configuration.basePath}${localVarPath}`,
314314
{
315315
context: localVarHttpContext,
316316
params: localVarQueryParameters,
@@ -384,7 +384,7 @@ export class PetService {
384384
}
385385

386386
let localVarPath = `/pet/findByTags`;
387-
return this.httpClient.get<Array<Pet>>(`${this.configuration.basePath}${localVarPath}`,
387+
return this.httpClient.request<Array<Pet>>('get', `${this.configuration.basePath}${localVarPath}`,
388388
{
389389
context: localVarHttpContext,
390390
params: localVarQueryParameters,
@@ -452,7 +452,7 @@ export class PetService {
452452
}
453453

454454
let localVarPath = `/pet/${this.configuration.encodeParam({name: "petId", value: petId, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int64"})}`;
455-
return this.httpClient.get<Pet>(`${this.configuration.basePath}${localVarPath}`,
455+
return this.httpClient.request<Pet>('get', `${this.configuration.basePath}${localVarPath}`,
456456
{
457457
context: localVarHttpContext,
458458
responseType: <any>responseType_,
@@ -526,10 +526,10 @@ export class PetService {
526526
}
527527

528528
let localVarPath = `/pet`;
529-
return this.httpClient.put<any>(`${this.configuration.basePath}${localVarPath}`,
530-
body,
529+
return this.httpClient.request<any>('put', `${this.configuration.basePath}${localVarPath}`,
531530
{
532531
context: localVarHttpContext,
532+
body: body,
533533
responseType: <any>responseType_,
534534
withCredentials: this.configuration.withCredentials,
535535
headers: localVarHeaders,
@@ -615,10 +615,10 @@ export class PetService {
615615
}
616616

617617
let localVarPath = `/pet/${this.configuration.encodeParam({name: "petId", value: petId, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int64"})}`;
618-
return this.httpClient.post<any>(`${this.configuration.basePath}${localVarPath}`,
619-
localVarConvertFormParamsToString ? localVarFormParams.toString() : localVarFormParams,
618+
return this.httpClient.request<any>('post', `${this.configuration.basePath}${localVarPath}`,
620619
{
621620
context: localVarHttpContext,
621+
body: localVarConvertFormParamsToString ? localVarFormParams.toString() : localVarFormParams,
622622
responseType: <any>responseType_,
623623
withCredentials: this.configuration.withCredentials,
624624
headers: localVarHeaders,
@@ -708,10 +708,10 @@ export class PetService {
708708
}
709709

710710
let localVarPath = `/pet/${this.configuration.encodeParam({name: "petId", value: petId, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int64"})}/uploadImage`;
711-
return this.httpClient.post<ApiResponse>(`${this.configuration.basePath}${localVarPath}`,
712-
localVarConvertFormParamsToString ? localVarFormParams.toString() : localVarFormParams,
711+
return this.httpClient.request<ApiResponse>('post', `${this.configuration.basePath}${localVarPath}`,
713712
{
714713
context: localVarHttpContext,
714+
body: localVarConvertFormParamsToString ? localVarFormParams.toString() : localVarFormParams,
715715
responseType: <any>responseType_,
716716
withCredentials: this.configuration.withCredentials,
717717
headers: localVarHeaders,

modules/openapi-generator/src/test/resources/integrationtests/typescript/petstore-expected/api/store.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class StoreService {
137137
}
138138

139139
let localVarPath = `/store/order/${this.configuration.encodeParam({name: "orderId", value: orderId, in: "path", style: "simple", explode: false, dataType: "string", dataFormat: undefined})}`;
140-
return this.httpClient.delete<any>(`${this.configuration.basePath}${localVarPath}`,
140+
return this.httpClient.request<any>('delete', `${this.configuration.basePath}${localVarPath}`,
141141
{
142142
context: localVarHttpContext,
143143
responseType: <any>responseType_,
@@ -199,7 +199,7 @@ export class StoreService {
199199
}
200200

201201
let localVarPath = `/store/inventory`;
202-
return this.httpClient.get<{ [key: string]: number; }>(`${this.configuration.basePath}${localVarPath}`,
202+
return this.httpClient.request<{ [key: string]: number; }>('get', `${this.configuration.basePath}${localVarPath}`,
203203
{
204204
context: localVarHttpContext,
205205
responseType: <any>responseType_,
@@ -259,7 +259,7 @@ export class StoreService {
259259
}
260260

261261
let localVarPath = `/store/order/${this.configuration.encodeParam({name: "orderId", value: orderId, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int64"})}`;
262-
return this.httpClient.get<Order>(`${this.configuration.basePath}${localVarPath}`,
262+
return this.httpClient.request<Order>('get', `${this.configuration.basePath}${localVarPath}`,
263263
{
264264
context: localVarHttpContext,
265265
responseType: <any>responseType_,
@@ -326,10 +326,10 @@ export class StoreService {
326326
}
327327

328328
let localVarPath = `/store/order`;
329-
return this.httpClient.post<Order>(`${this.configuration.basePath}${localVarPath}`,
330-
body,
329+
return this.httpClient.request<Order>('post', `${this.configuration.basePath}${localVarPath}`,
331330
{
332331
context: localVarHttpContext,
332+
body: body,
333333
responseType: <any>responseType_,
334334
withCredentials: this.configuration.withCredentials,
335335
headers: localVarHeaders,

modules/openapi-generator/src/test/resources/integrationtests/typescript/petstore-expected/api/user.service.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ export class UserService {
145145
}
146146

147147
let localVarPath = `/user`;
148-
return this.httpClient.post<any>(`${this.configuration.basePath}${localVarPath}`,
149-
body,
148+
return this.httpClient.request<any>('post', `${this.configuration.basePath}${localVarPath}`,
150149
{
151150
context: localVarHttpContext,
151+
body: body,
152152
responseType: <any>responseType_,
153153
withCredentials: this.configuration.withCredentials,
154154
headers: localVarHeaders,
@@ -211,10 +211,10 @@ export class UserService {
211211
}
212212

213213
let localVarPath = `/user/createWithArray`;
214-
return this.httpClient.post<any>(`${this.configuration.basePath}${localVarPath}`,
215-
body,
214+
return this.httpClient.request<any>('post', `${this.configuration.basePath}${localVarPath}`,
216215
{
217216
context: localVarHttpContext,
217+
body: body,
218218
responseType: <any>responseType_,
219219
withCredentials: this.configuration.withCredentials,
220220
headers: localVarHeaders,
@@ -277,10 +277,10 @@ export class UserService {
277277
}
278278

279279
let localVarPath = `/user/createWithList`;
280-
return this.httpClient.post<any>(`${this.configuration.basePath}${localVarPath}`,
281-
body,
280+
return this.httpClient.request<any>('post', `${this.configuration.basePath}${localVarPath}`,
282281
{
283282
context: localVarHttpContext,
283+
body: body,
284284
responseType: <any>responseType_,
285285
withCredentials: this.configuration.withCredentials,
286286
headers: localVarHeaders,
@@ -336,7 +336,7 @@ export class UserService {
336336
}
337337

338338
let localVarPath = `/user/${this.configuration.encodeParam({name: "username", value: username, in: "path", style: "simple", explode: false, dataType: "string", dataFormat: undefined})}`;
339-
return this.httpClient.delete<any>(`${this.configuration.basePath}${localVarPath}`,
339+
return this.httpClient.request<any>('delete', `${this.configuration.basePath}${localVarPath}`,
340340
{
341341
context: localVarHttpContext,
342342
responseType: <any>responseType_,
@@ -395,7 +395,7 @@ export class UserService {
395395
}
396396

397397
let localVarPath = `/user/${this.configuration.encodeParam({name: "username", value: username, in: "path", style: "simple", explode: false, dataType: "string", dataFormat: undefined})}`;
398-
return this.httpClient.get<User>(`${this.configuration.basePath}${localVarPath}`,
398+
return this.httpClient.request<User>('get', `${this.configuration.basePath}${localVarPath}`,
399399
{
400400
context: localVarHttpContext,
401401
responseType: <any>responseType_,
@@ -468,7 +468,7 @@ export class UserService {
468468
}
469469

470470
let localVarPath = `/user/login`;
471-
return this.httpClient.get<string>(`${this.configuration.basePath}${localVarPath}`,
471+
return this.httpClient.request<string>('get', `${this.configuration.basePath}${localVarPath}`,
472472
{
473473
context: localVarHttpContext,
474474
params: localVarQueryParameters,
@@ -522,7 +522,7 @@ export class UserService {
522522
}
523523

524524
let localVarPath = `/user/logout`;
525-
return this.httpClient.get<any>(`${this.configuration.basePath}${localVarPath}`,
525+
return this.httpClient.request<any>('get', `${this.configuration.basePath}${localVarPath}`,
526526
{
527527
context: localVarHttpContext,
528528
responseType: <any>responseType_,
@@ -592,10 +592,10 @@ export class UserService {
592592
}
593593

594594
let localVarPath = `/user/${this.configuration.encodeParam({name: "username", value: username, in: "path", style: "simple", explode: false, dataType: "string", dataFormat: undefined})}`;
595-
return this.httpClient.put<any>(`${this.configuration.basePath}${localVarPath}`,
596-
body,
595+
return this.httpClient.request<any>('put', `${this.configuration.basePath}${localVarPath}`,
597596
{
598597
context: localVarHttpContext,
598+
body: body,
599599
responseType: <any>responseType_,
600600
withCredentials: this.configuration.withCredentials,
601601
headers: localVarHeaders,

0 commit comments

Comments
 (0)