From f41aaeb2c22bc322401987dcf1b37ea15cbfcafa Mon Sep 17 00:00:00 2001 From: AdoKevin Date: Tue, 9 Jun 2026 16:11:33 +0800 Subject: [PATCH 1/2] feat: add option to cli for disabling interactive api generation --- src/bin/cli.ts | 7 ++++--- src/bin/openapi.ts | 5 +++-- src/bin/utils.ts | 12 ++++++++++++ test/bin-utils.spec.ts | 13 +++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 test/bin-utils.spec.ts diff --git a/src/bin/cli.ts b/src/bin/cli.ts index e1edcd7..a61e88e 100644 --- a/src/bin/cli.ts +++ b/src/bin/cli.ts @@ -6,11 +6,12 @@ import type { GenerateServiceProps } from '../index'; import { generateService } from '../index'; import { logError } from '../log'; import { readConfig } from '../readConfig'; -import { createMultiselectOptions } from './utils'; +import { createMultiselectOptions, parseInteractiveMode } from './utils'; program .option('-cfn, --configFileName ', 'config file name') - .option('-cfp, --configFilePath ', 'config file path'); + .option('-cfp, --configFilePath ', 'config file path') + .option('-i, --interactive ', 'enable interactive mode', true); program.parse(); const options = program.opts(); @@ -37,7 +38,7 @@ async function run() { /** 是否交互式 */ let isInteractive = false; - if (configs.length > 1) { + if (configs.length > 1 && parseInteractiveMode(options.interactive)) { // 有多个配置,则交互式选择 isInteractive = true; diff --git a/src/bin/openapi.ts b/src/bin/openapi.ts index 8f1e321..4bb8273 100644 --- a/src/bin/openapi.ts +++ b/src/bin/openapi.ts @@ -10,7 +10,7 @@ import { generateService } from '../index'; import { logError } from '../log'; import { readConfig } from '../readConfig'; import type { IPriorityRule, IReactQueryMode } from '../type'; -import { createMultiselectOptions } from './utils'; +import { createMultiselectOptions, parseInteractiveMode } from './utils'; const params = program .name('openapi') @@ -107,6 +107,7 @@ const params = program '--supportParseEnumDescByReg ', 'custom regex for parsing enum description' ) + .option('-i, --interactive ', 'enable interactive mode', true) .parse(process.argv) .opts(); @@ -189,7 +190,7 @@ async function run() { /** 是否交互式 */ let isInteractive = false; - if (configs.length > 1) { + if (configs.length > 1 && parseInteractiveMode(params.interactive)) { // 有多个配置,则交互式选择 isInteractive = true; diff --git a/src/bin/utils.ts b/src/bin/utils.ts index fc971c6..3f626cb 100644 --- a/src/bin/utils.ts +++ b/src/bin/utils.ts @@ -13,3 +13,15 @@ export function createMultiselectOptions( ('schemaPath' in config ? config.schemaPath : 'Apifox Config'), })); } + +export function parseInteractiveMode(value: unknown): boolean { + if (value === undefined) { + return true; + } + + if (typeof value === 'boolean') { + return value; + } + + return JSON.parse(value as string) === true; +} diff --git a/test/bin-utils.spec.ts b/test/bin-utils.spec.ts new file mode 100644 index 0000000..1019498 --- /dev/null +++ b/test/bin-utils.spec.ts @@ -0,0 +1,13 @@ +import { describe, expect, it } from 'vitest'; + +import { parseInteractiveMode } from '../src/bin/utils'; + +describe('parseInteractiveMode', () => { + it('defaults interactive mode to enabled', () => { + expect(parseInteractiveMode(undefined)).toBe(true); + }); + + it('allows disabling interactive mode with false', () => { + expect(parseInteractiveMode('false')).toBe(false); + }); +}); From 8af5151d33f215ade35db2b6fcb907112532be77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=95=85=E5=9F=8E?= <1055120207@qq.com> Date: Wed, 10 Jun 2026 11:15:16 +0800 Subject: [PATCH 2/2] Create dry-guests-decide.md --- .changeset/dry-guests-decide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/dry-guests-decide.md diff --git a/.changeset/dry-guests-decide.md b/.changeset/dry-guests-decide.md new file mode 100644 index 0000000..cebbfa7 --- /dev/null +++ b/.changeset/dry-guests-decide.md @@ -0,0 +1,5 @@ +--- +"openapi-ts-request": patch +--- + +perf: add option to cli for disabling interactive api generation