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 #3540 from hey-api/fix/plugin-infer-warn

fix: show warning when plugin infer fails

authored by

Lubos and committed by
GitHub
2bfc2d07 fe5bfba6

+45 -11
+5
.changeset/fluffy-facts-film.md
··· 1 + --- 2 + "@hey-api/codegen-core": patch 3 + --- 4 + 5 + **log**: make group optional in warn method
+5
.changeset/soft-cars-cover.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + **config(plugins)**: show warning when plugin infer fails
+2 -2
packages/codegen-core/src/log.ts
··· 55 55 console.debug(`${prefix} ${message}`); 56 56 } 57 57 58 - function warn(message: string, group: keyof typeof WarnGroups) { 58 + function warn(message: string, group?: keyof typeof WarnGroups) { 59 59 if (NO_WARNINGS) return; 60 60 61 - const color = WarnGroups[group] ?? colors.yellowBright; 61 + const color = group ? WarnGroups[group] : colors.yellowBright; 62 62 63 63 console.warn(color(`${message}`)); 64 64 }
+33 -9
packages/openapi-ts/src/plugins/@hey-api/sdk/config.ts
··· 1 + import { log } from '@hey-api/codegen-core'; 1 2 import { definePluginConfig } from '@hey-api/shared'; 2 3 3 4 import { resolveExamples } from './examples'; 4 5 import { resolveOperations } from './operations'; 5 6 import { handler } from './plugin'; 6 7 import type { HeyApiSdkPlugin } from './types'; 8 + 9 + const transformerInferWarn = 10 + 'You set `transformer: true` but no transformer plugin was found in your plugins. Add a transformer plugin like `@hey-api/transformers` to enable this feature. The transformer option has been disabled.'; 11 + const validatorInferWarn = 12 + 'You set `validator: true` but no validator plugin was found in your plugins. Add a validator plugin like `zod` to enable this feature. The validator option has been disabled.'; 7 13 8 14 export const defaultConfig: HeyApiSdkPlugin['Config'] = { 9 15 config: { ··· 38 44 39 45 if (plugin.config.transformer) { 40 46 if (typeof plugin.config.transformer === 'boolean') { 41 - plugin.config.transformer = context.pluginByTag('transformer'); 47 + try { 48 + plugin.config.transformer = context.pluginByTag('transformer'); 49 + plugin.dependencies.add(plugin.config.transformer!); 50 + } catch { 51 + log.warn(transformerInferWarn); 52 + plugin.config.transformer = false; 53 + } 54 + } else { 55 + plugin.dependencies.add(plugin.config.transformer); 42 56 } 43 - 44 - plugin.dependencies.add(plugin.config.transformer!); 45 57 } else { 46 58 plugin.config.transformer = false; 47 59 } ··· 55 67 56 68 if (plugin.config.validator.request) { 57 69 if (typeof plugin.config.validator.request === 'boolean') { 58 - plugin.config.validator.request = context.pluginByTag('validator'); 70 + try { 71 + plugin.config.validator.request = context.pluginByTag('validator'); 72 + plugin.dependencies.add(plugin.config.validator.request!); 73 + } catch { 74 + log.warn(validatorInferWarn); 75 + plugin.config.validator.request = false; 76 + } 77 + } else { 78 + plugin.dependencies.add(plugin.config.validator.request); 59 79 } 60 - 61 - plugin.dependencies.add(plugin.config.validator.request!); 62 80 } else { 63 81 plugin.config.validator.request = false; 64 82 } 65 83 66 84 if (plugin.config.validator.response) { 67 85 if (typeof plugin.config.validator.response === 'boolean') { 68 - plugin.config.validator.response = context.pluginByTag('validator'); 86 + try { 87 + plugin.config.validator.response = context.pluginByTag('validator'); 88 + plugin.dependencies.add(plugin.config.validator.response!); 89 + } catch { 90 + log.warn(validatorInferWarn); 91 + plugin.config.validator.response = false; 92 + } 93 + } else { 94 + plugin.dependencies.add(plugin.config.validator.response); 69 95 } 70 - 71 - plugin.dependencies.add(plugin.config.validator.response!); 72 96 } else { 73 97 plugin.config.validator.response = false; 74 98 }