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

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #449 from hey-api/fix/only-remove-core-files-when-writing

authored by

Jordan Shatford and committed by
GitHub
2357fd28 840d9df6

+26 -30
+5
.changeset/new-kings-chew.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix: only remove core directory when export core is true
+7 -8
packages/openapi-ts/src/utils/write/__tests__/core.spec.ts
··· 6 6 import { setConfig } from '../../config'; 7 7 import { writeCore } from '../core'; 8 8 import { mockTemplates } from './mocks'; 9 - import { openApi } from './models'; 10 9 11 10 vi.mock('node:fs'); 12 11 13 12 describe('writeCore', () => { 14 - let templates: Parameters<typeof writeCore>[3]; 13 + let templates: Parameters<typeof writeCore>[2]; 15 14 beforeEach(() => { 16 15 templates = mockTemplates; 17 16 }); 18 17 19 18 it('writes to filesystem', async () => { 20 - const client: Parameters<typeof writeCore>[2] = { 19 + const client: Parameters<typeof writeCore>[1] = { 21 20 enumNames: [], 22 21 models: [], 23 22 server: 'http://localhost:8080', ··· 42 41 useOptions: true, 43 42 }); 44 43 45 - await writeCore(openApi, '/', client, templates); 44 + await writeCore('/', client, templates); 46 45 47 46 expect(writeFileSync).toHaveBeenCalledWith( 48 47 path.resolve('/', '/OpenAPI.ts'), ··· 71 70 }); 72 71 73 72 it('uses client server value for base', async () => { 74 - const client: Parameters<typeof writeCore>[2] = { 73 + const client: Parameters<typeof writeCore>[1] = { 75 74 enumNames: [], 76 75 models: [], 77 76 server: 'http://localhost:8080', ··· 96 95 useOptions: true, 97 96 }); 98 97 99 - await writeCore(openApi, '/', client, templates); 98 + await writeCore('/', client, templates); 100 99 101 100 expect(templates.core.settings).toHaveBeenCalledWith({ 102 101 $config: config, ··· 107 106 }); 108 107 109 108 it('uses custom value for base', async () => { 110 - const client: Parameters<typeof writeCore>[2] = { 109 + const client: Parameters<typeof writeCore>[1] = { 111 110 enumNames: [], 112 111 models: [], 113 112 server: 'http://localhost:8080', ··· 133 132 useOptions: true, 134 133 }); 135 134 136 - await writeCore(openApi, '/', client, templates); 135 + await writeCore('/', client, templates); 137 136 138 137 expect(templates.core.settings).toHaveBeenCalledWith({ 139 138 $config: config,
+1 -6
packages/openapi-ts/src/utils/write/client.ts
··· 81 81 82 82 // deprecated files 83 83 await writeClientClass(openApi, outputPath, client, templates); 84 - await writeCore( 85 - openApi, 86 - path.resolve(config.output, 'core'), 87 - client, 88 - templates, 89 - ); 84 + await writeCore(path.resolve(config.output, 'core'), client, templates); 90 85 91 86 await processIndex({ files }); 92 87
+13 -16
packages/openapi-ts/src/utils/write/core.ts
··· 7 7 } from 'node:fs'; 8 8 import path from 'node:path'; 9 9 10 - import type { OpenApi } from '../../openApi'; 11 10 import type { Client } from '../../types/client'; 12 11 import { getConfig } from '../config'; 13 12 import { getHttpRequestName } from '../getHttpRequestName'; ··· 15 14 16 15 /** 17 16 * Generate OpenAPI core files, this includes the basic boilerplate code to handle requests. 18 - * @param openApi {@link OpenApi} Dereferenced OpenAPI specification 19 17 * @param outputPath Directory to write the generated files to 20 18 * @param client Client containing models, schemas, and services 21 19 * @param templates The loaded handlebar templates 22 20 */ 23 21 export const writeCore = async ( 24 - openApi: OpenApi, 25 22 outputPath: string, 26 23 client: Client, 27 24 templates: Templates, 28 25 ): Promise<void> => { 29 26 const config = getConfig(); 30 27 31 - const context = { 32 - httpRequest: getHttpRequestName(config.client), 33 - server: config.base !== undefined ? config.base : client.server, 34 - version: client.version, 35 - }; 28 + if (config.exportCore) { 29 + const context = { 30 + httpRequest: getHttpRequestName(config.client), 31 + server: config.base !== undefined ? config.base : client.server, 32 + version: client.version, 33 + }; 36 34 37 - rmSync(path.resolve(outputPath), { 38 - force: true, 39 - recursive: true, 40 - }); 41 - mkdirSync(path.resolve(outputPath), { 42 - recursive: true, 43 - }); 35 + rmSync(path.resolve(outputPath), { 36 + force: true, 37 + recursive: true, 38 + }); 39 + mkdirSync(path.resolve(outputPath), { 40 + recursive: true, 41 + }); 44 42 45 - if (config.exportCore) { 46 43 await writeFileSync( 47 44 path.resolve(outputPath, 'OpenAPI.ts'), 48 45 templates.core.settings({