-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Open
Labels
Description
Description
hen generating a TypeScript client from an OpenAPI schema containing timezone enums such as "Etc/GMT+12"
and "Etc/GMT-12"
, the generator creates duplicate enum property names (EtcGmt122
), leading to a TypeScript compilation error:
src/api/api.ts:12517:5 - error TS1117: An object literal cannot have multiple properties with the same name.
12517 EtcGmt122: 'Etc/GMT-12',
~~~~~~~~~
This happens because both "Etc/GMT+12"
and "Etc/GMT-12"
resolve to the same sanitized identifier (EtcGmt12
), and the generator attempts to disambiguate by appending numeric suffixes, which results in collisions again.
openapi-generator version
7.14.0
OpenAPI declaration file content or url
{
"components": {
"schemas": {
"UtcTimezoneEnum": {
"enum": [
"Etc/GMT+12",
"Etc/GMT+11",
"Etc/GMT+10",
"Pacific/Marquesas",
"Etc/GMT+9",
"Etc/GMT+8",
"Etc/GMT+7",
"Etc/GMT+6",
"Etc/GMT+5",
"Etc/GMT+4",
"America/St_Johns",
"Etc/GMT+3",
"Etc/GMT+2",
"Etc/GMT+1",
"Etc/GMT0",
"Etc/GMT-1",
"Europe/Kiev",
"Etc/GMT-3",
"Asia/Tehran",
"Etc/GMT-4",
"Asia/Kabul",
"Etc/GMT-5",
"Asia/Kolkata",
"Asia/Kathmandu",
"Etc/GMT-6",
"Asia/Yangon",
"Etc/GMT-7",
"Etc/GMT-8",
"Australia/Eucla",
"Etc/GMT-9",
"Australia/Darwin",
"Etc/GMT-10",
"Australia/Lord_Howe",
"Etc/GMT-11",
"Etc/GMT-12",
"Pacific/Chatham",
"Etc/GMT-13",
"Etc/GMT-14"
],
"type": "string",
"description": "* `Etc/GMT+12` - UTC-12:00\n* `Etc/GMT+11` - UTC-11:00\n* `Etc/GMT+10` - UTC-10:00\n* `Pacific/Marquesas` - UTC-09:30\n* `Etc/GMT+9` - UTC-09:00\n* `Etc/GMT+8` - UTC-08:00\n* `Etc/GMT+7` - UTC-07:00\n* `Etc/GMT+6` - UTC-06:00\n* `Etc/GMT+5` - UTC-05:00\n* `Etc/GMT+4` - UTC-04:00\n* `America/St_Johns` - UTC-03:30\n* `Etc/GMT+3` - UTC-03:00\n* `Etc/GMT+2` - UTC-02:00\n* `Etc/GMT+1` - UTC-01:00\n* `Etc/GMT0` - UTC 00:00\n* `Etc/GMT-1` - UTC+01:00\n* `Europe/Kiev` - UTC+02:00\n* `Etc/GMT-3` - UTC+03:00\n* `Asia/Tehran` - UTC+03:30\n* `Etc/GMT-4` - UTC+04:00\n* `Asia/Kabul` - UTC+04:30\n* `Etc/GMT-5` - UTC+05:00\n* `Asia/Kolkata` - UTC+05:30\n* `Asia/Kathmandu` - UTC+05:45\n* `Etc/GMT-6` - UTC+06:00\n* `Asia/Yangon` - UTC+06:30\n* `Etc/GMT-7` - UTC+07:00\n* `Etc/GMT-8` - UTC+08:00\n* `Australia/Eucla` - UTC+08:45\n* `Etc/GMT-9` - UTC+09:00\n* `Australia/Darwin` - UTC+09:30\n* `Etc/GMT-10` - UTC+10:00\n* `Australia/Lord_Howe` - UTC+10:30\n* `Etc/GMT-11` - UTC+11:00\n* `Etc/GMT-12` - UTC+12:00\n* `Pacific/Chatham` - UTC+12:45\n* `Etc/GMT-13` - UTC+13:00\n* `Etc/GMT-14` - UTC+14:00"
}
}
}
}
Generation Details
Generated in api.ts
}
/**
* * `Etc/GMT+12` - UTC-12:00 * `Etc/GMT+11` - UTC-11:00 * `Etc/GMT+10` - UTC-10:00 * `Pacific/Marquesas` - UTC-09:30 * `Etc/GMT+9` - UTC-09:00 * `Etc/GMT+8` - UTC-08:00 * `Etc/GMT+7` - UTC-07:00 * `Etc/GMT+6` - UTC-06:00 * `Etc/GMT+5` - UTC-05:00 * `Etc/GMT+4` - UTC-04:00 * `America/St_Johns` - UTC-03:30 * `Etc/GMT+3` - UTC-03:00 * `Etc/GMT+2` - UTC-02:00 * `Etc/GMT+1` - UTC-01:00 * `Etc/GMT0` - UTC 00:00 * `Etc/GMT-1` - UTC+01:00 * `Europe/Kiev` - UTC+02:00 * `Etc/GMT-3` - UTC+03:00 * `Asia/Tehran` - UTC+03:30 * `Etc/GMT-4` - UTC+04:00 * `Asia/Kabul` - UTC+04:30 * `Etc/GMT-5` - UTC+05:00 * `Asia/Kolkata` - UTC+05:30 * `Asia/Kathmandu` - UTC+05:45 * `Etc/GMT-6` - UTC+06:00 * `Asia/Yangon` - UTC+06:30 * `Etc/GMT-7` - UTC+07:00 * `Etc/GMT-8` - UTC+08:00 * `Australia/Eucla` - UTC+08:45 * `Etc/GMT-9` - UTC+09:00 * `Australia/Darwin` - UTC+09:30 * `Etc/GMT-10` - UTC+10:00 * `Australia/Lord_Howe` - UTC+10:30 * `Etc/GMT-11` - UTC+11:00 * `Etc/GMT-12` - UTC+12:00 * `Pacific/Chatham` - UTC+12:45 * `Etc/GMT-13` - UTC+13:00 * `Etc/GMT-14` - UTC+14:00
* @export
* @enum {string}
*/
export const UtcTimezoneEnum = {
EtcGmt122: 'Etc/GMT+12',
EtcGmt11: 'Etc/GMT+11',
EtcGmt10: 'Etc/GMT+10',
PacificMarquesas: 'Pacific/Marquesas',
EtcGmt9: 'Etc/GMT+9',
EtcGmt8: 'Etc/GMT+8',
EtcGmt7: 'Etc/GMT+7',
EtcGmt6: 'Etc/GMT+6',
EtcGmt5: 'Etc/GMT+5',
EtcGmt4: 'Etc/GMT+4',
AmericaStJohns: 'America/St_Johns',
EtcGmt3: 'Etc/GMT+3',
EtcGmt2: 'Etc/GMT+2',
EtcGmt1: 'Etc/GMT+1',
EtcGmt0: 'Etc/GMT0',
EtcGmt12: 'Etc/GMT-1',
EuropeKiev: 'Europe/Kiev',
EtcGmt32: 'Etc/GMT-3',
AsiaTehran: 'Asia/Tehran',
EtcGmt42: 'Etc/GMT-4',
AsiaKabul: 'Asia/Kabul',
EtcGmt52: 'Etc/GMT-5',
AsiaKolkata: 'Asia/Kolkata',
AsiaKathmandu: 'Asia/Kathmandu',
EtcGmt62: 'Etc/GMT-6',
AsiaYangon: 'Asia/Yangon',
EtcGmt72: 'Etc/GMT-7',
EtcGmt82: 'Etc/GMT-8',
AustraliaEucla: 'Australia/Eucla',
EtcGmt92: 'Etc/GMT-9',
AustraliaDarwin: 'Australia/Darwin',
EtcGmt102: 'Etc/GMT-10',
AustraliaLordHowe: 'Australia/Lord_Howe',
EtcGmt112: 'Etc/GMT-11',
EtcGmt122: 'Etc/GMT-12', // <--- duplicate key causes TS1117
PacificChatham: 'Pacific/Chatham',
EtcGmt13: 'Etc/GMT-13',
EtcGmt14: 'Etc/GMT-14'
} as const;
export type UtcTimezoneEnum = typeof UtcTimezoneEnum[keyof typeof UtcTimezoneEnum];
Error:
error TS1117: An object literal cannot have multiple properties with the same name.
Steps to reproduce
npx openapi-generator-cli generate -g typescript-axios -i http://localhost:8000/api/schema/?format=json -o ./src/api/
Suggest a fix
In the TypeScript enum generator, enhance the logic to include sign indicators for numeric parts when generating identifiers from enum values.
For example:
"Etc/GMT+12"
→EtcGmtPos12
"Etc/GMT-12"
→EtcGmtNeg12
This ensures stable and unique keys without violating TypeScript syntax rules.