File tree Expand file tree Collapse file tree 3 files changed +60
-1
lines changed
packages/openapi-ts/src/generate Expand file tree Collapse file tree 3 files changed +60
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @hey-api/openapi-ts " : patch
3+ ---
4+
5+ fix(renderer): replace default import placeholder
Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from 'vitest' ;
2+
3+ import { TypeScriptRenderer } from '../renderer' ;
4+
5+ describe ( 'TypeScriptRenderer' , ( ) => {
6+ describe ( 'default import placeholder replacement' , ( ) => {
7+ it ( 'should replace placeholders in default imports correctly' , ( ) => {
8+ const renderer = new TypeScriptRenderer ( ) ;
9+
10+ // Create a mock project with symbols that have placeholders
11+ const project = {
12+ symbolIdToFiles : ( ) => [ ] ,
13+ symbols : new Map ( ) ,
14+ } as any ;
15+
16+ // Create a symbol with a placeholder
17+ const symbolId = 95 ;
18+ const symbol = {
19+ id : symbolId ,
20+ name : 'foo' ,
21+ placeholder : '_heyapi_95_' ,
22+ } ;
23+ project . symbols . set ( symbolId , symbol ) ;
24+
25+ // Create a mock file
26+ const file = {
27+ resolvedNames : new Map ( [ [ symbolId , 'foo' ] ] ) ,
28+ } as any ;
29+
30+ // Create bindings with a default import that has a placeholder
31+ const bindings = new Map ( ) ;
32+ bindings . set ( 'foo' , {
33+ aliases : { } ,
34+ defaultBinding : '_heyapi_95_' , // Contains placeholder that should be replaced
35+ from : 'foo' ,
36+ names : [ ] ,
37+ typeNames : [ ] ,
38+ } ) ;
39+
40+ // Generate import lines
41+ const importLines = renderer [ 'getImportLines' ] ( bindings , file , project ) ;
42+
43+ // The import should use 'foo' not '_heyapi_95_'
44+ expect ( importLines ) . toEqual ( [ "import foo from 'foo';" ] ) ;
45+ } ) ;
46+ } ) ;
47+ } ) ;
Original file line number Diff line number Diff line change @@ -281,7 +281,14 @@ export class TypeScriptRenderer implements Renderer {
281281 let isTypeOnly = false ;
282282
283283 if ( value . defaultBinding ) {
284- defaultBinding = tsc . identifier ( { text : value . defaultBinding } ) ;
284+ const processedDefaultBinding = renderIds (
285+ value . defaultBinding ,
286+ ( symbolId ) => {
287+ const symbol = project . symbols . get ( symbolId ) ;
288+ return this . replacerFn ( { file, project, symbol } ) ;
289+ } ,
290+ ) ;
291+ defaultBinding = tsc . identifier ( { text : processedDefaultBinding } ) ;
285292 if ( value . typeDefaultBinding ) {
286293 isTypeOnly = true ;
287294 }
You can’t perform that action at this time.
0 commit comments