Skip to content

Commit 9ba9603

Browse files
committed
Expanded tests to ensure null and empty strings are handled correctly
1 parent b8cf5a2 commit 9ba9603

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export const enumCache = new Map<string, ts.EnumDeclaration>();
268268
export function tsEnum(
269269
name: string,
270270
members: (string | number)[],
271-
metadata?: { name?: string; description?: string }[],
271+
metadata?: { name?: string; description?: string | null }[],
272272
options?: { export?: boolean; shouldCache?: boolean },
273273
) {
274274
let enumName = sanitizeMemberName(name);
@@ -352,7 +352,7 @@ function sanitizeMemberName(name: string) {
352352
}
353353

354354
/** Sanitize TS enum member expression */
355-
export function tsEnumMember(value: string | number, metadata: { name?: string; description?: string } = {}) {
355+
export function tsEnumMember(value: string | number, metadata: { name?: string; description?: string | null } = {}) {
356356
let name = metadata.name ?? String(value);
357357
if (!JS_PROPERTY_INDEX_RE.test(name)) {
358358
if (Number(name[0]) >= 0) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ describe("tsEnum", () => {
278278
tsEnum(
279279
".Error.code.",
280280
[100, 101, 102],
281-
[{ name: "Unauthorized", description: "User is unauthorized" }, { name: "NotFound" }],
281+
[{ name: "Unauthorized", description: "User is unauthorized" }, { name: "NotFound", description: "" }, { name: "Value102", description: null }],
282282
),
283283
).trim(),
284284
).toBe(`enum ErrorCode {

0 commit comments

Comments
 (0)