ferdikoomen / openapi-typescript-codegen

NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification
MIT License
2.91k stars 519 forks source link

optionally pass other setting to AxiosRequestConfig used in axios.request(requestConfig); #2157

Open grimmer0125 opened 4 months ago

grimmer0125 commented 4 months ago

Describe the solution you'd like A clear and concise description of what you want to happen. Ideally with a small example of the proposed changes.

// In the generated client's constructor, it could be 

 constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = AxiosHttpRequest, rawAxiosConfig: AxiosRequestConfig) {
    // save rawAxiosConfig somethere
}

// in the generated request.ts
const requestConfig: AxiosRequestConfig = {
        url,
        headers,
        data: body ?? formData,
        method: options.method,
        withCredentials: config.WITH_CREDENTIALS,
        cancelToken: source.token,
        ...rawAxiosConfig
    };

now:

   // current
    constructor(config?: Partial<OpenAPIConfig>, HttpRequest: HttpRequestConstructor = AxiosHttpRequest) {
        this.request = new HttpRequest({
            BASE: config?.BASE ?? '',
            VERSION: config?.VERSION ?? '1.0',
            WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
            CREDENTIALS: config?.CREDENTIALS ?? 'include',
            TOKEN: config?.TOKEN,
            USERNAME: config?.USERNAME,
            PASSWORD: config?.PASSWORD,
            HEADERS: config?.HEADERS,
            ENCODE_PATH: config?.ENCODE_PATH,
        });

   // in the generated request.ts        
    const requestConfig: AxiosRequestConfig = {
        url,
        headers,
        data: body ?? formData,
        method: options.method,
        withCredentials: config.WITH_CREDENTIALS,
        cancelToken: source.token,
    };        
mrlubos commented 4 months ago

Hey @grimmer0125, please migrate to https://github.com/hey-api/openapi-ts if you'd like this addressed. I'm actually working on an Axios client right now which will follow the Fetch API client I released yesterday