File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -355,6 +355,38 @@ describe('generateMSW', () => {
355355 expect ( result . implementation . function ) . not . toContain ( ': TestPdfFile' ) ;
356356 } ) ;
357357
358+ it ( 'should rewrite aliased ref imports for $ref binary schemas' , ( ) => {
359+ const aliasedVerbOptions = {
360+ ...mockVerbOptions ,
361+ response : {
362+ imports : [ ] ,
363+ definition : { success : '__TestPdfFile' } ,
364+ types : {
365+ success : [
366+ {
367+ key : '200' ,
368+ value : '__TestPdfFile' ,
369+ contentType : '*/*' ,
370+ originalSchema : { type : 'string' , format : 'binary' } ,
371+ imports : [ { name : 'TestPdfFile' , alias : '__TestPdfFile' } ] ,
372+ schemas : [ ] ,
373+ type : 'string' ,
374+ isEnum : false ,
375+ isRef : true ,
376+ hasReadonlyProps : false ,
377+ } ,
378+ ] ,
379+ } ,
380+ contentTypes : [ '*/*' ] ,
381+ } ,
382+ } as unknown as GeneratorVerbOptions ;
383+
384+ const result = generateMSW ( aliasedVerbOptions , baseOptions ) ;
385+
386+ expect ( result . implementation . function ) . toContain ( ': ArrayBuffer' ) ;
387+ expect ( result . implementation . function ) . not . toContain ( ': __TestPdfFile' ) ;
388+ } ) ;
389+
358390 it ( 'should not force binary path when preferredContentType narrows to a non-binary success variant' , ( ) => {
359391 const mixedVerbOptions = {
360392 ...mockVerbOptions ,
Original file line number Diff line number Diff line change @@ -158,11 +158,14 @@ function generateDefinition(
158158 const isBinaryResponse =
159159 contentTypesByPreference . some ( ( ct ) => isBinaryLikeContentType ( ct ) ) ||
160160 responsesByPreference . some ( ( r ) => isSchemaBinary ( r ) ) ;
161- // Bare ref names of schema-binary responses (from imports, which is the canonical place ).
161+ // Bare ref names of schema-binary responses (include alias for collision-renamed imports ).
162162 const binaryRefNames = responsesByPreference
163163 . filter ( ( r ) => isSchemaBinary ( r ) )
164- . flatMap ( ( r ) => r . imports . map ( ( imp ) => imp . name ) )
165- . filter ( Boolean ) ;
164+ . flatMap ( ( r ) =>
165+ r . imports . flatMap ( ( imp ) =>
166+ imp . alias ? [ imp . name , imp . alias ] : [ imp . name ] ,
167+ ) ,
168+ ) ;
166169 const isReturnHttpResponse = value && value !== 'undefined' ;
167170
168171 const getResponseMockFunctionName = `${ getResponseMockFunctionNameBase } ${ pascal (
You can’t perform that action at this time.
0 commit comments