File tree Expand file tree Collapse file tree 5 files changed +72
-9
lines changed Expand file tree Collapse file tree 5 files changed +72
-9
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
55### Fixed
66- Support enums with single quotes in names
77- Generating better names when ` operationId ` is not given (breaking change)
8+ - Fixed issue where ` x-enum ` flags where breaking due to non-string values
89
910## [ 0.19.0] - 2022-02-02
1011### Added
Original file line number Diff line number Diff line change 11import type { Enum } from '../../../client/interfaces/Enum' ;
2+ import { isString } from '../../../utils/isString' ;
23import type { WithEnumExtension } from '../interfaces/Extensions/WithEnumExtension' ;
34
45/**
@@ -8,12 +9,12 @@ import type { WithEnumExtension } from '../interfaces/Extensions/WithEnumExtensi
89 * @param definition
910 */
1011export const extendEnum = ( enumerators : Enum [ ] , definition : WithEnumExtension ) : Enum [ ] => {
11- const names = definition [ 'x-enum-varnames' ] ;
12- const descriptions = definition [ 'x-enum-descriptions' ] ;
12+ const names = definition [ 'x-enum-varnames' ] ?. filter ( isString ) ;
13+ const descriptions = definition [ 'x-enum-descriptions' ] ?. filter ( isString ) ;
1314
1415 return enumerators . map ( ( enumerator , index ) => ( {
1516 name : names ?. [ index ] || enumerator . name ,
16- description : descriptions ?. [ index ] || enumerator . description ,
17+ description : JSON . stringify ( descriptions ?. [ index ] || enumerator . description ) ,
1718 value : enumerator . value ,
1819 type : enumerator . type ,
1920 } ) ) ;
Original file line number Diff line number Diff line change 11import type { Enum } from '../../../client/interfaces/Enum' ;
2+ import { isString } from '../../../utils/isString' ;
23import type { WithEnumExtension } from '../interfaces/Extensions/WithEnumExtension' ;
34
45/**
@@ -8,8 +9,8 @@ import type { WithEnumExtension } from '../interfaces/Extensions/WithEnumExtensi
89 * @param definition
910 */
1011export const extendEnum = ( enumerators : Enum [ ] , definition : WithEnumExtension ) : Enum [ ] => {
11- const names = definition [ 'x-enum-varnames' ] ;
12- const descriptions = definition [ 'x-enum-descriptions' ] ;
12+ const names = definition [ 'x-enum-varnames' ] ?. filter ( isString ) ;
13+ const descriptions = definition [ 'x-enum-descriptions' ] ?. filter ( isString ) ;
1314
1415 return enumerators . map ( ( enumerator , index ) => ( {
1516 name : names ?. [ index ] || enumerator . name ,
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ export enum {{{name}}} {
1111 */
1212 {{ /if }}
1313 {{ #containsSpaces name }}
14- " {{{ name }}} " = {{{ value }}} ,
14+ ' {{{ name }}} ' = {{{ value }}} ,
1515 {{ else }}
1616 {{{ name }}} = {{{ value }}} ,
1717 {{ /containsSpaces }}
Original file line number Diff line number Diff line change @@ -890,15 +890,15 @@ exports[`v2 should generate: ./test/generated/v2/models/EnumWithExtensions.ts 1`
890890 */
891891export enum EnumWithExtensions {
892892 /**
893- * Used when the status of something is successful
893+ * \\" Used when the status of something is successful\\"
894894 */
895895 CUSTOM_SUCCESS = 200,
896896 /**
897- * Used when the status of something has a warning
897+ * \\" Used when the status of something has a warning\\"
898898 */
899899 CUSTOM_WARNING = 400,
900900 /**
901- * Used when the status of something has an error
901+ * \\" Used when the status of something has an error\\"
902902 */
903903 CUSTOM_ERROR = 500,
904904}"
@@ -913,20 +913,65 @@ exports[`v2 should generate: ./test/generated/v2/models/EnumWithNumbers.ts 1`] =
913913 * This is a simple enum with numbers
914914 */
915915export enum EnumWithNumbers {
916+ /**
917+ * null
918+ */
916919 '_1' = 1,
920+ /**
921+ * null
922+ */
917923 '_2' = 2,
924+ /**
925+ * null
926+ */
918927 '_3' = 3,
928+ /**
929+ * null
930+ */
919931 '_1.1' = 1.1,
932+ /**
933+ * null
934+ */
920935 '_1.2' = 1.2,
936+ /**
937+ * null
938+ */
921939 '_1.3' = 1.3,
940+ /**
941+ * null
942+ */
922943 '_100' = 100,
944+ /**
945+ * null
946+ */
923947 '_200' = 200,
948+ /**
949+ * null
950+ */
924951 '_300' = 300,
952+ /**
953+ * null
954+ */
925955 '_-100' = -100,
956+ /**
957+ * null
958+ */
926959 '_-200' = -200,
960+ /**
961+ * null
962+ */
927963 '_-300' = -300,
964+ /**
965+ * null
966+ */
928967 '_-1.1' = -1.1,
968+ /**
969+ * null
970+ */
929971 '_-1.2' = -1.2,
972+ /**
973+ * null
974+ */
930975 '_-1.3' = -1.3,
931976}"
932977`;
@@ -940,10 +985,25 @@ exports[`v2 should generate: ./test/generated/v2/models/EnumWithStrings.ts 1`] =
940985 * This is a simple enum with strings
941986 */
942987export enum EnumWithStrings {
988+ /**
989+ * null
990+ */
943991 SUCCESS = 'Success',
992+ /**
993+ * null
994+ */
944995 WARNING = 'Warning',
996+ /**
997+ * null
998+ */
945999 ERROR = 'Error',
1000+ /**
1001+ * null
1002+ */
9461003 _SINGLE_QUOTE_ = ''Single Quote'',
1004+ /**
1005+ * null
1006+ */
9471007 _DOUBLE_QUOTES_ = '\\"Double Quotes\\"',
9481008}"
9491009`;
You can’t perform that action at this time.
0 commit comments