Generate TypeScript 2.4 string enums from Java enums #144
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds possibility to generate TypeScript string enums from Java enums. TypeScript enums were originally number-based but TypeScript 2.4 will allow string members in enums.
Java enum values usually translates to
string
s in JSON and typescript-generator generates by default union of string literals. For example for this Java enum:following TypeScript union type is generated:
This PR adds new possibility to generate following string enum:
Configuration
This feature can be used by configuring
mapEnum
parameter toasEnum
value.For implementation files (
.ts
) it is also possible to generate enums withoutconst
keyword by settingnonConstEnums
parameter totrue
.Number enums
Some Java enums are rendered as numbers in JSON (for example Jackson2 provides
JsonFormat.Shape.NUMBER_INT
). Mapping of those enums are not changed by this PR, they are always treated as TypeScript number-based enums.Deprecated extensions
With this new functionality following extensions are not needed anymore and are deprecated:
cz.habarta.typescript.generator.ext.EnumConstantsExtension
cz.habarta.typescript.generator.ext.NonConstEnumsExtension