question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Being able to provide your own client instance

See original GitHub issue

Ability to provide a custom client instance

Let’s say I’ve set --client to be axios as the generated client, it would be nice to have control over the generated client and for example being able to configure the request/response interceptors or other config.

Of course there are multiple ways to provide such functionality, but an example would be to add an additional optional parameter to the command like --clientInstance (or -ci in short) which points to a js/ts file which exports the client with the desired config.

An example for the latter when using axios, could be:

$ openapi --input ./api/swagger.json --output ./api/client --client axios --clientInstance ./api/axios-instance.ts

Then have your own instance located at /api/axios-instance.ts, with for example the following setup

import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios";

const axiosInstance: AxiosInstance = axios.create({
    // custom config
});

const onRequest = (config: AxiosRequestConfig): AxiosRequestConfig => {
    console.log(`[request] - ${config.method}`);
    return config;
}

const onRequestError = (error: AxiosError): Promise<AxiosError> => {
    console.log(`[request error] - ${error.code}`)
    return Promise.reject(error);
}

const onResponse = (response: AxiosResponse): AxiosResponse => {
    console.log(`[response] - ${response.status}`);
    return response;
}

const onResponseError = (error: AxiosError): Promise<AxiosError> => {
    console.log(`[response error] - ${error.code}`);
    return Promise.reject(error);
}

axiosInstance.interceptors.request.use(onRequest, onRequestError);
axiosInstance.interceptors.response.use(onResponse, onResponseError);

export default axiosInstance; 

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ferdikoomencommented, Jun 2, 2022

@jvdwijngaard @Lighttree I added a section to the documentation that explains how you can use your own request file, this might be a solution for your case: https://github.com/ferdikoomen/openapi-typescript-codegen/blob/master/docs/custom-request-file.md

0reactions
Lighttreecommented, Jun 3, 2022

@ferdikoomen Thanks! I think this solves raised issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A beginner's guide to Docker — how to create a client/server ...
This article is made for you. After a short introduction on Docker-Compose, you will be able to create your first client/server-side application ...
Read more >
17 Types of Clients and How To Work With Each | Indeed.com
Wherever possible, present this client with relevant data, facts or testimonials to provide positive evidence about your services.
Read more >
Rule 1.7 Conflict of Interest: Current Clients - Comment
Personal Interest Conflicts. [10] The lawyer's own interests should not be permitted to have an adverse effect on representation of a client. For...
Read more >
Connect using EC2 Instance Connect - AWS Documentation
The following instructions explain how to connect to your Linux instance using EC2 ... To connect to your instance using your own key...
Read more >
linuxserver/docker-wireguard - GitHub
Don't forget to set the necessary POSTUP and POSTDOWN rules in your client's peer conf for lan access. Usage. Here are some example...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found