diff --git a/plugins/typescript/src/core/schemaToEnumDeclaration.test.ts b/plugins/typescript/src/core/schemaToEnumDeclaration.test.ts index a34c23f..606c5af 100644 --- a/plugins/typescript/src/core/schemaToEnumDeclaration.test.ts +++ b/plugins/typescript/src/core/schemaToEnumDeclaration.test.ts @@ -7,14 +7,15 @@ describe("schemaToTypeAliasDeclaration", () => { it("should generate a string enums", () => { const schema: SchemaObject = { type: "string", - enum: ["AVAILABLE", "PENDING", "SOLD"], + enum: ["AVAILABLE", "PENDING", "SOLD", "WITH SPACE"], }; expect(printSchema(schema)).toMatchInlineSnapshot(` "export enum Test { AVAILABLE = "AVAILABLE", PENDING = "PENDING", - SOLD = "SOLD" + SOLD = "SOLD", + "WITH SPACE" = "WITH SPACE" }" `); }); diff --git a/plugins/typescript/src/core/schemaToEnumDeclaration.ts b/plugins/typescript/src/core/schemaToEnumDeclaration.ts index b497187..29b7604 100644 --- a/plugins/typescript/src/core/schemaToEnumDeclaration.ts +++ b/plugins/typescript/src/core/schemaToEnumDeclaration.ts @@ -48,6 +48,7 @@ function getEnumMembers( if (typeof enumValue === "string") { enumName = enumValue.match(/^\d/) ? `"_${enumValue}"` : enumValue; + enumName = enumName.match(/[^"]+.*\s.*/) ? `"${enumName}"` : enumName; 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 64232dc..6402eb7 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" } /**