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.

fix: respect logs setting if initialization fails

Lubos ​ 9afbf666 96053a5e

+53 -27
+5
.changeset/mighty-bulldogs-kiss.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix: respect logs setting if initialization fails
-17
packages/openapi-ts-tests/test/bin.test.ts
··· 164 164 ); 165 165 }); 166 166 167 - it('throws error with wrong client', () => { 168 - const result = sync('node', [ 169 - path.resolve(__dirname, '..', '..', 'openapi-ts', 'bin', 'index.cjs'), 170 - '--input', 171 - path.resolve(__dirname, 'spec', 'v3.json'), 172 - '--output', 173 - path.resolve(__dirname, 'generated', 'bin'), 174 - '--client', 175 - 'invalid/client', 176 - '--dry-run', 177 - 'true', 178 - ]); 179 - expect(result.stdout.toString()).toBe(''); 180 - expect(result.stderr.toString()).toContain('encountered an error'); 181 - expect(result.stderr.toString()).toContain('client needs to be set'); 182 - }); 183 - 184 167 it('displays help', () => { 185 168 const result = sync('node', [ 186 169 path.resolve(__dirname, '..', '..', 'openapi-ts', 'bin', 'index.cjs'),
+7 -2
packages/openapi-ts/src/index.ts
··· 32 32 const resolvedConfig = 33 33 typeof userConfig === 'function' ? await userConfig() : userConfig; 34 34 35 - let configs: Config[] = []; 35 + const configs: Array<Config> = []; 36 36 37 37 try { 38 38 Performance.start('createClient'); 39 39 40 40 Performance.start('config'); 41 - configs = await initConfigs(resolvedConfig); 41 + for (const result of await initConfigs(resolvedConfig)) { 42 + configs.push(result.config); 43 + if (result.errors.length) { 44 + throw result.errors[0]; 45 + } 46 + } 42 47 Performance.end('config'); 43 48 44 49 Performance.start('handlebars');
+41 -8
packages/openapi-ts/src/initConfigs.ts
··· 332 332 */ 333 333 export const initConfigs = async ( 334 334 userConfig: UserConfig | undefined, 335 - ): Promise<Config[]> => { 335 + ): Promise< 336 + ReadonlyArray<{ 337 + config: Config; 338 + errors: ReadonlyArray<Error>; 339 + }> 340 + > => { 336 341 let configurationFile: string | undefined = undefined; 337 342 if (userConfig?.configFile) { 338 343 const parts = userConfig.configFile.split('.'); ··· 350 355 ? configFromFile.map((config) => mergeConfigs(config, userConfig)) 351 356 : [mergeConfigs(configFromFile, userConfig)]; 352 357 353 - return userConfigs.map((userConfig) => { 358 + const results: Array<{ 359 + config: Config; 360 + errors: Array<Error>; 361 + }> = []; 362 + 363 + for (const userConfig of userConfigs) { 354 364 const { 355 365 base, 356 366 configFile = '', ··· 361 371 request, 362 372 useOptions = true, 363 373 } = userConfig; 374 + 375 + const errors: Array<Error> = []; 364 376 365 377 const logs = getLogs(userConfig); 366 378 ··· 372 384 const output = getOutput(userConfig); 373 385 374 386 if (!input.path) { 375 - throw new Error( 376 - 'missing input - which OpenAPI specification should we use to generate your output?', 387 + errors.push( 388 + new Error( 389 + 'missing input - which OpenAPI specification should we use to generate your output?', 390 + ), 377 391 ); 378 392 } 379 393 380 394 if (!output.path) { 381 - throw new Error('missing output - where should we generate your output?'); 395 + errors.push( 396 + new Error('missing output - where should we generate your output?'), 397 + ); 382 398 } 383 399 384 400 if (!useOptions) { ··· 389 405 390 406 output.path = path.resolve(process.cwd(), output.path); 391 407 408 + let plugins: Pick<Config, 'plugins' | 'pluginOrder'>; 409 + 410 + try { 411 + plugins = getPlugins(userConfig); 412 + } catch (error) { 413 + errors.push(error); 414 + plugins = { 415 + pluginOrder: [], 416 + plugins: {}, 417 + }; 418 + } 419 + 392 420 const config = setConfig({ 393 - ...getPlugins(userConfig), 421 + ...plugins, 394 422 base, 395 423 configFile, 396 424 dryRun, ··· 409 437 console.warn('config:', config); 410 438 } 411 439 412 - return config; 413 - }); 440 + results.push({ 441 + config, 442 + errors, 443 + }); 444 + } 445 + 446 + return results; 414 447 };