diff --git a/plugins/typescript/src/core/schemaToEnumDeclaration.test.ts b/plugins/typescript/src/core/schemaToEnumDeclaration.test.ts index 93150d58..f041d3cf 100644 --- a/plugins/typescript/src/core/schemaToEnumDeclaration.test.ts +++ b/plugins/typescript/src/core/schemaToEnumDeclaration.test.ts @@ -7,14 +7,16 @@ describe("schemaToTypeAliasDeclaration", () => { it("should generate a string enums", () => { const schema: SchemaObject = { type: "string", - enum: ["AVAILABLE", "PENDING", "SOLD"], + enum: ["AVAILABLE", "PENDING", "PENDING/SUBMITTED", "SOLD", "SOLD:SHIPPED"], }; expect(printSchema(schema)).toMatchInlineSnapshot(` "export enum Test { AVAILABLE = \\"AVAILABLE\\", PENDING = \\"PENDING\\", - SOLD = \\"SOLD\\" + PENDING_SUBMITTED = \\"PENDING/SUBMITTED\\", + SOLD = \\"SOLD\\", + SOLD_SHIPPED = \\"SOLD:SHIPPED\\" }" `); }); diff --git a/plugins/typescript/src/core/schemaToEnumDeclaration.ts b/plugins/typescript/src/core/schemaToEnumDeclaration.ts index f765324e..b01a6d4c 100644 --- a/plugins/typescript/src/core/schemaToEnumDeclaration.ts +++ b/plugins/typescript/src/core/schemaToEnumDeclaration.ts @@ -42,7 +42,8 @@ function getEnumMembers( let enumValueNode: ts.Expression | undefined = undefined; if (typeof enumValue === "string") { - enumName = enumValue; + enumName = enumValue + .replace(/[^a-z0-9_]/gi, "_"); enumValueNode = f.createStringLiteral(enumValue); } else if (typeof enumValue === "number") { enumName = convertNumberToWord(enumValue) diff --git a/plugins/typescript/src/generators/generateSchemaTypes.test.ts b/plugins/typescript/src/generators/generateSchemaTypes.test.ts index c3d5381b..a0257bd0 100644 --- a/plugins/typescript/src/generators/generateSchemaTypes.test.ts +++ b/plugins/typescript/src/generators/generateSchemaTypes.test.ts @@ -233,7 +233,7 @@ describe("generateSchemaTypes", () => { export enum DogBreed { saimois = \\"saimois\\", bengal = \\"bengal\\", - british shorthair = \\"british shorthair\\" + british_shorthair = \\"british shorthair\\" } /**