From 8ea3d2d05834b5928fca0f0a2a4f7e7013da3315 Mon Sep 17 00:00:00 2001 From: everm039 Date: Mon, 15 Dec 2025 10:08:02 -0800 Subject: [PATCH 1/4] fix: allow custom redocly file using --redocly --- packages/openapi-typescript/bin/cli.js | 20 ++++++++++++++++---- packages/openapi-typescript/test/cli.test.ts | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/openapi-typescript/bin/cli.js b/packages/openapi-typescript/bin/cli.js index c3a589dc5..d3afb9561 100755 --- a/packages/openapi-typescript/bin/cli.js +++ b/packages/openapi-typescript/bin/cli.js @@ -188,10 +188,22 @@ async function main() { const input = flags._[0]; - // load Redocly config - const maybeRedoc = findConfig(flags.redocly ? path.dirname(flags.redocly) : undefined); - const redocly = maybeRedoc - ? await loadConfig({ configPath: maybeRedoc }) + // load Redocly config (respect explicit --redocly path if provided) + let redocConfigPath; + if (flags.redocly) { + const explicitPath = path.resolve(flags.redocly); + if (fs.existsSync(explicitPath)) { + const stat = fs.statSync(explicitPath); + redocConfigPath = stat.isDirectory() ? findConfig(explicitPath) : explicitPath; + } + if (!redocConfigPath) { + errorAndExit(`Redocly config not found at: ${flags.redocly}`); + } + } else { + redocConfigPath = findConfig(); + } + const redocly = redocConfigPath + ? await loadConfig({ configPath: redocConfigPath }) : await createConfig({}, { extends: ["minimal"] }); // handle Redoc APIs diff --git a/packages/openapi-typescript/test/cli.test.ts b/packages/openapi-typescript/test/cli.test.ts index aef23e167..b61aed0d5 100644 --- a/packages/openapi-typescript/test/cli.test.ts +++ b/packages/openapi-typescript/test/cli.test.ts @@ -160,6 +160,21 @@ describe("CLI", () => { } }); + test("--redocly explicit config path", async () => { + const altOutput = new URL("./test/fixtures/redocly-flag/output-alt/", root); + fs.rmSync(altOutput, { recursive: true, force: true }); + + await execa(cmd, ["--redocly", "test/fixtures/redocly-flag/redocly.alt.yaml"], { + cwd, + }); + + for (const schema of ["a", "b", "c"]) { + await expect( + fs.readFileSync(new URL(`./test/fixtures/redocly-flag/output-alt/${schema}.ts`, root), "utf8"), + ).toMatchFileSnapshot(fileURLToPath(new URL("./examples/simple-example.ts", root))); + } + }); + test.skipIf(os.platform() === "win32")("lint error", async () => { const cwd = new URL("./fixtures/redocly-lint-error", import.meta.url); From 8bad1703f9911776071365ea97ab61005587e2ca Mon Sep 17 00:00:00 2001 From: everm039 Date: Tue, 16 Dec 2025 17:13:28 -0800 Subject: [PATCH 2/4] chore: include the fixture --- .../test/fixtures/redocly-flag/.gitignore | 1 + .../test/fixtures/redocly-flag/redocly.alt.yaml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 packages/openapi-typescript/test/fixtures/redocly-flag/redocly.alt.yaml diff --git a/packages/openapi-typescript/test/fixtures/redocly-flag/.gitignore b/packages/openapi-typescript/test/fixtures/redocly-flag/.gitignore index 53752db25..16cd5bdde 100644 --- a/packages/openapi-typescript/test/fixtures/redocly-flag/.gitignore +++ b/packages/openapi-typescript/test/fixtures/redocly-flag/.gitignore @@ -1 +1,2 @@ output +output-alt diff --git a/packages/openapi-typescript/test/fixtures/redocly-flag/redocly.alt.yaml b/packages/openapi-typescript/test/fixtures/redocly-flag/redocly.alt.yaml new file mode 100644 index 000000000..208cfa768 --- /dev/null +++ b/packages/openapi-typescript/test/fixtures/redocly-flag/redocly.alt.yaml @@ -0,0 +1,16 @@ +extends: + - recommended + +apis: + a@v1: + root: ./openapi/a.yaml + x-openapi-ts: + output: ./output-alt/a.ts + b@v1: + root: ./openapi/b.yaml + x-openapi-ts: + output: ./output-alt/b.ts + c@v1: + root: ./openapi/c.yaml + x-openapi-ts: + output: ./output-alt/c.ts From afcb321d6324d565515aab5bd03652e65f035800 Mon Sep 17 00:00:00 2001 From: everm039 Date: Mon, 2 Feb 2026 10:53:42 -0800 Subject: [PATCH 3/4] chore: refactor for clarity --- packages/openapi-typescript/bin/cli.js | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/openapi-typescript/bin/cli.js b/packages/openapi-typescript/bin/cli.js index d3afb9561..2c411c37b 100755 --- a/packages/openapi-typescript/bin/cli.js +++ b/packages/openapi-typescript/bin/cli.js @@ -167,6 +167,18 @@ function done(input, output, time) { console.log(`🚀 ${c.green(`${input} → ${c.bold(output)}`)} ${c.dim(`[${formatTime(time)}]`)}`); } +function findRedocConfigPath() { + if (!flags.redocly) { + return findConfig(); + } + const explicitPath = path.resolve(flags.redocly); + if (!fs.existsSync(explicitPath)) { + return undefined; + } + const stat = fs.statSync(explicitPath); + return stat.isDirectory() ? findConfig(explicitPath) : explicitPath; +} + async function main() { if ("help" in flags) { // biome-ignore lint/suspicious/noConsole: this is a CLI @@ -188,19 +200,9 @@ async function main() { const input = flags._[0]; - // load Redocly config (respect explicit --redocly path if provided) - let redocConfigPath; - if (flags.redocly) { - const explicitPath = path.resolve(flags.redocly); - if (fs.existsSync(explicitPath)) { - const stat = fs.statSync(explicitPath); - redocConfigPath = stat.isDirectory() ? findConfig(explicitPath) : explicitPath; - } - if (!redocConfigPath) { - errorAndExit(`Redocly config not found at: ${flags.redocly}`); - } - } else { - redocConfigPath = findConfig(); + const redocConfigPath = findRedocConfigPath(); + if (flags.redocly && !redocConfigPath) { + errorAndExit(`Redocly config not found at: ${flags.redocly}`); } const redocly = redocConfigPath ? await loadConfig({ configPath: redocConfigPath }) From d67d384e1bf233f340269ce38ae46042dc4cc08f Mon Sep 17 00:00:00 2001 From: everm039 Date: Tue, 3 Feb 2026 12:29:58 -0800 Subject: [PATCH 4/4] chore: added changeset --- .changeset/short-cougars-hear.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/short-cougars-hear.md diff --git a/.changeset/short-cougars-hear.md b/.changeset/short-cougars-hear.md new file mode 100644 index 000000000..736e44139 --- /dev/null +++ b/.changeset/short-cougars-hear.md @@ -0,0 +1,5 @@ +--- +"openapi-typescript": patch +--- + +Fixes the `--redocly` flag so that it no longer hangs and is able to lookup the Redocly file at a custom path