@@ -14,7 +14,9 @@ const TYPES = {
14
14
const capitalize = str => `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
15
15
16
16
const camelCase = name =>
17
- name . replace ( / ( - | _ | \. | \s ) + [ a - z ] / g, letter => letter . toUpperCase ( ) . replace ( / [ ^ 0 - 9 a - z ] / gi, '' ) ) ;
17
+ name . replace ( / ( - | _ | \. | \s ) + [ a - z ] / g, letter =>
18
+ letter . toUpperCase ( ) . replace ( / [ ^ 0 - 9 a - z ] / gi, '' )
19
+ ) ;
18
20
19
21
const buildTypes = ( spec , options ) => {
20
22
const { definitions } = spec ;
@@ -47,8 +49,9 @@ const buildTypes = (spec, options) => {
47
49
const buildNextEnum = ( [ ID , options ] ) => {
48
50
output . push ( `enum ${ ID } {` ) ;
49
51
options . forEach ( option => {
50
- const name = typeof option === 'string' ? capitalize ( camelCase ( option ) ) : option ;
51
- output . push ( `${ name } : ${ option } ;` ) ;
52
+ const name =
53
+ typeof option === 'string' ? capitalize ( camelCase ( option ) ) : option ;
54
+ output . push ( `${ name } = ${ JSON . stringify ( option ) } ,` ) ;
52
55
} ) ;
53
56
output . push ( '}' ) ;
54
57
} ;
@@ -70,13 +73,20 @@ const buildTypes = (spec, options) => {
70
73
const name = `${ camelCase ( key ) } ${ optional ? '?' : '' } ` ;
71
74
const type = getType ( value ) ;
72
75
76
+ if ( typeof value . description === 'string' ) {
77
+ // Print out descriptions as comments, but only if there’s something there (.*)
78
+ output . push (
79
+ `// ${ value . description . replace ( / \n $ / , '' ) . replace ( / \n / g, '\n// ' ) } `
80
+ ) ;
81
+ }
82
+
73
83
// If this is a nested object, let’s add it to the stack for later
74
84
if ( type === 'object' ) {
75
85
const newID = camelCase ( `${ ID } _${ key } ` ) ;
76
86
queue . push ( [ newID , value ] ) ;
77
87
output . push ( `${ name } : ${ newID } ;` ) ;
78
88
return ;
79
- } else if ( options . enum === true && Array . isArray ( value . enum ) ) {
89
+ } else if ( Array . isArray ( value . enum ) ) {
80
90
const newID = camelCase ( `${ ID } _${ key } ` ) ;
81
91
enumQueue . push ( [ newID , value . enum ] ) ;
82
92
output . push ( `${ name } : ${ newID } ;` ) ;
@@ -102,8 +112,6 @@ const buildTypes = (spec, options) => {
102
112
buildNextInterface ( ) ;
103
113
}
104
114
105
- // console.log(output.join('\n'));
106
-
107
115
return output . join ( '\n' ) ;
108
116
} ;
109
117
0 commit comments