@@ -79,7 +79,11 @@ function parse(spec: Swagger2, options: Swagger2Options = {}): string {
7979 }
8080
8181 // Returns primitive type, or 'object' or 'any'
82- function getType ( definition : Swagger2Definition , nestedName : string ) : string {
82+ function getType (
83+ definition : Swagger2Definition ,
84+ nestedName : string ,
85+ getTypeOptions : { camelcase : boolean }
86+ ) : string {
8387 const { $ref, items, type, ...value } = definition ;
8488
8589 const nextInterface = camelCase ( nestedName ) ; // if this becomes an interface, it’ll need to be camelCased
@@ -88,10 +92,13 @@ function parse(spec: Swagger2, options: Swagger2Options = {}): string {
8892
8993 if ( $ref ) {
9094 const [ refName , refProperties ] = getRef ( $ref ) ;
91- const convertedRefName = spacesToUnderscores ( refName ) ;
95+ let convertedRefName = spacesToUnderscores ( refName ) ;
96+ if ( options && options . camelcase === true ) {
97+ convertedRefName = camelCase ( convertedRefName ) ;
98+ }
9299 // If a shallow array interface, return that instead
93100 if ( refProperties . items && refProperties . items . $ref ) {
94- return getType ( refProperties , refName ) ;
101+ return getType ( refProperties , refName , getTypeOptions ) ;
95102 }
96103 if ( refProperties . type && PRIMITIVE [ refProperties . type ] ) {
97104 return PRIMITIVE [ refProperties . type ] ;
@@ -101,13 +108,13 @@ function parse(spec: Swagger2, options: Swagger2Options = {}): string {
101108
102109 if ( items && items . $ref ) {
103110 const [ refName ] = getRef ( items . $ref ) ;
104- return `${ getType ( items , refName ) } []` ;
111+ return `${ getType ( items , refName , getTypeOptions ) } []` ;
105112 }
106113
107114 if ( items ) {
108115 // if an array, keep nesting
109116 if ( items . type === 'array' ) {
110- return `${ getType ( items , nestedName ) } []` ;
117+ return `${ getType ( items , nestedName , getTypeOptions ) } []` ;
111118 }
112119 // else if primitive, return type
113120 if ( items . type && PRIMITIVE [ items . type ] ) {
@@ -119,7 +126,7 @@ function parse(spec: Swagger2, options: Swagger2Options = {}): string {
119126 }
120127
121128 if ( Array . isArray ( value . oneOf ) ) {
122- return value . oneOf . map ( ( def ) : string => getType ( def , '' ) ) . join ( ' | ' ) ;
129+ return value . oneOf . map ( ( def ) : string => getType ( def , '' , getTypeOptions ) ) . join ( ' | ' ) ;
123130 }
124131
125132 if ( value . properties ) {
@@ -180,7 +187,7 @@ function parse(spec: Swagger2, options: Swagger2Options = {}): string {
180187 const newID = `${ ID } ${ capitalize ( formattedKey ) } ` ;
181188 const interfaceType = Array . isArray ( value . enum )
182189 ? ` ${ value . enum . map ( option => JSON . stringify ( option ) ) . join ( ' | ' ) } ` // Handle enums in the same definition
183- : getType ( value , newID ) ;
190+ : getType ( value , newID , { camelcase : shouldCamelCase } ) ;
184191
185192 let property : Property = {
186193 interfaceType,
@@ -205,7 +212,9 @@ function parse(spec: Swagger2, options: Swagger2Options = {}): string {
205212 }
206213
207214 if ( ( additionalProperties as Swagger2Definition ) . type ) {
208- const interfaceType = getType ( additionalProperties as Swagger2Definition , '' ) ;
215+ const interfaceType = getType ( additionalProperties as Swagger2Definition , '' , {
216+ camelcase : shouldCamelCase ,
217+ } ) ;
209218 output . push ( `[name: string]: ${ interfaceType } ` ) ;
210219 }
211220 }
0 commit comments