acacode / acacode/swagger-typescript-api

Enum with exactly opposite negative and positive integer values results in duplicate enum entries

未關閉
#474 2 則留言 4 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
TypeScript
星號
4.1k
分支
436
PR 合併指標
30 天內沒有已合併 PR

描述

When schema contains enums with integer values, their member names are generated as `Value${absoluteValueOfActualValue}`, which causes `Value${absoluteValueOfActualValue}` == `Value${actualValue}`, so when enums have negative and positive values of the same absolute value, they are generated with identical names.

This swagger.json entry:
```
"AddressFamily": {
"enum": [
0,
1,
2,
3,
4,
<...>
29,
65536,
65537,
-1,
],
"type": "integer",
"format": "int32"
},
```

results in this incorrect typescript enum, since `Value1` is duplicate enum member name:

```
export enum AddressFamily {
Value0 = 0,
Value1 = 1,
Value2 = 2,
Value3 = 3,
Value4 = 4,
<...>
Value29 = 29,
Value65536 = 65536,
Value65537 = 65537,
Value1 = -1,
}
```

It broke after release of v12, as previously these were generated as `type` and worked fine:
```
export type AddressFamily =
| 0
| 1
| 2
| 3
| 4
<...>
| 29
| 65536
| 65537
| -1;
```

latest tested: v12.0.2

Thanks and let me know if you need any extra info

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。