Skip to content

Commit 110d5d1

Browse files
committed
Fix number enum names
1 parent 4a92b34 commit 110d5d1

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@manifoldco/swagger-to-ts",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Convert Swagger files to TypeScript",
55
"main": "dist/swaggerToTS.js",
66
"scripts": {

src/swaggerToTS.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ const buildTypes = (spec, options) => {
4949
const buildNextEnum = ([ID, options]) => {
5050
output.push(`enum ${ID} {`);
5151
options.forEach(option => {
52-
const name =
53-
typeof option === 'string' ? capitalize(camelCase(option)) : option;
54-
output.push(`${name} = ${JSON.stringify(option)},`);
52+
if (typeof option === 'number') {
53+
const lastWord = ID.search(/[A-Z](?=[^A-Z]*$)/);
54+
const name = ID.substr(lastWord, ID.length);
55+
output.push(`${name}${option} = ${option},`);
56+
} else {
57+
const name = capitalize(camelCase(option));
58+
output.push(`${name} = ${JSON.stringify(option)},`);
59+
}
5560
});
5661
output.push('}');
5762
};

0 commit comments

Comments
 (0)