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
This commit is contained in:
Gregory Merlet 2024-10-16 13:32:05 +02:00 committed by GitHub
parent ca032113f2
commit 0a39a1760e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 33 additions and 7 deletions

View File

@ -62,10 +62,12 @@ export class {{classname}} {
protected basePath = '{{{basePath}}}';
public defaultHeaders: Record<string,string> = {};
public configuration = new Configuration();
protected httpClient: HttpService;
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
this.configuration = configuration || this.configuration;
this.basePath = configuration?.basePath || this.basePath;
this.httpClient = configuration?.httpClient || httpClient;
}
/**

View File

@ -1,3 +1,4 @@
import type { HttpService } from '@nestjs/axios';
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
export interface ConfigurationParameters {
@ -7,6 +8,7 @@ export interface ConfigurationParameters {
accessToken?: string | Promise<string> | (() => string | Promise<string>);
basePath?: string;
withCredentials?: boolean;
httpClient?: HttpService;
}
export class Configuration {
@ -16,6 +18,7 @@ export class Configuration {
accessToken?: string | Promise<string> | (() => string | Promise<string>);
basePath?: string;
withCredentials?: boolean;
httpClient?: HttpService;
constructor(configurationParameters: ConfigurationParameters = {}) {
this.apiKeys = configurationParameters.apiKeys;
@ -24,6 +27,7 @@ export class Configuration {
this.accessToken = configurationParameters.accessToken;
this.basePath = configurationParameters.basePath;
this.withCredentials = configurationParameters.withCredentials;
this.httpClient = configurationParameters.httpClient;
}
/**

View File

@ -26,10 +26,12 @@ export class PetService {
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders: Record<string,string> = {};
public configuration = new Configuration();
protected httpClient: HttpService;
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
this.configuration = configuration || this.configuration;
this.basePath = configuration?.basePath || this.basePath;
this.httpClient = configuration?.httpClient || httpClient;
}
/**

View File

@ -25,10 +25,12 @@ export class StoreService {
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders: Record<string,string> = {};
public configuration = new Configuration();
protected httpClient: HttpService;
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
this.configuration = configuration || this.configuration;
this.basePath = configuration?.basePath || this.basePath;
this.httpClient = configuration?.httpClient || httpClient;
}
/**

View File

@ -25,10 +25,12 @@ export class UserService {
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders: Record<string,string> = {};
public configuration = new Configuration();
protected httpClient: HttpService;
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
this.configuration = configuration || this.configuration;
this.basePath = configuration?.basePath || this.basePath;
this.httpClient = configuration?.httpClient || httpClient;
}
/**

View File

@ -1,3 +1,4 @@
import type { HttpService } from '@nestjs/axios';
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
export interface ConfigurationParameters {
@ -7,6 +8,7 @@ export interface ConfigurationParameters {
accessToken?: string | Promise<string> | (() => string | Promise<string>);
basePath?: string;
withCredentials?: boolean;
httpClient?: HttpService;
}
export class Configuration {
@ -16,6 +18,7 @@ export class Configuration {
accessToken?: string | Promise<string> | (() => string | Promise<string>);
basePath?: string;
withCredentials?: boolean;
httpClient?: HttpService;
constructor(configurationParameters: ConfigurationParameters = {}) {
this.apiKeys = configurationParameters.apiKeys;
@ -24,6 +27,7 @@ export class Configuration {
this.accessToken = configurationParameters.accessToken;
this.basePath = configurationParameters.basePath;
this.withCredentials = configurationParameters.withCredentials;
this.httpClient = configurationParameters.httpClient;
}
/**

View File

@ -27,10 +27,12 @@ export class PetService {
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders: Record<string,string> = {};
public configuration = new Configuration();
protected httpClient: HttpService;
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
this.configuration = configuration || this.configuration;
this.basePath = configuration?.basePath || this.basePath;
this.httpClient = configuration?.httpClient || httpClient;
}
/**

View File

@ -26,10 +26,12 @@ export class StoreService {
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders: Record<string,string> = {};
public configuration = new Configuration();
protected httpClient: HttpService;
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
this.configuration = configuration || this.configuration;
this.basePath = configuration?.basePath || this.basePath;
this.httpClient = configuration?.httpClient || httpClient;
}
/**

View File

@ -26,10 +26,12 @@ export class UserService {
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders: Record<string,string> = {};
public configuration = new Configuration();
protected httpClient: HttpService;
constructor(protected httpClient: HttpService, @Optional() configuration: Configuration) {
constructor(httpClient: HttpService, @Optional() configuration: Configuration) {
this.configuration = configuration || this.configuration;
this.basePath = configuration?.basePath || this.basePath;
this.httpClient = configuration?.httpClient || httpClient;
}
/**

View File

@ -1,3 +1,4 @@
import type { HttpService } from '@nestjs/axios';
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
export interface ConfigurationParameters {
@ -7,6 +8,7 @@ export interface ConfigurationParameters {
accessToken?: string | Promise<string> | (() => string | Promise<string>);
basePath?: string;
withCredentials?: boolean;
httpClient?: HttpService;
}
export class Configuration {
@ -16,6 +18,7 @@ export class Configuration {
accessToken?: string | Promise<string> | (() => string | Promise<string>);
basePath?: string;
withCredentials?: boolean;
httpClient?: HttpService;
constructor(configurationParameters: ConfigurationParameters = {}) {
this.apiKeys = configurationParameters.apiKeys;
@ -24,6 +27,7 @@ export class Configuration {
this.accessToken = configurationParameters.accessToken;
this.basePath = configurationParameters.basePath;
this.withCredentials = configurationParameters.withCredentials;
this.httpClient = configurationParameters.httpClient;
}
/**