diff --git a/.changeset/fix-cli-kebab-flag-order.md b/.changeset/fix-cli-kebab-flag-order.md new file mode 100644 index 000000000..d5db53521 --- /dev/null +++ b/.changeset/fix-cli-kebab-flag-order.md @@ -0,0 +1,5 @@ +--- +"openapi-typescript": patch +--- + +Fix CLI hanging when multi-word flags appear before the schema file argument. Flags such as `--enum-values`, `--path-params-as-types`, `--dedupe-enums`, `--empty-objects-unknown`, and others were not recognized as boolean by the argument parser when written in kebab-case, causing the schema path to be silently consumed as the flag's value and leaving the CLI waiting on stdin. Both camelCase and kebab-case forms are now registered as boolean. diff --git a/packages/openapi-typescript/bin/cli.js b/packages/openapi-typescript/bin/cli.js index 31be6e795..65834ce00 100755 --- a/packages/openapi-typescript/bin/cli.js +++ b/packages/openapi-typescript/bin/cli.js @@ -98,8 +98,14 @@ const BOOLEAN_FLAGS = [ "rootTypesNoSchemaPrefix", ]; +// yargs-parser only recognizes boolean flags by their exact registered name, +// so --enum-values (kebab-case) is not treated as boolean unless "enum-values" +// is also in the boolean list. Generate kebab-case equivalents so positional +// args after multi-word flags aren't silently consumed as flag values. +const BOOLEAN_FLAGS_KEBAB = BOOLEAN_FLAGS.map((f) => f.replace(/([A-Z])/g, (c) => `-${c.toLowerCase()}`)); + const flags = parser(args, { - boolean: BOOLEAN_FLAGS, + boolean: [...BOOLEAN_FLAGS, ...BOOLEAN_FLAGS_KEBAB], string: ["output", "redocly"], alias: { redocly: ["c"],