Generate interfaces with typescript axios generator only using OpenApi Generator

Recently, I've been utilizing the OpenApi Generator for TypeScript alongside Axios, and I must say it's been functioning really well! However, one thing that has crossed my mind is how to generate classes instead of interfaces.

For instance, when I use typescript-node, I receive all models as classes with optional Interfaces by simply setting the option withInterfaces. On the other hand, with typescript-axios, only interfaces are generated which can be quite frustrating. Can someone provide some guidance on this matter?

The version I am currently using is 1.0.12-4.3.0

Appreciate any assistance you can offer, Andi

Answer №1

To customize the templates for my project, I created an openapi-templates folder at the root.

After locating the desired template from the openapi-generator github repository, the next steps may vary depending on your setup. In my case, I utilize the docker version of openapi-generator-cli by mounting my local folder containing openapi-templates as :/local in docker. By using the -t /local/openapi-templates command line switch, I direct the generator to use my customized templates over the default ones.

Make sure to download the modelGeneric.mustache file from the provided link and place it within the openapi-templates folder. Modify this file by changing instances of the interface keyword to class.

Running the generator with the added command line parameter will result in generating classes instead of interfaces. As TypeScript allows classes to serve as interfaces, no significant drawbacks are present.

It is essential to keep in mind that the openapi team periodically updates these templates. Therefore, it is advisable to check for new default templates every 6 months and apply any necessary customizations accordingly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Best practices for bundling ambient module in typescript for npm distribution

Imagine creating an npm package named get-subject with a source file called src/index.ts. This is how the code looks: import { ReplaySubject } from 'rx'; export default function getSubject() { return new ReplaySubject(1); } The package inclu ...

Utilize Lodash to iterate through functions in a loop and retrieve the first matching result

I am looking to iterate through an array of objects and call a method on them. If the result of that method meets certain conditions, I want to immediately return that result. The current implementation is as follows: public getFirstMatch(value: string, a ...

Troubleshooting Angular 2 Karma Error: Module Parse Failed due to missing loader for file type

I'm currently configuring Karma for my Angular 2 application and I seem to be facing an issue with a missing plugin. Could anyone provide assistance with this matter? I am utilizing the following repository as a reference: https://github.com/AngularC ...

Understanding the usage of if and if not statements in Typescript can be done by utilizing

Currently, I am working on an app using TypeScript React and Meteor. The state that I have at the moment is: {user && ( ... )} This code only displays certain data if the user is logged in. However, I want to display this data only if the tournament is n ...

Utilize @types for the Typescript npm library without the need for downstream projects to install this dependency

Our npm library package, built in TypeScript and known as lib-utils, provides a range of utilities for other projects to leverage. One of the dependencies within lib-utils is d3, which is both a peerDependency and a devDependency. Additionally, there is a ...

Just getting started with Typescript and Angular and encountering issues with sending POST requests using Http

Recently, I started learning Angular and Typescript. One of the tasks I attempted was creating a basic login page. To achieve this, I developed a service in typescript that triggers upon clicking the 'Login' button. The input fields for username ...

Angular 4 does not return a time object from TimePicker

How can I get the selected time from a TimePicker in a form? Using a TimePicker in a form: <label class="padd"> Time of visiting </label> <ngb-timepicker [(ngModel)]="meridianTime" [meridian]="meridian" formControlName="time" id="time" ...

Utilizing Dependency Injection with TypeScript and Angular 5 in an Abstract Class

In my BaseComponent, I have some dependencies injected. The first dependency, EntityService, is essential and correctly implemented. However, the AnyOtherService is only utilized within the abstract BaseComponent. Instead of injecting it into the ChildCom ...

Struggling to retrieve variable within the .catch function in Ionic 3

I am having trouble accessing the toast variable from the constructor in order to toast errors. It keeps showing as undefined, and I'm not sure why. This issue seems to only occur in this class, which is strange. The error message reads "ERROR TypeErr ...

What is the best way to preserve an enumeration value in TypeScript?

Is there a way to save enumeration values in TypeScript? For instance: createArticle(name: string, clr: ??enumeration??) { return axios.post(`${environment.apiUrl}/cards`, { card: `${name}`, color: ??clr?? }, ... } PS: Conte ...

Prohibit using any as an argument in a function if a generic type is

I have attempted to implement this particular solution to prevent the calling of a generic function with the second type being equal to any. The following code snippet works fine as long as the first generic parameter is explicitly specified: declare fu ...

The issue arises when using Angular Material as it seems that passing a data object to a matdialog dialog

After reviewing multiple posts and carefully examining the process of passing data from an Angular Component to MatDialog, I am facing an issue where 'undefined' is being returned when the dialog loads. Below is the code snippet I have been work ...

Implementing multiple TypeScript classes with the same interface and comparing the properties of their objects

Looking to incorporate 2 classes for business logic within my application. Below is some pseudo code showcasing the use of object and string types to specify each logic: Includes interface and class declarations; interface IResult<T, E> { resul ...

Jest is consistently encountering errors when trying to parse a JSON file located within the node_modules folder

I've been having trouble setting up my jest.config.js file to run tests on a TypeScript Vuejs app. Jest is throwing an error about encountering an unexpected token while parsing a JSON file in the node_modules folder. I'm not sure why this is hap ...

Encountering difficulty directing component in Angular 9: Error Type: Unable to access 'outlet' property of undefined

I am facing an issue with routing in my dashboard module. Specifically, I am trying to navigate to the WhatsAppConversationComponent using routes defined in the DashboardRoutes, but it is not working as expected. Within my Dashboard module, I have declare ...

Enabling Class Method Overrides in Typescript

In my code, I have a base class called Animal which contains some methods. There is also a subclass of this class named Bird, which overrides one of the parent methods to handle a specific edge case. The structure of these classes is as follows: class ...

What is the proper way to return a Promise within a Javascript async function? Why does the Async function not automatically wrap the returned Promise?

Here is the code I have been working on. My goal is to initiate a task that involves multiple await calls before it actually starts. Once the task is initiated, I need to update the user interface to indicate that the task has begun and is awaiting the res ...

TypeScript's reliance on dependent types

Is it possible to implement this functionality using TypeScript? There exist objects that define various "actions". export interface IAction { action: string; data: any; otherParam1: number; otherParam2: number; } The 'action' p ...

How to set up an Angular animation using component input variables?

My goal is to introduce an @Input parameter that will define the timing of the animation in this demonstration of circle progress. However, the animation settings are currently specified within the @Component decorator, and it seems that this code does no ...

Mapping a list of records by a nested attribute using Typescript generic types

In my current project, I am implementing a unique custom type called "RecordsByType", which is currently undefined in the code snippet below. Within this snippet, I have various types that represent database records, each with its type defined within a ne ...