Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typescript-angular] Allow string literal unions instead of string enums #12718

Open
StefanKern opened this issue Jun 28, 2022 · 1 comment · May be fixed by #19413
Open

[typescript-angular] Allow string literal unions instead of string enums #12718

StefanKern opened this issue Jun 28, 2022 · 1 comment · May be fixed by #19413

Comments

@StefanKern
Copy link

StefanKern commented Jun 28, 2022

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 and typescript-axios generator actually already implements this by default (stringEnums = false).

See this recent merge request:
#11368

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,
    TWO: 'TWO' as TypeEnum,
    THREE: 'THREE' as TypeEnum,
  } as const;
}

--> This title and description is a copy of [REQ][typescript-fetch] Allow string literal unions instead of string enums, which already describes it perfectly and also applies this typescript generator.

Addition:
current output of option stringEnum

export interface Model {
  type: EnumSample;
}
export enum EnumSample {
  ONE = 'ONE',
  TWO= 'TWO',
  THREE= 'THREE'
}
```
@StefanKern StefanKern changed the title [typescript-angular] stringEnums should behave the same as other implementions [typescript-angular] Allow string literal unions instead of string enums Jun 28, 2022
@inkassso
Copy link

What is the issue here? The typescript-angular generator already supports this, the option stringEnums is false by default, which generates the enum in the form of a union type and an accompanied object with the string literals.

simon-abbott added a commit to simon-abbott/openapi-generator that referenced this issue Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants