fork of hey-api/openapi-ts because I need some additional things

Merge pull request #2674 from hey-api/copilot/fix-2673

authored by

Lubos and committed by
GitHub
b59afd5e f99690bf

+60 -1
+5
.changeset/unlucky-foxes-arrive.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix(renderer): replace default import placeholder
+47
packages/openapi-ts/src/generate/__tests__/renderer.test.ts
··· 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 + });
+8 -1
packages/openapi-ts/src/generate/renderer.ts
··· 281 281 let isTypeOnly = false; 282 282 283 283 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 }); 285 292 if (value.typeDefaultBinding) { 286 293 isTypeOnly = true; 287 294 }