Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/short-cougars-hear.md
Original file line number Diff line number Diff line change
@@ -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
22 changes: 18 additions & 4 deletions packages/openapi-typescript/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -188,10 +200,12 @@ 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 })
const redocConfigPath = findRedocConfigPath();
if (flags.redocly && !redocConfigPath) {
errorAndExit(`Redocly config not found at: ${flags.redocly}`);
}
const redocly = redocConfigPath
? await loadConfig({ configPath: redocConfigPath })
: await createConfig({}, { extends: ["minimal"] });

// handle Redoc APIs
Expand Down
15 changes: 15 additions & 0 deletions packages/openapi-typescript/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
output
output-alt
Original file line number Diff line number Diff line change
@@ -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