File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -331,7 +331,7 @@ describe('generateMSW', () => {
331331 value : 'TestPdfFile' ,
332332 contentType : '*/*' ,
333333 originalSchema : { type : 'string' , format : 'binary' } ,
334- imports : [ ] ,
334+ imports : [ { name : 'TestPdfFile' } ] ,
335335 schemas : [ ] ,
336336 type : 'string' ,
337337 isEnum : false ,
Original file line number Diff line number Diff line change @@ -158,11 +158,11 @@ function generateDefinition(
158158 const isBinaryResponse =
159159 contentTypesByPreference . some ( ( ct ) => isBinaryLikeContentType ( ct ) ) ||
160160 responsesByPreference . some ( ( r ) => isSchemaBinary ( r ) ) ;
161- // Ref aliases of schema-binary responses; rewritten to `ArrayBuffer` alongside literal `Blob` .
162- const binaryAliasTypeNames = responsesByPreference
161+ // Bare ref names of schema-binary responses (from imports, which is the canonical place) .
162+ const binaryRefNames = responsesByPreference
163163 . filter ( ( r ) => isSchemaBinary ( r ) )
164- . map ( ( r ) => r . value )
165- . filter ( ( name ) => name !== 'Blob' ) ;
164+ . flatMap ( ( r ) => r . imports . map ( ( imp ) => imp . name ) )
165+ . filter ( Boolean ) ;
166166 const isReturnHttpResponse = value && value !== 'undefined' ;
167167
168168 const getResponseMockFunctionName = `${ getResponseMockFunctionNameBase } ${ pascal (
@@ -179,11 +179,8 @@ function generateDefinition(
179179 ? `${ addedSplitMockImplementations . join ( '\n\n' ) } \n\n`
180180 : '' ;
181181
182- const binaryTypePattern = [ 'Blob' , ...binaryAliasTypeNames ]
183- . map ( ( n ) => escapeRegExp ( n ) )
184- . join ( '|' ) ;
185182 const binaryTypeRewriteRegex = new RegExp (
186- String . raw `\b(?:${ binaryTypePattern } )\b` ,
183+ String . raw `\b(?:${ [ 'Blob' , ... binaryRefNames ] . map ( ( n ) => escapeRegExp ( n ) ) . join ( '|' ) } )\b` ,
187184 'g' ,
188185 ) ;
189186 const mockReturnType = isBinaryResponse
You can’t perform that action at this time.
0 commit comments