@@ -54,6 +54,10 @@ function sanitize(name: string): string {
5454 return name . includes ( '-' ) ? `'${ name } '` : name ;
5555}
5656
57+ function spacesToUnderscores ( name : string ) : string {
58+ return name . replace ( / \s / g, '_' ) ;
59+ }
60+
5761function parse ( spec : Swagger2 , options : Swagger2Options = { } ) : string {
5862 const shouldUseWrapper = options . wrapper !== false ;
5963 const wrapper =
@@ -93,14 +97,15 @@ function parse(spec: Swagger2, options: Swagger2Options = {}): string {
9397
9498 if ( $ref ) {
9599 const [ refName , refProperties ] = getRef ( $ref ) ;
100+ const convertedRefName = spacesToUnderscores ( refName ) ;
96101 // If a shallow array interface, return that instead
97102 if ( refProperties . items && refProperties . items . $ref ) {
98103 return getType ( refProperties , refName ) ;
99104 }
100105 if ( refProperties . type && TYPES [ refProperties . type ] ) {
101106 return TYPES [ refProperties . type ] ;
102107 }
103- return refName || DEFAULT_TYPE ;
108+ return convertedRefName || DEFAULT_TYPE ;
104109 }
105110
106111 if ( items && items . $ref ) {
@@ -172,7 +177,11 @@ function parse(spec: Swagger2, options: Swagger2Options = {}): string {
172177 // Open interface
173178 const isExtending = includes . length ? ` extends ${ includes . join ( ', ' ) } ` : '' ;
174179
175- output . push ( `export interface ${ shouldCamelCase ? camelCase ( ID ) : ID } ${ isExtending } {` ) ;
180+ output . push (
181+ `export interface ${
182+ shouldCamelCase ? camelCase ( ID ) : spacesToUnderscores ( ID )
183+ } ${ isExtending } {`
184+ ) ;
176185
177186 // Populate interface
178187 Object . entries ( allProperties ) . forEach ( ( [ key , value ] ) : void => {
0 commit comments