Skip to content

Commit 28783ab

Browse files
committed
feat: add options to service functions
1 parent 06f0b68 commit 28783ab

File tree

7 files changed

+214
-132
lines changed

7 files changed

+214
-132
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { HttpService } from '@nestjs/axios';
88
{{^useAxiosHttpModule}}
99
import { HttpService, Injectable, Optional } from '@nestjs/common';
1010
{{/useAxiosHttpModule}}
11-
import { AxiosResponse } from 'axios';
11+
import { AxiosResponse, RawAxiosRequestConfig } from 'axios';
1212
import { Observable, from, of, switchMap } from 'rxjs';
1313
{{#imports}}
1414
import { {{classname}} } from '../{{filename}}';
@@ -93,14 +93,15 @@ export class {{classname}} {
9393
{{/allParams}}* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
9494
* @param reportProgress flag to report request and response progress.
9595
{{/useSingleRequestParameter}}
96+
* @param {*} [options] Override http request option.
9697
*/
9798
{{#useSingleRequestParameter}}
98-
public {{nickname}}({{#allParams.0}}requestParameters: {{classname}}{{operationIdCamelCase}}Request, {{/allParams.0}}): Observable<AxiosResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>>;
99-
public {{nickname}}({{#allParams.0}}requestParameters: {{classname}}{{operationIdCamelCase}}Request, {{/allParams.0}}): Observable<any> {
99+
public {{nickname}}({{#allParams.0}}requestParameters: {{classname}}{{operationIdCamelCase}}Request, {{/allParams.0}}options?: RawAxiosRequestConfig): Observable<AxiosResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>>;
100+
public {{nickname}}({{#allParams.0}}requestParameters: {{classname}}{{operationIdCamelCase}}Request, {{/allParams.0}}options?: RawAxiosRequestConfig): Observable<any> {
100101
{{/useSingleRequestParameter}}
101102
{{^useSingleRequestParameter}}
102-
public {{nickname}}({{#allParams}}{{^isConstEnumParam}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/isConstEnumParam}}{{/allParams}}): Observable<AxiosResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>>;
103-
public {{nickname}}({{#allParams}}{{^isConstEnumParam}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/isConstEnumParam}}{{/allParams}}): Observable<any> {
103+
public {{nickname}}({{#allParams}}{{^isConstEnumParam}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/isConstEnumParam}}{{/allParams}}options?: RawAxiosRequestConfig): Observable<AxiosResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>>;
104+
public {{nickname}}({{#allParams}}{{^isConstEnumParam}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/isConstEnumParam}}{{/allParams}}options?: RawAxiosRequestConfig): Observable<any> {
104105
{{/useSingleRequestParameter}}
105106
{{#allParams.0}}
106107
{{#useSingleRequestParameter}}
@@ -291,7 +292,8 @@ export class {{classname}} {
291292
responseType: "blob",
292293
{{/isResponseFile}}
293294
withCredentials: this.configuration.withCredentials,
294-
headers: headers
295+
headers: {...headers, ...options?.headers},
296+
...options,
295297
}
296298
);
297299
})

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

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/* tslint:disable:no-unused-variable member-ordering */
1313

1414
import { HttpService, Injectable, Optional } from '@nestjs/common';
15-
import { AxiosResponse } from 'axios';
15+
import { AxiosResponse, RawAxiosRequestConfig } from 'axios';
1616
import { Observable, from, of, switchMap } from 'rxjs';
1717
import { ApiResponse } from '../model/apiResponse';
1818
import { Pet } from '../model/pet';
@@ -49,9 +49,10 @@ export class PetService {
4949
* @param pet Pet object that needs to be added to the store
5050
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
5151
* @param reportProgress flag to report request and response progress.
52+
* @param {*} [options] Override http request option.
5253
*/
53-
public addPet(pet: Pet, ): Observable<AxiosResponse<Pet>>;
54-
public addPet(pet: Pet, ): Observable<any> {
54+
public addPet(pet: Pet, options?: RawAxiosRequestConfig): Observable<AxiosResponse<Pet>>;
55+
public addPet(pet: Pet, options?: RawAxiosRequestConfig): Observable<any> {
5556
if (pet === null || pet === undefined) {
5657
throw new Error('Required parameter pet was null or undefined when calling addPet.');
5758
}
@@ -96,7 +97,8 @@ export class PetService {
9697
pet,
9798
{
9899
withCredentials: this.configuration.withCredentials,
99-
headers: headers
100+
headers: {...headers, ...options?.headers},
101+
...options,
100102
}
101103
);
102104
})
@@ -109,9 +111,10 @@ export class PetService {
109111
* @param apiKey
110112
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
111113
* @param reportProgress flag to report request and response progress.
114+
* @param {*} [options] Override http request option.
112115
*/
113-
public deletePet(petId: number, apiKey?: string, ): Observable<AxiosResponse<any>>;
114-
public deletePet(petId: number, apiKey?: string, ): Observable<any> {
116+
public deletePet(petId: number, apiKey?: string, options?: RawAxiosRequestConfig): Observable<AxiosResponse<any>>;
117+
public deletePet(petId: number, apiKey?: string, options?: RawAxiosRequestConfig): Observable<any> {
115118
if (petId === null || petId === undefined) {
116119
throw new Error('Required parameter petId was null or undefined when calling deletePet.');
117120
}
@@ -150,7 +153,8 @@ export class PetService {
150153
return this.httpClient.delete<any>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
151154
{
152155
withCredentials: this.configuration.withCredentials,
153-
headers: headers
156+
headers: {...headers, ...options?.headers},
157+
...options,
154158
}
155159
);
156160
})
@@ -162,9 +166,10 @@ export class PetService {
162166
* @param status Status values that need to be considered for filter
163167
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
164168
* @param reportProgress flag to report request and response progress.
169+
* @param {*} [options] Override http request option.
165170
*/
166-
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, ): Observable<AxiosResponse<Array<Pet>>>;
167-
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, ): Observable<any> {
171+
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, options?: RawAxiosRequestConfig): Observable<AxiosResponse<Array<Pet>>>;
172+
public findPetsByStatus(status: Array<'available' | 'pending' | 'sold'>, options?: RawAxiosRequestConfig): Observable<any> {
168173
if (status === null || status === undefined) {
169174
throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.');
170175
}
@@ -208,7 +213,8 @@ export class PetService {
208213
{
209214
params: queryParameters,
210215
withCredentials: this.configuration.withCredentials,
211-
headers: headers
216+
headers: {...headers, ...options?.headers},
217+
...options,
212218
}
213219
);
214220
})
@@ -220,9 +226,10 @@ export class PetService {
220226
* @param tags Tags to filter by
221227
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
222228
* @param reportProgress flag to report request and response progress.
229+
* @param {*} [options] Override http request option.
223230
*/
224-
public findPetsByTags(tags: Array<string>, ): Observable<AxiosResponse<Array<Pet>>>;
225-
public findPetsByTags(tags: Array<string>, ): Observable<any> {
231+
public findPetsByTags(tags: Array<string>, options?: RawAxiosRequestConfig): Observable<AxiosResponse<Array<Pet>>>;
232+
public findPetsByTags(tags: Array<string>, options?: RawAxiosRequestConfig): Observable<any> {
226233
if (tags === null || tags === undefined) {
227234
throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.');
228235
}
@@ -266,7 +273,8 @@ export class PetService {
266273
{
267274
params: queryParameters,
268275
withCredentials: this.configuration.withCredentials,
269-
headers: headers
276+
headers: {...headers, ...options?.headers},
277+
...options,
270278
}
271279
);
272280
})
@@ -278,9 +286,10 @@ export class PetService {
278286
* @param petId ID of pet to return
279287
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
280288
* @param reportProgress flag to report request and response progress.
289+
* @param {*} [options] Override http request option.
281290
*/
282-
public getPetById(petId: number, ): Observable<AxiosResponse<Pet>>;
283-
public getPetById(petId: number, ): Observable<any> {
291+
public getPetById(petId: number, options?: RawAxiosRequestConfig): Observable<AxiosResponse<Pet>>;
292+
public getPetById(petId: number, options?: RawAxiosRequestConfig): Observable<any> {
284293
if (petId === null || petId === undefined) {
285294
throw new Error('Required parameter petId was null or undefined when calling getPetById.');
286295
}
@@ -316,7 +325,8 @@ export class PetService {
316325
return this.httpClient.get<Pet>(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`,
317326
{
318327
withCredentials: this.configuration.withCredentials,
319-
headers: headers
328+
headers: {...headers, ...options?.headers},
329+
...options,
320330
}
321331
);
322332
})
@@ -328,9 +338,10 @@ export class PetService {
328338
* @param pet Pet object that needs to be added to the store
329339
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
330340
* @param reportProgress flag to report request and response progress.
341+
* @param {*} [options] Override http request option.
331342
*/
332-
public updatePet(pet: Pet, ): Observable<AxiosResponse<Pet>>;
333-
public updatePet(pet: Pet, ): Observable<any> {
343+
public updatePet(pet: Pet, options?: RawAxiosRequestConfig): Observable<AxiosResponse<Pet>>;
344+
public updatePet(pet: Pet, options?: RawAxiosRequestConfig): Observable<any> {
334345
if (pet === null || pet === undefined) {
335346
throw new Error('Required parameter pet was null or undefined when calling updatePet.');
336347
}
@@ -375,7 +386,8 @@ export class PetService {
375386
pet,
376387
{
377388
withCredentials: this.configuration.withCredentials,
378-
headers: headers
389+
headers: {...headers, ...options?.headers},
390+
...options,
379391
}
380392
);
381393
})
@@ -389,9 +401,10 @@ export class PetService {
389401
* @param status Updated status of the pet
390402
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
391403
* @param reportProgress flag to report request and response progress.
404+
* @param {*} [options] Override http request option.
392405
*/
393-
public updatePetWithForm(petId: number, name?: string, status?: string, ): Observable<AxiosResponse<any>>;
394-
public updatePetWithForm(petId: number, name?: string, status?: string, ): Observable<any> {
406+
public updatePetWithForm(petId: number, name?: string, status?: string, options?: RawAxiosRequestConfig): Observable<AxiosResponse<any>>;
407+
public updatePetWithForm(petId: number, name?: string, status?: string, options?: RawAxiosRequestConfig): Observable<any> {
395408
if (petId === null || petId === undefined) {
396409
throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.');
397410
}
@@ -449,7 +462,8 @@ export class PetService {
449462
convertFormParamsToString ? formParams!.toString() : formParams!,
450463
{
451464
withCredentials: this.configuration.withCredentials,
452-
headers: headers
465+
headers: {...headers, ...options?.headers},
466+
...options,
453467
}
454468
);
455469
})
@@ -463,9 +477,10 @@ export class PetService {
463477
* @param file file to upload
464478
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
465479
* @param reportProgress flag to report request and response progress.
480+
* @param {*} [options] Override http request option.
466481
*/
467-
public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, ): Observable<AxiosResponse<ApiResponse>>;
468-
public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, ): Observable<any> {
482+
public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, options?: RawAxiosRequestConfig): Observable<AxiosResponse<ApiResponse>>;
483+
public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, options?: RawAxiosRequestConfig): Observable<any> {
469484
if (petId === null || petId === undefined) {
470485
throw new Error('Required parameter petId was null or undefined when calling uploadFile.');
471486
}
@@ -528,7 +543,8 @@ export class PetService {
528543
convertFormParamsToString ? formParams!.toString() : formParams!,
529544
{
530545
withCredentials: this.configuration.withCredentials,
531-
headers: headers
546+
headers: {...headers, ...options?.headers},
547+
...options,
532548
}
533549
);
534550
})

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/* tslint:disable:no-unused-variable member-ordering */
1313

1414
import { HttpService, Injectable, Optional } from '@nestjs/common';
15-
import { AxiosResponse } from 'axios';
15+
import { AxiosResponse, RawAxiosRequestConfig } from 'axios';
1616
import { Observable, from, of, switchMap } from 'rxjs';
1717
import { Order } from '../model/order';
1818
import { Configuration } from '../configuration';
@@ -48,9 +48,10 @@ export class StoreService {
4848
* @param orderId ID of the order that needs to be deleted
4949
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
5050
* @param reportProgress flag to report request and response progress.
51+
* @param {*} [options] Override http request option.
5152
*/
52-
public deleteOrder(orderId: string, ): Observable<AxiosResponse<any>>;
53-
public deleteOrder(orderId: string, ): Observable<any> {
53+
public deleteOrder(orderId: string, options?: RawAxiosRequestConfig): Observable<AxiosResponse<any>>;
54+
public deleteOrder(orderId: string, options?: RawAxiosRequestConfig): Observable<any> {
5455
if (orderId === null || orderId === undefined) {
5556
throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.');
5657
}
@@ -79,7 +80,8 @@ export class StoreService {
7980
return this.httpClient.delete<any>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
8081
{
8182
withCredentials: this.configuration.withCredentials,
82-
headers: headers
83+
headers: {...headers, ...options?.headers},
84+
...options,
8385
}
8486
);
8587
})
@@ -90,9 +92,10 @@ export class StoreService {
9092
* Returns a map of status codes to quantities
9193
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
9294
* @param reportProgress flag to report request and response progress.
95+
* @param {*} [options] Override http request option.
9396
*/
94-
public getInventory(): Observable<AxiosResponse<{ [key: string]: number; }>>;
95-
public getInventory(): Observable<any> {
97+
public getInventory(options?: RawAxiosRequestConfig): Observable<AxiosResponse<{ [key: string]: number; }>>;
98+
public getInventory(options?: RawAxiosRequestConfig): Observable<any> {
9699
let headers = {...this.defaultHeaders};
97100

98101
let accessTokenObservable: Observable<any> = of(null);
@@ -123,7 +126,8 @@ export class StoreService {
123126
return this.httpClient.get<{ [key: string]: number; }>(`${this.basePath}/store/inventory`,
124127
{
125128
withCredentials: this.configuration.withCredentials,
126-
headers: headers
129+
headers: {...headers, ...options?.headers},
130+
...options,
127131
}
128132
);
129133
})
@@ -135,9 +139,10 @@ export class StoreService {
135139
* @param orderId ID of pet that needs to be fetched
136140
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
137141
* @param reportProgress flag to report request and response progress.
142+
* @param {*} [options] Override http request option.
138143
*/
139-
public getOrderById(orderId: number, ): Observable<AxiosResponse<Order>>;
140-
public getOrderById(orderId: number, ): Observable<any> {
144+
public getOrderById(orderId: number, options?: RawAxiosRequestConfig): Observable<AxiosResponse<Order>>;
145+
public getOrderById(orderId: number, options?: RawAxiosRequestConfig): Observable<any> {
141146
if (orderId === null || orderId === undefined) {
142147
throw new Error('Required parameter orderId was null or undefined when calling getOrderById.');
143148
}
@@ -168,7 +173,8 @@ export class StoreService {
168173
return this.httpClient.get<Order>(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`,
169174
{
170175
withCredentials: this.configuration.withCredentials,
171-
headers: headers
176+
headers: {...headers, ...options?.headers},
177+
...options,
172178
}
173179
);
174180
})
@@ -180,9 +186,10 @@ export class StoreService {
180186
* @param order order placed for purchasing the pet
181187
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
182188
* @param reportProgress flag to report request and response progress.
189+
* @param {*} [options] Override http request option.
183190
*/
184-
public placeOrder(order: Order, ): Observable<AxiosResponse<Order>>;
185-
public placeOrder(order: Order, ): Observable<any> {
191+
public placeOrder(order: Order, options?: RawAxiosRequestConfig): Observable<AxiosResponse<Order>>;
192+
public placeOrder(order: Order, options?: RawAxiosRequestConfig): Observable<any> {
186193
if (order === null || order === undefined) {
187194
throw new Error('Required parameter order was null or undefined when calling placeOrder.');
188195
}
@@ -219,7 +226,8 @@ export class StoreService {
219226
order,
220227
{
221228
withCredentials: this.configuration.withCredentials,
222-
headers: headers
229+
headers: {...headers, ...options?.headers},
230+
...options,
223231
}
224232
);
225233
})

0 commit comments

Comments
 (0)