swagger-api / swagger-api/swagger-codegen
[Typescript] Enum name collision with `r` and `r+`
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Using typescript-node and typescript-fetch generators a duplicate entry is created when enum items have the same name with one containing a +.
Swagger-codegen version
5.4.0 downloaded using npm, @openapitools/openapi-generator-cli.
Swagger declaration file content or url
{
"rating": {
"type": "string",
"enum": [
"g",
"pg",
"pg_13",
"r",
"r+",
"rx"
]
},
}
this json schema (used inside an application/json response), gets converted to the following code:
export enum RatingEnum {
G = <any> 'g',
Pg = <any> 'pg',
Pg13 = <any> 'pg_13',
R = <any> 'r',
R = <any> 'r+',
Rx = <any> 'rx'
}
As you can see the entry R is present twice.
Command line used for generation
openapi-generator-cli generate -i swagger/swagger.json -o lib -g typescript-node --strict-spec false
Steps to reproduce
Create a swagger file with an endpoint that returns content with type application/json, it has to have a json schema attached with type object and the property above.
Use the command above to generate a typescript sdk for the swagger file.
Transpiling using tsc will throw an error.
Related issues/PRs
Unable to find any
Suggest a fix/enhancement
I would personally recommend transforming the + into the text plus so instead of R it would become RPlus or Rplus.
This problem may occur with other signs and generators as well, the ones described in this issue are the only ones I attempted.
Another option would be making it into the following type:
export type RatingEnum = 'g' | 'pg' | 'pg_13' | 'r' | 'r+' | 'rx';
If you have any questions please do ask them, I look on my GitHub multiple times a day and should be able to come back with a response fairly swiftly
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 reproducing the issue with the provided schema and the typescript-node generator command, then compare the enum-name handling in the typescript-node and typescript-fetch generators. Check the generated RatingEnum with tsc; done means values such as r and r+ produce distinct valid TypeScript enum members without compilation errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100