From 097d0a1bac09bb9bc28ca14281af8c51d46619d0 Mon Sep 17 00:00:00 2001 From: Matsuuu Date: Thu, 27 Mar 2025 10:29:34 +0200 Subject: [PATCH 1/4] feat: disable writing a log file via a --no-log-file flag --- packages/openapi-ts/bin/index.cjs | 5 + packages/openapi-ts/src/index.ts | 3 +- packages/openapi-ts/src/initConfigs.ts | 2 + packages/openapi-ts/src/types/config.d.ts | 113 +++++++++++----------- 4 files changed, 68 insertions(+), 55 deletions(-) diff --git a/packages/openapi-ts/bin/index.cjs b/packages/openapi-ts/bin/index.cjs index 5d7a1d813..16a86df53 100755 --- a/packages/openapi-ts/bin/index.cjs +++ b/packages/openapi-ts/bin/index.cjs @@ -34,6 +34,10 @@ const params = program 'DEPRECATED. Manually set base in OpenAPI config instead of inferring from server value', ) .option('-s, --silent', 'Set log level to silent') + .option( + '--no-log-file', + 'Disable writing a log file. Works like --silent but without supressing console output', + ) .option( '-w, --watch [value]', 'Regenerate the client when the input file changes?', @@ -83,6 +87,7 @@ async function start() { userConfig = processParams(params, [ 'dryRun', + 'logFile', 'experimentalParser', 'exportCore', 'useOptions', diff --git a/packages/openapi-ts/src/index.ts b/packages/openapi-ts/src/index.ts index 4dd53041f..2998d4653 100644 --- a/packages/openapi-ts/src/index.ts +++ b/packages/openapi-ts/src/index.ts @@ -67,10 +67,11 @@ export const createClient = async ( } catch (error) { const config = configs[0] as Config | undefined; const dryRun = config ? config.dryRun : resolvedConfig?.dryRun; + const writeLogFile = config ? config.logFile : resolvedConfig?.logFile; // TODO: add setting for log output if (!dryRun) { const logs = config?.logs ?? getLogs(resolvedConfig); - if (logs.level !== 'silent') { + if (logs.level !== 'silent' && writeLogFile) { const logName = `openapi-ts-error-${Date.now()}.log`; const logsDir = path.resolve(process.cwd(), logs.path ?? ''); ensureDirSync(logsDir); diff --git a/packages/openapi-ts/src/initConfigs.ts b/packages/openapi-ts/src/initConfigs.ts index 5d0a3fcbb..38465e3e9 100644 --- a/packages/openapi-ts/src/initConfigs.ts +++ b/packages/openapi-ts/src/initConfigs.ts @@ -269,6 +269,7 @@ export const initConfigs = async ( dryRun = false, experimentalParser = true, exportCore = true, + logFile = true, name, request, useOptions = true, @@ -311,6 +312,7 @@ export const initConfigs = async ( experimentalParser, exportCore: false, input, + logFile, logs, name, output, diff --git a/packages/openapi-ts/src/types/config.d.ts b/packages/openapi-ts/src/types/config.d.ts index ac52416e3..692577d78 100644 --- a/packages/openapi-ts/src/types/config.d.ts +++ b/packages/openapi-ts/src/types/config.d.ts @@ -135,6 +135,23 @@ export interface UserConfig { | (string & {}) | Record | Input; + /** + * @deprecated + * + * Opt in to the experimental parser? + * + * @default true + */ + experimentalParser?: boolean; + + /** + * @deprecated + * + * Generate core client classes? + * + * @default true + */ + exportCore?: boolean; /** * The relative location of the logs folder * @@ -175,6 +192,48 @@ export interface UserConfig { */ path?: string; }; + /** + * Whether or not error logs should be written to a file or not + * */ + logFile: boolean; + /** + * Regenerate the client when the input file changes? You can alternatively + * pass a numeric value for the interval in ms. + * + * @default false + */ + watch?: + | boolean + | number + | { + /** + * Regenerate the client when the input file changes? + * + * @default false + */ + enabled?: boolean; + /** + * How often should we attempt to detect the input file change? (in ms) + * + * @default 1000 + */ + interval?: number; + /** + * How long will we wait before the request times out? + * + * @default 60_000 + */ + timeout?: number; + }; + /** + * @deprecated + * + * Custom client class name. Please note this option is deprecated and + * will be removed in favor of clients. + * + * @link https://heyapi.dev/openapi-ts/migrating.html#deprecated-name + */ + name?: string; /** * The relative location of the output folder */ @@ -230,35 +289,6 @@ export interface UserConfig { * @default ['@hey-api/typescript', '@hey-api/sdk'] */ plugins?: ReadonlyArray; - /** - * Regenerate the client when the input file changes? You can alternatively - * pass a numeric value for the interval in ms. - * - * @default false - */ - watch?: - | boolean - | number - | { - /** - * Regenerate the client when the input file changes? - * - * @default false - */ - enabled?: boolean; - /** - * How often should we attempt to detect the input file change? (in ms) - * - * @default 1000 - */ - interval?: number; - /** - * How long will we wait before the request times out? - * - * @default 60_000 - */ - timeout?: number; - }; /** * @deprecated * @@ -266,31 +296,6 @@ export interface UserConfig { */ // eslint-disable-next-line typescript-sort-keys/interface base?: string; - /** - * @deprecated - * - * Opt in to the experimental parser? - * - * @default true - */ - experimentalParser?: boolean; - /** - * @deprecated - * - * Generate core client classes? - * - * @default true - */ - exportCore?: boolean; - /** - * @deprecated - * - * Custom client class name. Please note this option is deprecated and - * will be removed in favor of clients. - * - * @link https://heyapi.dev/openapi-ts/migrating.html#deprecated-name - */ - name?: string; /** * @deprecated * From 50c3a7f2d8d168300b23e22b8128014a7f8c7cd7 Mon Sep 17 00:00:00 2001 From: Matsuuu Date: Thu, 27 Mar 2025 10:39:42 +0200 Subject: [PATCH 2/4] fix: make logFile optional in config --- packages/openapi-ts/bin/index.cjs | 2 + packages/openapi-ts/src/getLogs.ts | 1 + packages/openapi-ts/src/index.ts | 4 +- packages/openapi-ts/src/initConfigs.ts | 2 - packages/openapi-ts/src/types/config.d.ts | 120 +++++++++++----------- 5 files changed, 66 insertions(+), 63 deletions(-) diff --git a/packages/openapi-ts/bin/index.cjs b/packages/openapi-ts/bin/index.cjs index 16a86df53..f00a98ef9 100755 --- a/packages/openapi-ts/bin/index.cjs +++ b/packages/openapi-ts/bin/index.cjs @@ -118,6 +118,8 @@ async function start() { userConfig.logs.level = 'silent'; } + userConfig.logs.file = userConfig.logFile; + if (typeof params.watch === 'string') { userConfig.watch = Number.parseInt(params.watch, 10); } diff --git a/packages/openapi-ts/src/getLogs.ts b/packages/openapi-ts/src/getLogs.ts index 77d6703da..d09b5d6d7 100644 --- a/packages/openapi-ts/src/getLogs.ts +++ b/packages/openapi-ts/src/getLogs.ts @@ -2,6 +2,7 @@ import type { Config, UserConfig } from './types/config'; export const getLogs = (userConfig: UserConfig | undefined): Config['logs'] => { let logs: Config['logs'] = { + file: true, level: 'info', path: process.cwd(), }; diff --git a/packages/openapi-ts/src/index.ts b/packages/openapi-ts/src/index.ts index 2998d4653..7f23c95f2 100644 --- a/packages/openapi-ts/src/index.ts +++ b/packages/openapi-ts/src/index.ts @@ -67,11 +67,11 @@ export const createClient = async ( } catch (error) { const config = configs[0] as Config | undefined; const dryRun = config ? config.dryRun : resolvedConfig?.dryRun; - const writeLogFile = config ? config.logFile : resolvedConfig?.logFile; + // TODO: add setting for log output if (!dryRun) { const logs = config?.logs ?? getLogs(resolvedConfig); - if (logs.level !== 'silent' && writeLogFile) { + if (logs.level !== 'silent' && logs.file) { const logName = `openapi-ts-error-${Date.now()}.log`; const logsDir = path.resolve(process.cwd(), logs.path ?? ''); ensureDirSync(logsDir); diff --git a/packages/openapi-ts/src/initConfigs.ts b/packages/openapi-ts/src/initConfigs.ts index 38465e3e9..5d0a3fcbb 100644 --- a/packages/openapi-ts/src/initConfigs.ts +++ b/packages/openapi-ts/src/initConfigs.ts @@ -269,7 +269,6 @@ export const initConfigs = async ( dryRun = false, experimentalParser = true, exportCore = true, - logFile = true, name, request, useOptions = true, @@ -312,7 +311,6 @@ export const initConfigs = async ( experimentalParser, exportCore: false, input, - logFile, logs, name, output, diff --git a/packages/openapi-ts/src/types/config.d.ts b/packages/openapi-ts/src/types/config.d.ts index 692577d78..690b968f0 100644 --- a/packages/openapi-ts/src/types/config.d.ts +++ b/packages/openapi-ts/src/types/config.d.ts @@ -135,23 +135,6 @@ export interface UserConfig { | (string & {}) | Record | Input; - /** - * @deprecated - * - * Opt in to the experimental parser? - * - * @default true - */ - experimentalParser?: boolean; - - /** - * @deprecated - * - * Generate core client classes? - * - * @default true - */ - exportCore?: boolean; /** * The relative location of the logs folder * @@ -160,6 +143,12 @@ export interface UserConfig { logs?: | string | { + /** + * Whether or not error logs should be written to a file or not + * + * @default true + * */ + file?: boolean; /** * The logging level to control the verbosity of log output. * Determines which messages are logged based on their severity. @@ -185,6 +174,7 @@ export interface UserConfig { | 'silent' | 'trace' | 'warn'; + /** * The relative location of the logs folder * @@ -192,48 +182,6 @@ export interface UserConfig { */ path?: string; }; - /** - * Whether or not error logs should be written to a file or not - * */ - logFile: boolean; - /** - * Regenerate the client when the input file changes? You can alternatively - * pass a numeric value for the interval in ms. - * - * @default false - */ - watch?: - | boolean - | number - | { - /** - * Regenerate the client when the input file changes? - * - * @default false - */ - enabled?: boolean; - /** - * How often should we attempt to detect the input file change? (in ms) - * - * @default 1000 - */ - interval?: number; - /** - * How long will we wait before the request times out? - * - * @default 60_000 - */ - timeout?: number; - }; - /** - * @deprecated - * - * Custom client class name. Please note this option is deprecated and - * will be removed in favor of clients. - * - * @link https://heyapi.dev/openapi-ts/migrating.html#deprecated-name - */ - name?: string; /** * The relative location of the output folder */ @@ -289,6 +237,35 @@ export interface UserConfig { * @default ['@hey-api/typescript', '@hey-api/sdk'] */ plugins?: ReadonlyArray; + /** + * Regenerate the client when the input file changes? You can alternatively + * pass a numeric value for the interval in ms. + * + * @default false + */ + watch?: + | boolean + | number + | { + /** + * Regenerate the client when the input file changes? + * + * @default false + */ + enabled?: boolean; + /** + * How often should we attempt to detect the input file change? (in ms) + * + * @default 1000 + */ + interval?: number; + /** + * How long will we wait before the request times out? + * + * @default 60_000 + */ + timeout?: number; + }; /** * @deprecated * @@ -296,6 +273,31 @@ export interface UserConfig { */ // eslint-disable-next-line typescript-sort-keys/interface base?: string; + /** + * @deprecated + * + * Opt in to the experimental parser? + * + * @default true + */ + experimentalParser?: boolean; + /** + * @deprecated + * + * Generate core client classes? + * + * @default true + */ + exportCore?: boolean; + /** + * @deprecated + * + * Custom client class name. Please note this option is deprecated and + * will be removed in favor of clients. + * + * @link https://heyapi.dev/openapi-ts/migrating.html#deprecated-name + */ + name?: string; /** * @deprecated * From a6448acafd41239b704e8afee44264755900833f Mon Sep 17 00:00:00 2001 From: Matsuuu Date: Thu, 27 Mar 2025 11:49:13 +0200 Subject: [PATCH 3/4] fix: tests should have log file set --- packages/openapi-ts/src/generate/__tests__/class.test.ts | 1 + packages/openapi-ts/src/generate/__tests__/core.test.ts | 3 +++ packages/openapi-ts/src/generate/__tests__/index.test.ts | 1 + packages/openapi-ts/src/generate/__tests__/output.test.ts | 1 + packages/openapi-ts/src/openApi/__tests__/index.test.ts | 1 + .../src/plugins/@hey-api/schemas/__tests__/schemas.test.ts | 2 ++ .../src/plugins/@hey-api/sdk/__tests__/plugin.test.ts | 4 ++++ .../src/plugins/@hey-api/typescript/__tests__/plugin.test.ts | 1 + packages/openapi-ts/src/utils/__tests__/handlebars.test.ts | 2 ++ packages/openapi-ts/src/utils/__tests__/parse.test.ts | 1 + 10 files changed, 17 insertions(+) diff --git a/packages/openapi-ts/src/generate/__tests__/class.test.ts b/packages/openapi-ts/src/generate/__tests__/class.test.ts index 53e51af27..463c028b6 100644 --- a/packages/openapi-ts/src/generate/__tests__/class.test.ts +++ b/packages/openapi-ts/src/generate/__tests__/class.test.ts @@ -20,6 +20,7 @@ describe('generateLegacyClientClass', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, diff --git a/packages/openapi-ts/src/generate/__tests__/core.test.ts b/packages/openapi-ts/src/generate/__tests__/core.test.ts index 6f7a09f60..f3a55be99 100644 --- a/packages/openapi-ts/src/generate/__tests__/core.test.ts +++ b/packages/openapi-ts/src/generate/__tests__/core.test.ts @@ -35,6 +35,7 @@ describe('generateLegacyCore', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, @@ -127,6 +128,7 @@ describe('generateLegacyCore', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, @@ -202,6 +204,7 @@ describe('generateLegacyCore', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, diff --git a/packages/openapi-ts/src/generate/__tests__/index.test.ts b/packages/openapi-ts/src/generate/__tests__/index.test.ts index d2ec50db3..9280ee5a6 100644 --- a/packages/openapi-ts/src/generate/__tests__/index.test.ts +++ b/packages/openapi-ts/src/generate/__tests__/index.test.ts @@ -20,6 +20,7 @@ describe('generateIndexFile', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, diff --git a/packages/openapi-ts/src/generate/__tests__/output.test.ts b/packages/openapi-ts/src/generate/__tests__/output.test.ts index 151d42a56..35132adae 100644 --- a/packages/openapi-ts/src/generate/__tests__/output.test.ts +++ b/packages/openapi-ts/src/generate/__tests__/output.test.ts @@ -21,6 +21,7 @@ describe('generateLegacyOutput', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, diff --git a/packages/openapi-ts/src/openApi/__tests__/index.test.ts b/packages/openapi-ts/src/openApi/__tests__/index.test.ts index 1f31ccd66..3fb61ba55 100644 --- a/packages/openapi-ts/src/openApi/__tests__/index.test.ts +++ b/packages/openapi-ts/src/openApi/__tests__/index.test.ts @@ -18,6 +18,7 @@ vi.mock('../3.1.x', () => ({ vi.mock('../../utils/config', () => { const config: Partial = { logs: { + file: false, level: 'silent', path: '', }, diff --git a/packages/openapi-ts/src/plugins/@hey-api/schemas/__tests__/schemas.test.ts b/packages/openapi-ts/src/plugins/@hey-api/schemas/__tests__/schemas.test.ts index 1c3f4dbb2..264ab950b 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/schemas/__tests__/schemas.test.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/schemas/__tests__/schemas.test.ts @@ -21,6 +21,7 @@ describe('generateLegacySchemas', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, @@ -109,6 +110,7 @@ describe('generateLegacySchemas', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, diff --git a/packages/openapi-ts/src/plugins/@hey-api/sdk/__tests__/plugin.test.ts b/packages/openapi-ts/src/plugins/@hey-api/sdk/__tests__/plugin.test.ts index 6deb0ef2e..6cbca25bc 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/sdk/__tests__/plugin.test.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/sdk/__tests__/plugin.test.ts @@ -24,6 +24,7 @@ describe('handlerLegacy', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, @@ -184,6 +185,7 @@ describe('methodNameBuilder', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, @@ -266,6 +268,7 @@ describe('methodNameBuilder', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, @@ -351,6 +354,7 @@ describe('methodNameBuilder', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, diff --git a/packages/openapi-ts/src/plugins/@hey-api/typescript/__tests__/plugin.test.ts b/packages/openapi-ts/src/plugins/@hey-api/typescript/__tests__/plugin.test.ts index 6f6137de3..9e7b533eb 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/typescript/__tests__/plugin.test.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/typescript/__tests__/plugin.test.ts @@ -21,6 +21,7 @@ describe('generateLegacyTypes', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, diff --git a/packages/openapi-ts/src/utils/__tests__/handlebars.test.ts b/packages/openapi-ts/src/utils/__tests__/handlebars.test.ts index 30194aeda..13a7239bb 100644 --- a/packages/openapi-ts/src/utils/__tests__/handlebars.test.ts +++ b/packages/openapi-ts/src/utils/__tests__/handlebars.test.ts @@ -18,6 +18,7 @@ describe('registerHandlebarHelpers', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, @@ -84,6 +85,7 @@ describe('registerHandlebarTemplates', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, diff --git a/packages/openapi-ts/src/utils/__tests__/parse.test.ts b/packages/openapi-ts/src/utils/__tests__/parse.test.ts index 9ea94f73a..26e372986 100644 --- a/packages/openapi-ts/src/utils/__tests__/parse.test.ts +++ b/packages/openapi-ts/src/utils/__tests__/parse.test.ts @@ -13,6 +13,7 @@ describe('operationNameFn', () => { path: '', }, logs: { + file: true, level: 'info', path: process.cwd(), }, From 6971f5bca4dd17ea65400c504ad0a4ffb083a38b Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 27 Mar 2025 10:05:28 +0000 Subject: [PATCH 4/4] Create dull-pianos-enjoy.md --- .changeset/dull-pianos-enjoy.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dull-pianos-enjoy.md diff --git a/.changeset/dull-pianos-enjoy.md b/.changeset/dull-pianos-enjoy.md new file mode 100644 index 000000000..6b1968570 --- /dev/null +++ b/.changeset/dull-pianos-enjoy.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +feat: ability to disable writing a log file via a `--no-log-file` flag or `logs.file` = `false`