Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum generation: duplicate identifiers #1874

Open
1 of 2 tasks
DanDeMicco opened this issue Aug 22, 2024 · 0 comments
Open
1 of 2 tasks

Enum generation: duplicate identifiers #1874

DanDeMicco opened this issue Aug 22, 2024 · 0 comments
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@DanDeMicco
Copy link
Contributor

DanDeMicco commented Aug 22, 2024

Description

A brief description of the bug.
When generating enum values there is a possibility of name collision. For example, if an enum contains a list of timezone values, there may be collisions due to use of + and -.

Sample enum:

description: The default time zone setting for this entity.
type: string
example: America/New_York
enum:
  - Africa/Abidjan
  - Africa/Accra
  - Etc/GMT
  - Etc/GMT+0
  - Etc/GMT+1
  - Etc/GMT-1

this will result in a duplicate identifer being outputted:

Etc_GMT_1 = "Etc/GMT+1",
Etc_GMT_1 = "Etc/GMT-1",
Name Version
openapi-typescript 7.3.0
Node.js v18.20.4
OS + version macOS 14.6.1

Reproduction

How can this be reproduced / when did the error occur?

  1. create an enum value with timezone data above
npx openapi-typescript ./openapi.yaml -o ./src/typings/schema.ts --enum --alphabetize --dedupe-enums
  1. see output and notice duplicated value in enum

Expected result
There should be no duplicated enums. One approach would be to surround in quotes if a special character is detected instead of replacing all special characters with _, or can have different replacement logic (e.g. + -> plus)

(in case it’s not obvious)

Checklist

@DanDeMicco DanDeMicco added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

1 participant