[REQ] [typescript-axios] Object value enums
Created by: jmroon
Is your feature request related to a problem? Please describe.
While the typescript interfaces generated for the model can be fully compatible with client side models, this is not the case with enums as different string enums cannot be compatible on the client side. Typescript enums are problematic, and the typescript community has a better solution.
Implemented this would allow the client side models and server side models to be entirely decoupled, as enums are the only thing standing in the way of that at the moment.
I realize that many people likely use the server models directly, but a flexible approach would be preferable.
Describe the solution you'd like
The typescript-angular generator actually already implements this by default (stringEnums = false). It creates an object value enum as such:
export interface Model {
type: Model.TypeEnum;
}
export namespace Model{
export type TypeEnum = 'ONE' | 'TWO' | 'THREE';
export const TypeEnum = {
ONE: 'ONE' as TypeEnum,
ONE: 'TWO' as TypeEnum,
ONE: 'THREE' as TypeEnum,
} as const;
}
Alternative Solutions
It would be even greater if this could be extended to all typescript generators, but I'm not sure if their functionality is centralized in any way.
I did take a quick look at the source, but my Java-fu is weak and I can't find the obvious place to implement the change.