-
-
Notifications
You must be signed in to change notification settings - Fork 546
Escape Enums in V2 #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Escape Enums in V2 #425
Conversation
Codecov Report
@@ Coverage Diff @@
## main #425 +/- ##
=======================================
Coverage 93.56% 93.56%
=======================================
Files 5 5
Lines 264 264
Branches 86 86
=======================================
Hits 247 247
Misses 13 13
Partials 4 4
Continue to review full report at Codecov.
|
@@ -62,7 +62,7 @@ export default function generateTypesV2(input: OpenAPI2 | OpenAPI2Schemas, optio | |||
case "enum": { | |||
return tsUnionOf( | |||
(node.enum as string[]).map((item) => | |||
typeof item === "number" || typeof item === "boolean" ? item : `'${item}'` | |||
typeof item === "number" || typeof item === "boolean" ? item : `'${item.replace(/'/g, "\\'")}'` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
@@ -226,7 +226,7 @@ describe("transformation", () => { | |||
expect(swaggerToTS(schema)).toBe( | |||
format(` | |||
export interface definitions { | |||
union: { string?: 'Totoro' | 'Satsuki' | 'Mei' } | |||
union: { string?: 'Totoro' | 'Sats\\'uki' | 'Mei' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you!
@all-contributors please add @asithade for code, bug |
I've put up a pull request to add @asithade! 🎉 |
Applying the same fix on V3 as V2.
Ref: #365