From 8ea3d2d05834b5928fca0f0a2a4f7e7013da3315 Mon Sep 17 00:00:00 2001 From: everm039 Date: Mon, 15 Dec 2025 10:08:02 -0800 Subject: [PATCH 1/2] 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/2] 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