swagger-api / swagger-api/swagger-codegen

[Typescript] Personnalized enum from Java to Typescript

Open
#8,511 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Hello there. I'm trying to generate typescript from java with swagger. Here is my java code :

public enum ColorCode {
	A("Red"),
	B("Blue"),
	C("Green"),
	D("Yellow"),
	E("White");
	
	private String value;
	
	ColorCode(final String value) {
		this.value = value;
	}
}

The typescript generated is :

export enum ColorCode {
       A = 'A',
       B = 'B',
       C = 'C',
       D = 'D',
       E = 'E'
}

Is it a way to generated typescript like this? :

export enum ColorCode {
       Red = 'A',
       Blue = 'B',
       Green = 'C',
       Yellow = 'D',
       White = 'E'
}

I tried with @JsonValue annotation but the result is not what I expect. I want to clarify that I'm using swagger-codegen-maven-plugin and I tried to modify associated mustache with no results.

Swagger-codegen version

swagger-codegen version is 2.3.1

Swagger declaration file content or url
"colorCode": {
   "type":"string",
   "enum":[
      "A",
      "V",
      "S",
      "C",
     "N"
   ]
},

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the swagger-codegen-maven-plugin configuration and the associated TypeScript Mustache templates, then compare them with the Swagger declaration shown in the issue. Confirm how enum values and display names are represented, and consider the work complete when generation produces the requested TypeScript enum mapping for the documented Java enum.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.