Enum that are negatives(-) are generated with the same name as positives(+)

Open Beginner friendly
#502 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
openapi, typescript
Domain
cli, tooling

Research direction

Look at the enum generation code, likely in a file handling enum extraction or name transformation. The issue shows that negative numbers in enums need to be parsed to include an underscore (e.g., '-1' becomes '_1') to avoid name collisions. Start by searching for 'enum' or 'generate' in the codebase, then run the reproduction steps to see the current output and test a fix.

Written by the indexing model from the issue text.

Description

Problem

When you have an enum with negatives(-) values and positive(+) values with the same number:

image

It produces an enum with the same name:

image

Possible Solution

For generating names in Enums function need to parse the "-" to a "_" character, it will generate something like this:

image

Steps to reproduce

  • Create a swagger api with enums with a negative and a positive number (with the same number Ex: -1,1 or -2,2 or -3,3 or so on)
  • Run the command: npx swagger-typescript-api -p http://localhost/api-json --extract-enums
  • The generated enum will have the same name for both -1 and 1
Dominant language
TypeScript
Stars
4.1k
Forks
436
Avg merge
9d 7h
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

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.

More from acacode/swagger-typescript-api

All issues in acacode/swagger-typescript-api

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.