Skip to content

Commit ff6880e

Browse files
committed
fix: Quote the name if it consists entirely of invalid characters and replace only the invalid characters with "_" if they are part of the name
1 parent 50908b1 commit ff6880e

File tree

1 file changed

+9
-1
lines changed
  • packages/openapi-typescript/src/lib

1 file changed

+9
-1
lines changed

packages/openapi-typescript/src/lib/ts.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,15 @@ export function tsEnumMember(value: string | number, metadata: { name?: string;
285285
} else if (name[0] === "-") {
286286
name = `ValueMinus${name.slice(1)}`;
287287
}
288-
name = name.replace(JS_PROPERTY_INDEX_INVALID_CHARS_RE, "_");
288+
289+
const invalidCharMatch = name.match(JS_PROPERTY_INDEX_INVALID_CHARS_RE);
290+
if (invalidCharMatch) {
291+
if (invalidCharMatch[0] === name) {
292+
name = `"${name}"`;
293+
} else {
294+
name = name.replace(JS_PROPERTY_INDEX_INVALID_CHARS_RE, "_");
295+
}
296+
}
289297
}
290298

291299
let member: ts.EnumMember;

0 commit comments

Comments
 (0)