PR checklist
-
Read the contribution guidelines. -
Ran the shell script under ./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
. -
Filed the PR against the correct branch: Default: master
. -
Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
Description of the PR
Errors in Generate/Validate print to stderr/exit 1
Generate and Validate exposed exceptions rather than user-friendly messages when an error occurred. In generate, this could happen for numerous reasons, but the most likely is a user typing (or guessing) an invalid generator name. In Validate, an error was exposed if there were any validation errors in a spec.
New behavior:
- Generate now exposes a typed exception when a generator cannot be loaded by name. This allows consistent messaging for load failures.
- Generate now presents guidance on failure (check the spelling and try again). This is purely a usability improvement.
- Validate now writes validation errors to stderr and exits with code 1. Improve err messages: config-help/required opts.
- config-help now presents same error for invalid generator names as the 'generate' command.
- Options which are required, and those which require a value, now present a user-friendly hint at the error and exit with code 1 (rather than an uncaught exception).
Examples
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar config-help -g asdf
Can't load config class with name 'asdf'
Available:
ada
…(removed)
typescript-node
[error] Check the spelling of the generator's name and try again.
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ~/temp/specs/petstore-v3.0.yaml -g php2
Can't load config class with name 'php2'
Available:
ada
…(removed)
typescript-node
[error] Check the spelling of the generator's name and try again.
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar validate -i ~/temp/specs/petstore-v3.0-invalid.yaml
Validating spec (/Users/jim/temp/specs/petstore-v3.0-invalid.yaml)
- attribute info is missing
[error] Spec is invalid.
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ~/temp/specs/petstore-v3.0.yaml
[error] A generator name (--generator-name / -g) is required.
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ~/temp/specs/petstore-v3.0.yaml -g
[error] Required values for option 'generator name' not provided
All of the above examples exit with status 1.
See #167 (closed)