Repository navigation
Conversation
…env var to locate openapitools.json - resolution order: explicit flag (-c/--config or --openapitools) > OPENAPI_GENERATOR_CLI_CONFIG env var > ./openapitools.json (default, unchanged when neither is set) - relative paths are resolved against the cwd - fail fast with a clear error when an explicitly set config path does not exist - version-manager resolve argv detection now also skips the new option forms Fixes OpenAPITools#782
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
…mand name
The global '-c, --config <path>' option collided with the Java generator's
own 'generate -c, --config <config file>' option (upstream Generate.java
defines name = {"-c", "--config"} for its generator configuration file).
Commander consumes registered root options from the whole argv - in both
parseOptions (used by ConfigService) and parse - so '-c' after 'generate'
was captured as the openapitools.json path: the CLI exited with 1 when
that path did not exist, and the generator config never reached the Java
process because commander had removed it from the subcommand arguments.
Of the two discussed options, excluding the invoked command's argv from
the global -c parsing (option a) is the only correct minimal fix: keeping
the option registered would keep the collision, and dropping only the
short alias would not be enough because the Java generate command also
defines the long '--config' form. The documented UX is preserved:
- the global -c/--config option is no longer registered with commander;
it is still listed in the root help and only honored BEFORE the command
name via extractGlobalConfigArgs(), which understands all option forms
(-c <path>, -c<path>, --config <path>, --config=<path>). Everything
after the first positional argument belongs to the invoked command and
is passed through untouched, which also covers commands other than
'generate'.
- AppModule hands commander an argv without the global config options, so
an unrecognized option before the command name cannot bury the command
(commander would otherwise skip its dispatch and print help).
- --openapitools keeps its existing behavior (registered root option,
honored in any position).
Also clear the shared 'error' mock between tests in
config.service.spec.ts so each missing-file assertion only sees its own
test's log output.
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 5 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
- the scan now skips root options that take their own value (--custom-generator, in both separate and inline forms) together with their values, so --custom-generator ./gen.jar -c my.json resolve does not silently lose the config path - a trailing -c/--config without a value is rejected with a clear error instead of silently falling back to the environment variable or the default ./openapitools.json - the spec suite clears OPENAPI_GENERATOR_CLI_CONFIG in the top-level beforeEach, so a host shell exporting it cannot push every ConfigService construction in the suite onto the not-found path
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #782
What
Adds a way to point
openapi-generator-cliat anopenapitools.jsonoutside the current working directory (monorepo use-case):-c, --config <path>on the root command — the existing--openapitools <openapitools.json>option is kept and works as an aliasOPENAPI_GENERATOR_CLI_CONFIGenvironment variable as a fallback, so the path can be supplied without changing the command line (e.g. in CI)Resolution order: explicit flag >
OPENAPI_GENERATOR_CLI_CONFIG>./openapitools.json(default).Behavior guarantees:
./openapitools.jsonis used and created on first run, exactly as beforeDesign note: design comment on #782.
How
ConfigService.configFileOrDefault()resolves the location (flag > env var > default). It remains the single source of truth for every read/write ofopenapitools.json, so all commands (version-manager list/set/resolve,use,generate, pass-through) pick it up without further changes.AppModuleregisters the new option on the root program, andisVersionManagerResolveCommand()now also skips the new option forms (-c <path>,--config <path>,--config=<path>,-c<path>) when scanning argv.Tests
Unit tests (
config.service.spec.ts,app.module.spec.ts):-c/--configand via--openapitools(existing behavior kept)OPENAPI_GENERATOR_CLI_CONFIG./openapitools.jsonunchanged when neither is setprocess.exit(1)version-manager resolvedetection skips the new option formsFull suite: 263 tests / 7 suites passing, plus lint and build, run in a
node:20Docker container. Manually smoke-tested the built CLI: valid flag, valid env var, precedence (flag wins), missing-path error paths, and the untouched default flow.Summary by cubic
Lets the CLI point at an
openapitools.jsonoutside the current working directory, for monorepos and CI.-c, --config <path>option before the command name, with--openapitoolskept as a working alias; it is not registered with commander to avoid colliding with the Java generator's owngenerate -c/--configoption, but is listed in help and stripped from the argv handed to commander.OPENAPI_GENERATOR_CLI_CONFIGenv var as a fallback; resolution order is flag, env var, then the default./openapitools.json(unchanged when neither is set).-c/--configafter it belong to the invoked command and pass through untouched.--custom-generator) are skipped together with that value, so the config path after them is still found.-c/--configwithout a value is rejected with a clear error instead of silently falling back to the env var or the default file.Written for commit 31864a8. Summary will update on new commits.