diff --git a/CHANGELOG.md b/CHANGELOG.md index 886cc64c..63f8a2c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ # Changelog All notable changes to this project will be documented in this file. +## [0.20.1] - 2022-02-25 +### Fixed +- Support enums with single quotes in names for V2 + ## [0.20.0] - 2022-02-25 ### Fixed - Updated dependencies -- Support enums with single quotes in names +- Support enums with single quotes in names for V3 - Generating better names when `operationId` is not given (breaking change) - Fixed issue where `x-enum` flags where breaking due to non-string values diff --git a/package.json b/package.json index 5dd3512e..743d96de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openapi-typescript-codegen", - "version": "0.20.0", + "version": "0.20.1", "description": "Library that generates Typescript clients based on the OpenAPI specification.", "author": "Ferdi Koomen", "homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen", diff --git a/src/openApi/v2/parser/getEnum.ts b/src/openApi/v2/parser/getEnum.ts index c684b466..607022fa 100644 --- a/src/openApi/v2/parser/getEnum.ts +++ b/src/openApi/v2/parser/getEnum.ts @@ -23,7 +23,7 @@ export const getEnum = (values?: (string | number)[]): Enum[] => { .replace(/^(\d+)/g, '_$1') .replace(/([a-z])([A-Z]+)/g, '$1_$2') .toUpperCase(), - value: `'${value}'`, + value: `'${value.replace(/'/g, "\\'")}'`, type: 'string', description: null, }; diff --git a/test/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index 580f451a..922747cf 100644 --- a/test/__snapshots__/index.spec.ts.snap +++ b/test/__snapshots__/index.spec.ts.snap @@ -1000,7 +1000,7 @@ export enum EnumWithStrings { /** * null */ - _SINGLE_QUOTE_ = ''Single Quote'', + _SINGLE_QUOTE_ = '\\\\'Single Quote\\\\'', /** * null */