Skip to content

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

Merged
merged 1 commit into from
Dec 31, 2020
Merged

Escape Enums in V2 #425

merged 1 commit into from
Dec 31, 2020

Conversation

asithade
Copy link
Contributor

Applying the same fix on V3 as V2.
Ref: #365

@codecov
Copy link

codecov bot commented Dec 30, 2020

Codecov Report

Merging #425 (b4243f2) into main (fc40e78) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           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           
Impacted Files Coverage Δ
src/v2.ts 85.71% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 23ef7f6...b4243f2. Read the comment docs.

@@ -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, "\\'")}'`
Copy link
Contributor

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' }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Copy link
Contributor

@drwpow drwpow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you!

@drwpow drwpow merged commit fca8764 into openapi-ts:main Dec 31, 2020
@drwpow
Copy link
Contributor

drwpow commented Dec 31, 2020

@all-contributors please add @asithade for code, bug

@allcontributors
Copy link
Contributor

@drwpow

I've put up a pull request to add @asithade! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants