Skip to content

Commit 0a39a17

Browse files
Add httpClient config to typescript-nestjs generator (#19876)
* feat: add httpClient to config * chore: generate samples and doc * refactor: change import to type * chore: generate samples and doc
1 parent ca03211 commit 0a39a17

File tree

10 files changed

+33
-7
lines changed

10 files changed

+33
-7
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ export class {{classname}} {
6262
protected basePath = '{{{basePath}}}';
6363
public defaultHeaders: Record<string,string> = {};
6464
public configuration = new Configuration();
65+
protected httpClient: HttpService;
6566

66-
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
67+
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
6768
this.configuration = configuration || this.configuration;
6869
this.basePath = configuration?.basePath || this.basePath;
70+
this.httpClient = configuration?.httpClient || httpClient;
6971
}
7072

7173
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { HttpService } from '@nestjs/axios';
12
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
23

34
export interface ConfigurationParameters {
@@ -7,6 +8,7 @@ export interface ConfigurationParameters {
78
accessToken?: string | Promise<string> | (() => string | Promise<string>);
89
basePath?: string;
910
withCredentials?: boolean;
11+
httpClient?: HttpService;
1012
}
1113

1214
export class Configuration {
@@ -16,6 +18,7 @@ export class Configuration {
1618
accessToken?: string | Promise<string> | (() => string | Promise<string>);
1719
basePath?: string;
1820
withCredentials?: boolean;
21+
httpClient?: HttpService;
1922

2023
constructor(configurationParameters: ConfigurationParameters = {}) {
2124
this.apiKeys = configurationParameters.apiKeys;
@@ -24,6 +27,7 @@ export class Configuration {
2427
this.accessToken = configurationParameters.accessToken;
2528
this.basePath = configurationParameters.basePath;
2629
this.withCredentials = configurationParameters.withCredentials;
30+
this.httpClient = configurationParameters.httpClient;
2731
}
2832

2933
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ export class PetService {
2626
protected basePath = 'http://petstore.swagger.io/v2';
2727
public defaultHeaders: Record<string,string> = {};
2828
public configuration = new Configuration();
29+
protected httpClient: HttpService;
2930

30-
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
31+
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
3132
this.configuration = configuration || this.configuration;
3233
this.basePath = configuration?.basePath || this.basePath;
34+
this.httpClient = configuration?.httpClient || httpClient;
3335
}
3436

3537
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ export class StoreService {
2525
protected basePath = 'http://petstore.swagger.io/v2';
2626
public defaultHeaders: Record<string,string> = {};
2727
public configuration = new Configuration();
28+
protected httpClient: HttpService;
2829

29-
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
30+
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
3031
this.configuration = configuration || this.configuration;
3132
this.basePath = configuration?.basePath || this.basePath;
33+
this.httpClient = configuration?.httpClient || httpClient;
3234
}
3335

3436
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ export class UserService {
2525
protected basePath = 'http://petstore.swagger.io/v2';
2626
public defaultHeaders: Record<string,string> = {};
2727
public configuration = new Configuration();
28+
protected httpClient: HttpService;
2829

29-
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
30+
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
3031
this.configuration = configuration || this.configuration;
3132
this.basePath = configuration?.basePath || this.basePath;
33+
this.httpClient = configuration?.httpClient || httpClient;
3234
}
3335

3436
/**

samples/client/petstore/typescript-nestjs-v6-provided-in-root/builds/default/configuration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { HttpService } from '@nestjs/axios';
12
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
23

34
export interface ConfigurationParameters {
@@ -7,6 +8,7 @@ export interface ConfigurationParameters {
78
accessToken?: string | Promise<string> | (() => string | Promise<string>);
89
basePath?: string;
910
withCredentials?: boolean;
11+
httpClient?: HttpService;
1012
}
1113

1214
export class Configuration {
@@ -16,6 +18,7 @@ export class Configuration {
1618
accessToken?: string | Promise<string> | (() => string | Promise<string>);
1719
basePath?: string;
1820
withCredentials?: boolean;
21+
httpClient?: HttpService;
1922

2023
constructor(configurationParameters: ConfigurationParameters = {}) {
2124
this.apiKeys = configurationParameters.apiKeys;
@@ -24,6 +27,7 @@ export class Configuration {
2427
this.accessToken = configurationParameters.accessToken;
2528
this.basePath = configurationParameters.basePath;
2629
this.withCredentials = configurationParameters.withCredentials;
30+
this.httpClient = configurationParameters.httpClient;
2731
}
2832

2933
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ export class PetService {
2727
protected basePath = 'http://petstore.swagger.io/v2';
2828
public defaultHeaders: Record<string,string> = {};
2929
public configuration = new Configuration();
30+
protected httpClient: HttpService;
3031

31-
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
32+
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
3233
this.configuration = configuration || this.configuration;
3334
this.basePath = configuration?.basePath || this.basePath;
35+
this.httpClient = configuration?.httpClient || httpClient;
3436
}
3537

3638
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ export class StoreService {
2626
protected basePath = 'http://petstore.swagger.io/v2';
2727
public defaultHeaders: Record<string,string> = {};
2828
public configuration = new Configuration();
29+
protected httpClient: HttpService;
2930

30-
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
31+
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
3132
this.configuration = configuration || this.configuration;
3233
this.basePath = configuration?.basePath || this.basePath;
34+
this.httpClient = configuration?.httpClient || httpClient;
3335
}
3436

3537
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ export class UserService {
2626
protected basePath = 'http://petstore.swagger.io/v2';
2727
public defaultHeaders: Record<string,string> = {};
2828
public configuration = new Configuration();
29+
protected httpClient: HttpService;
2930

30-
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
31+
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
3132
this.configuration = configuration || this.configuration;
3233
this.basePath = configuration?.basePath || this.basePath;
34+
this.httpClient = configuration?.httpClient || httpClient;
3335
}
3436

3537
/**

samples/client/petstore/typescript-nestjs-v8-provided-in-root/builds/default/configuration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { HttpService } from '@nestjs/axios';
12
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
23

34
export interface ConfigurationParameters {
@@ -7,6 +8,7 @@ export interface ConfigurationParameters {
78
accessToken?: string | Promise<string> | (() => string | Promise<string>);
89
basePath?: string;
910
withCredentials?: boolean;
11+
httpClient?: HttpService;
1012
}
1113

1214
export class Configuration {
@@ -16,6 +18,7 @@ export class Configuration {
1618
accessToken?: string | Promise<string> | (() => string | Promise<string>);
1719
basePath?: string;
1820
withCredentials?: boolean;
21+
httpClient?: HttpService;
1922

2023
constructor(configurationParameters: ConfigurationParameters = {}) {
2124
this.apiKeys = configurationParameters.apiKeys;
@@ -24,6 +27,7 @@ export class Configuration {
2427
this.accessToken = configurationParameters.accessToken;
2528
this.basePath = configurationParameters.basePath;
2629
this.withCredentials = configurationParameters.withCredentials;
30+
this.httpClient = configurationParameters.httpClient;
2731
}
2832

2933
/**

0 commit comments

Comments
 (0)