@@ -27,9 +27,7 @@ const TYPES: { [index: string]: string } = {
2727const capitalize = ( str : string ) => `${ str [ 0 ] . toUpperCase ( ) } ${ str . slice ( 1 ) } ` ;
2828
2929const camelCase = ( name : string ) =>
30- name . replace ( / ( - | _ | \. | \s ) + [ a - z ] / g, letter =>
31- letter . toUpperCase ( ) . replace ( / [ ^ 0 - 9 a - z ] / gi, '' )
32- ) ;
30+ name . replace ( / ( - | _ | \. | \s ) + [ a - z ] / g, letter => letter . toUpperCase ( ) . replace ( / [ ^ 0 - 9 a - z ] / gi, '' ) ) ;
3331
3432const buildTypes = ( spec : Swagger2 , namespace : string ) => {
3533 const queue : [ string , Swagger2Definition ] [ ] = [ ] ;
@@ -39,16 +37,21 @@ const buildTypes = (spec: Swagger2, namespace: string) => {
3937 const { definitions } = spec ;
4038
4139 function getRef ( lookup : string ) : [ string , Swagger2Definition ] {
42- const ref = lookup . replace ( '#/definitions/' , '' ) ;
43- return [ ref , definitions [ ref ] ] ;
40+ const ID = lookup . replace ( '#/definitions/' , '' ) ;
41+ const ref = definitions [ ID ] ;
42+ return [ ID , ref ] ;
4443 }
4544
4645 // Returns primitive type, or 'object' or 'any'
47- function getType ( definition : Swagger2Definition , nestedName : string ) {
46+ function getType ( definition : Swagger2Definition , nestedName : string ) : string {
4847 const { $ref, items, type, ...value } = definition ;
4948
5049 if ( $ref ) {
5150 const [ refName , refProperties ] = getRef ( $ref ) ;
51+ // If a shallow array interface, return that instead
52+ if ( refProperties . items && refProperties . items . $ref ) {
53+ return getType ( refProperties , refName ) ;
54+ }
5255 return TYPES [ refProperties . type ] || refName || 'any' ;
5356 }
5457
@@ -110,9 +113,7 @@ const buildTypes = (spec: Swagger2, namespace: string) => {
110113 return ;
111114 }
112115 // Open interface
113- const isExtending = includes . length
114- ? ` extends ${ includes . join ( ', ' ) } `
115- : '' ;
116+ const isExtending = includes . length ? ` extends ${ includes . join ( ', ' ) } ` : '' ;
116117
117118 output . push ( `export interface ${ camelCase ( ID ) } ${ isExtending } {` ) ;
118119
@@ -125,9 +126,7 @@ const buildTypes = (spec: Swagger2, namespace: string) => {
125126
126127 if ( typeof value . description === 'string' ) {
127128 // Print out descriptions as comments, but only if there’s something there (.*)
128- output . push (
129- `// ${ value . description . replace ( / \n $ / , '' ) . replace ( / \n / g, '\n// ' ) } `
130- ) ;
129+ output . push ( `// ${ value . description . replace ( / \n $ / , '' ) . replace ( / \n / g, '\n// ' ) } ` ) ;
131130 }
132131
133132 // Save enums for later
0 commit comments