Skip to content

Commit b4243f2

Browse files
committed
Escape Enums in V2
1 parent 23ef7f6 commit b4243f2

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/v2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default function generateTypesV2(input: OpenAPI2 | OpenAPI2Schemas, optio
6262
case "enum": {
6363
return tsUnionOf(
6464
(node.enum as string[]).map((item) =>
65-
typeof item === "number" || typeof item === "boolean" ? item : `'${item}'`
65+
typeof item === "number" || typeof item === "boolean" ? item : `'${item.replace(/'/g, "\\'")}'`
6666
)
6767
);
6868
}

tests/v2/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe("transformation", () => {
217217
definitions: {
218218
union: {
219219
properties: {
220-
string: { type: "string", enum: ["Totoro", "Satsuki", "Mei"] },
220+
string: { type: "string", enum: ["Totoro", "Sats'uki", "Mei"] },
221221
},
222222
type: "object",
223223
},
@@ -226,7 +226,7 @@ describe("transformation", () => {
226226
expect(swaggerToTS(schema)).toBe(
227227
format(`
228228
export interface definitions {
229-
union: { string?: 'Totoro' | 'Satsuki' | 'Mei' }
229+
union: { string?: 'Totoro' | 'Sats\\'uki' | 'Mei' }
230230
}`)
231231
);
232232
});

0 commit comments

Comments
 (0)