I'm using openapi-client-axios to generate an axios instance from an open-api specification file. When my app starts, it will request the open-api specification and the library will generate an axios instance from it. Now, i would like to remove the runtime dependency to my open-api specification and save the generated instance instead.
Is there a way to generate a prototype builder from a JS object? I would like to achieve something like this:
generateJSCodeFrom(axiosInstance);
Output.js:
function GeneratedAxiosClient() {
}
GeneratedAxiosClient.prototype.getById = function(id) {
return axios.get("localhost:8080/people", {id});
};
There are a number of code generators for generating client code from OpenAPI specifications. You can use these at compile or authoring time to generate a client so you do not need to load the OpenAPI specification at runtime. Of course this also means that you have to check your generated client regularly for updates if the API changes.
Some tools that generate OpenAPI clients:
There is also a wrapper module on npm for the OpenAPITools one which you could integrate into your JS build process.