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.
5
5
### Fixed
6
6
- Support enums with single quotes in names
7
7
- Generating better names when ` operationId ` is not given (breaking change)
8
+ - Fixed issue where ` x-enum ` flags where breaking due to non-string values
8
9
9
10
## [ 0.19.0] - 2022-02-02
10
11
### Added
Original file line number Diff line number Diff line change 1
1
import type { Enum } from '../../../client/interfaces/Enum' ;
2
+ import { isString } from '../../../utils/isString' ;
2
3
import type { WithEnumExtension } from '../interfaces/Extensions/WithEnumExtension' ;
3
4
4
5
/**
@@ -8,12 +9,12 @@ import type { WithEnumExtension } from '../interfaces/Extensions/WithEnumExtensi
8
9
* @param definition
9
10
*/
10
11
export 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 ) ;
13
14
14
15
return enumerators . map ( ( enumerator , index ) => ( {
15
16
name : names ?. [ index ] || enumerator . name ,
16
- description : descriptions ?. [ index ] || enumerator . description ,
17
+ description : JSON . stringify ( descriptions ?. [ index ] || enumerator . description ) ,
17
18
value : enumerator . value ,
18
19
type : enumerator . type ,
19
20
} ) ) ;
Original file line number Diff line number Diff line change 1
1
import type { Enum } from '../../../client/interfaces/Enum' ;
2
+ import { isString } from '../../../utils/isString' ;
2
3
import type { WithEnumExtension } from '../interfaces/Extensions/WithEnumExtension' ;
3
4
4
5
/**
@@ -8,8 +9,8 @@ import type { WithEnumExtension } from '../interfaces/Extensions/WithEnumExtensi
8
9
* @param definition
9
10
*/
10
11
export 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 ) ;
13
14
14
15
return enumerators . map ( ( enumerator , index ) => ( {
15
16
name : names ?. [ index ] || enumerator . name ,
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ export enum {{{name}}} {
11
11
*/
12
12
{{ /if }}
13
13
{{ #containsSpaces name }}
14
- " {{{ name }}} " = {{{ value }}} ,
14
+ ' {{{ name }}} ' = {{{ value }}} ,
15
15
{{ else }}
16
16
{{{ name }}} = {{{ value }}} ,
17
17
{{ /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`
890
890
*/
891
891
export enum EnumWithExtensions {
892
892
/**
893
- * Used when the status of something is successful
893
+ * \\" Used when the status of something is successful\\"
894
894
*/
895
895
CUSTOM_SUCCESS = 200,
896
896
/**
897
- * Used when the status of something has a warning
897
+ * \\" Used when the status of something has a warning\\"
898
898
*/
899
899
CUSTOM_WARNING = 400,
900
900
/**
901
- * Used when the status of something has an error
901
+ * \\" Used when the status of something has an error\\"
902
902
*/
903
903
CUSTOM_ERROR = 500,
904
904
}"
@@ -913,20 +913,65 @@ exports[`v2 should generate: ./test/generated/v2/models/EnumWithNumbers.ts 1`] =
913
913
* This is a simple enum with numbers
914
914
*/
915
915
export enum EnumWithNumbers {
916
+ /**
917
+ * null
918
+ */
916
919
'_1' = 1,
920
+ /**
921
+ * null
922
+ */
917
923
'_2' = 2,
924
+ /**
925
+ * null
926
+ */
918
927
'_3' = 3,
928
+ /**
929
+ * null
930
+ */
919
931
'_1.1' = 1.1,
932
+ /**
933
+ * null
934
+ */
920
935
'_1.2' = 1.2,
936
+ /**
937
+ * null
938
+ */
921
939
'_1.3' = 1.3,
940
+ /**
941
+ * null
942
+ */
922
943
'_100' = 100,
944
+ /**
945
+ * null
946
+ */
923
947
'_200' = 200,
948
+ /**
949
+ * null
950
+ */
924
951
'_300' = 300,
952
+ /**
953
+ * null
954
+ */
925
955
'_-100' = -100,
956
+ /**
957
+ * null
958
+ */
926
959
'_-200' = -200,
960
+ /**
961
+ * null
962
+ */
927
963
'_-300' = -300,
964
+ /**
965
+ * null
966
+ */
928
967
'_-1.1' = -1.1,
968
+ /**
969
+ * null
970
+ */
929
971
'_-1.2' = -1.2,
972
+ /**
973
+ * null
974
+ */
930
975
'_-1.3' = -1.3,
931
976
}"
932
977
`;
@@ -940,10 +985,25 @@ exports[`v2 should generate: ./test/generated/v2/models/EnumWithStrings.ts 1`] =
940
985
* This is a simple enum with strings
941
986
*/
942
987
export enum EnumWithStrings {
988
+ /**
989
+ * null
990
+ */
943
991
SUCCESS = 'Success',
992
+ /**
993
+ * null
994
+ */
944
995
WARNING = 'Warning',
996
+ /**
997
+ * null
998
+ */
945
999
ERROR = 'Error',
1000
+ /**
1001
+ * null
1002
+ */
946
1003
_SINGLE_QUOTE_ = ''Single Quote'',
1004
+ /**
1005
+ * null
1006
+ */
947
1007
_DOUBLE_QUOTES_ = '\\"Double Quotes\\"',
948
1008
}"
949
1009
`;
You can’t perform that action at this time.
0 commit comments