acacode / acacode/swagger-typescript-api

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

Aperta
#474 2 commenti 4 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
4.1k
Fork
436
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.