Skip to content

Conversation

@mynnx
Copy link
Contributor

@mynnx mynnx commented Dec 15, 2025

Changes

Resolves #2190 in which the CLI hangs when specifying a different path for redocly.yaml using the --redocly CLI flag. We've got several redocly.yaml files so this fix is necessary for us.

The old code only called findConfig on the dirname() of the argument you passed, looking for a redocly.yaml in that directory - so it wasn't looking for the file path you specified on the command line. In addition, when it couldn't find a path, it silently fell back to a minimal config waiting on input with a valid config.

Now it looks for either

  • a redocly.yaml file in the directory you've specified (old behavior), or
  • the specific file you're pointing at

and has clear error messages when it can't be found.

How to Review

Run the new test, or:

Happy path

 node packages/openapi-typescript/bin/cli.js \
  --redocly packages/openapi-typescript/test/fixtures/redocly-flag/redocly.alt.yaml
 ⚠  Component: "Problem" is never used. at #/components/schemas/Problem
🚀 b@v1 → ./output-alt/b.ts [53.7ms]
 ⚠  Component: "Problem" is never used. at #/components/schemas/Problem
🚀 a@v1 → ./output-alt/a.ts [64.2ms]
 ⚠  Component: "Problem" is never used. at #/components/schemas/Problem
🚀 c@v1 → ./output-alt/c.ts [74.9ms]

Failure path

 node packages/openapi-typescript/bin/cli.js \
  --redocly packages/openapi-typescript/test/fixtures/redocly-flag/NOT_A_REAL_FILE.yaml 
 ✘  Redocly config not found at: packages/openapi-typescript/test/fixtures/redocly-flag/redocly.alt.yam
file:///Users/mark.everett/Development/tmp/openapi-typescript/packages/openapi-typescript/bin/cli.js:161
  throw new Error(message);
        ^

Error: Redocly config not found at: packages/openapi-typescript/test/fixtures/redocly-flag/redocly.alt.yam
    at errorAndExit (file:///Users/mark.everett/Development/tmp/openapi-typescript/packages/openapi-typescript/bin/cli.js:161:9)
    ...

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • [] pnpm run update:examples run (only applicable for openapi-typescript)
    • ☝️  ERR_PNPM_NO_SCRIPT  Missing script: update:examples

@mynnx mynnx requested a review from a team as a code owner December 15, 2025 18:25
@mynnx mynnx requested a review from kerwanp December 15, 2025 18:25
@netlify
Copy link

netlify bot commented Dec 15, 2025

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit d67d384

@changeset-bot
Copy link

changeset-bot bot commented Dec 15, 2025

🦋 Changeset detected

Latest commit: d67d384

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
openapi-typescript Patch
swr-openapi Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mynnx
Copy link
Contributor Author

mynnx commented Jan 6, 2026

@drwpow or another maintainer, any chance I can get a review on this?

Copy link
Contributor

@duncanbeevers duncanbeevers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, though you might consider extracting this new, slightly-more-complicated config-finding functionality to a helper function.

  const input = flags._[0];

  // load Redocly config (respect explicit --redocly path if provided)
  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;
  }

  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"] });

@mynnx
Copy link
Contributor Author

mynnx commented Feb 2, 2026

Thanks for the suggestion @duncanbeevers - much clearer! Does @kerwanp need to review to get this merged?

@duncanbeevers
Copy link
Contributor

@mynnx Would you go ahead and add a a changeset file to the PR?
The changeset-bot comment explains how to add one.
This is new, backwards-compatible functionality, so it should be a minor level patch, per semver 2

@mynnx
Copy link
Contributor Author

mynnx commented Feb 3, 2026

@mynnx Would you go ahead and add a a changeset file to the PR? The changeset-bot comment explains how to add one. This is new, backwards-compatible functionality, so it should be a minor level patch, per semver 2

done!

@duncanbeevers duncanbeevers merged commit 4385590 into openapi-ts:main Feb 3, 2026
7 checks passed
@openapi-ts-bot openapi-ts-bot mentioned this pull request Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Providing --redocly option does nothing if redocly.yaml file exists, and hangs if it doesn't

2 participants