@@ -151,14 +151,18 @@ function generateDefinition(
151151 const isTextResponse =
152152 ( isExactlyStringReturnType && hasTextLikeContentType ) ||
153153 contentTypesByPreference . some ( ( ct ) => isTextLikeContentType ( ct ) ) ;
154+ const isSchemaBinary = ( r : ResReqTypesValue ) =>
155+ r . originalSchema ?. format === 'binary' ||
156+ ( r . originalSchema ?. contentMediaType === 'application/octet-stream' &&
157+ ! r . originalSchema . contentEncoding ) ;
154158 const isBinaryResponse =
155159 contentTypesByPreference . some ( ( ct ) => isBinaryLikeContentType ( ct ) ) ||
156- responsesByPreference . some (
157- ( r ) =>
158- r . originalSchema ?. format === 'binary' ||
159- ( r . originalSchema ?. contentMediaType === 'application/octet-stream' &&
160- ! r . originalSchema . contentEncoding ) ,
161- ) ;
160+ responsesByPreference . some ( ( r ) => isSchemaBinary ( r ) ) ;
161+ // Ref aliases of schema-binary responses; rewritten to `ArrayBuffer` alongside literal `Blob`.
162+ const binaryAliasTypeNames = responsesByPreference
163+ . filter ( ( r ) => isSchemaBinary ( r ) )
164+ . map ( ( r ) => r . value )
165+ . filter ( ( name ) => name !== 'Blob' ) ;
162166 const isReturnHttpResponse = value && value !== 'undefined' ;
163167
164168 const getResponseMockFunctionName = `${ getResponseMockFunctionNameBase } ${ pascal (
@@ -175,8 +179,15 @@ function generateDefinition(
175179 ? `${ addedSplitMockImplementations . join ( '\n\n' ) } \n\n`
176180 : '' ;
177181
182+ const binaryTypePattern = [ 'Blob' , ...binaryAliasTypeNames ]
183+ . map ( ( n ) => escapeRegExp ( n ) )
184+ . join ( '|' ) ;
185+ const binaryTypeRewriteRegex = new RegExp (
186+ String . raw `\b(?:${ binaryTypePattern } )\b` ,
187+ 'g' ,
188+ ) ;
178189 const mockReturnType = isBinaryResponse
179- ? returnType . replaceAll ( / \b B l o b \b / g , 'ArrayBuffer' )
190+ ? returnType . replaceAll ( binaryTypeRewriteRegex , 'ArrayBuffer' )
180191 : returnType ;
181192
182193 // Detect when the return type is a union containing void (e.g. "Resource | void"
0 commit comments