@@ -27,7 +27,7 @@ const buildTypes = (spec, namespace) => {
27
27
} ;
28
28
29
29
// Returns primitive type, or 'object' or 'any'
30
- const getType = ( { $ref, items, type } ) => {
30
+ const getType = ( { $ref, items, type, ... value } , nestedName ) => {
31
31
if ( $ref ) {
32
32
const [ refName , refProperties ] = getRef ( $ref ) ;
33
33
return TYPES [ refProperties . type ] || refName || 'any' ;
@@ -37,6 +37,10 @@ const buildTypes = (spec, namespace) => {
37
37
return `${ TYPES [ refProperties . type ] || refName || 'any' } []` ;
38
38
}
39
39
return `${ TYPES [ items . type ] || 'any' } []` ;
40
+ } else if ( value . properties ) {
41
+ // If this is a nested object, let’s add it to the stack for later
42
+ queue . push ( [ nestedName , { $ref, items, type, ...value } ] ) ;
43
+ return nestedName ;
40
44
}
41
45
42
46
return TYPES [ type ] || type || 'any' ;
@@ -72,7 +76,8 @@ const buildTypes = (spec, namespace) => {
72
76
Object . entries ( properties ) . forEach ( ( [ key , value ] ) => {
73
77
const optional = ! Array . isArray ( required ) || required . indexOf ( key ) === - 1 ;
74
78
const name = `${ camelCase ( key ) } ${ optional ? '?' : '' } ` ;
75
- const type = getType ( value ) ;
79
+ const newID = camelCase ( `${ ID } _${ key } ` ) ;
80
+ const type = getType ( value , newID ) ;
76
81
77
82
if ( typeof value . description === 'string' ) {
78
83
// Print out descriptions as comments, but only if there’s something there (.*)
@@ -81,14 +86,8 @@ const buildTypes = (spec, namespace) => {
81
86
) ;
82
87
}
83
88
84
- // If this is a nested object, let’s add it to the stack for later
85
- if ( type === 'object' ) {
86
- const newID = camelCase ( `${ ID } _${ key } ` ) ;
87
- queue . push ( [ newID , value ] ) ;
88
- output . push ( `${ name } : ${ newID } ;` ) ;
89
- return ;
90
- } else if ( Array . isArray ( value . enum ) ) {
91
- const newID = camelCase ( `${ ID } _${ key } ` ) ;
89
+ // Save enums for later
90
+ if ( Array . isArray ( value . enum ) ) {
92
91
enumQueue . push ( [ newID , value . enum ] ) ;
93
92
output . push ( `${ name } : ${ newID } ;` ) ;
94
93
return ;
0 commit comments