[CLI] Hangs when Options (-/-- flags) are out-of-order
openapi-typescript version
7.10.1
Node.js version
24.7.0
OS + version
macOS 15.6.1
Description
This unfortunately burned way too much of my time to manually stick debug prints and find out how the parsing works.
When providing flags such as --array-length as the first parameters, the CLI will interpret them as part of the schema-file instead of flags and just hang during the resolution under this code:
if (schema instanceof node_stream.Readable) {
const contents = await new Promise((resolve) => {
schema.resume();
schema.setEncoding("utf8");
let content = "";
schema.on("data", (chunk) => {
content += chunk;
});
schema.on("end", () => {
resolve(content.trim());
});
});
Reproduction
Run any flag such as --array-length before providing the schema
DEBUG=* npx openapi-typescript --array-length ./openapi.json -o ./generated-api.d.ts
Expected result
Parse flags using a CLI library such as yargs OR validate a minimal startswith("-") to alert user of how to use
Required
- [x] My OpenAPI schema is valid and passes the Redocly validator (
npx @redocly/cli@latest lint)
Extra
- [x] I’m willing to open a PR (see CONTRIBUTING.md)
I have noticed the same issue. This also means you can't point at specific redocly configs (or at least I can't).
Assuming a redocly.yaml file is present, the following works fine:
DEBUG=* openapi-typescript
Assuming a redocly-hello.yaml file is present, the following hangs forever:
DEBUG=* openapi-typescript --redocly "./redocly-hello.yaml"
Output is:
openapi-ts:redoc 0ms Loaded Redoc config
And that's it, it hangs there.
Since openapi-typescript is now in maintenance mode, this is fixed in openapi-typesafe, a maintained fork of openapi-typescript, openapi-fetch and openapi-react-query: kebab-case boolean flags before the schema path no longer take the path as their value, so the CLI does not hang. Apart from fixes like this one, the CLI flags, Node API and output match openapi-typescript 7.13, and npx openapi-typesafe-migrate --write moves a project over. https://github.com/openapi-typesafe/openapi-typesafe
The 1.0 release candidate is on npm: npm i -D openapi-typesafe@next.