OpenAPITools / OpenAPITools/openapi-generator
[typescript-angular] Allow string literal unions instead of string enums
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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:
https://github.com/OpenAPITools/openapi-generator/pull/11368It 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'
}
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the typescript-angular generator with the typescript-axios and typescript-fetch behavior referenced in the issue, then inspect the generated EnumSample output shown here. Done means the typescript-angular generator emits string literal unions with the corresponding constant object instead of a TypeScript string enum.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100