Skip to content

fix(reject): fix reject and exit with code 1 if error #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,20 @@ program
)
.option(
"-r, --responses",
"generate additional information about request responses\n" +
"also add typings for bad responses",
"generate additional information about request responses\n" + "also add typings for bad responses",
false,
)
.option("--union-enums", 'generate all "enum" types as union types (T1 | T2 | TN)', false)
.option("--route-types", "generate type definitions for API routes", false)
.option("--no-client", "do not generate an API class", false)
.option(
"--enum-names-as-values",
"use values in 'x-enumNames' as enum values (not only as keys)",
false,
)
.option("--enum-names-as-values", "use values in 'x-enumNames' as enum values (not only as keys)", false)
.option(
"--extract-request-params",
"extract request params to data contract (Also combine path params and query params into one object)",
false,
)
.option("--extract-request-body", "extract request body type to data contract", false)
.option(
"--modular",
"generate separated files for http client, data contracts, and routes",
false,
)
.option("--modular", "generate separated files for http client, data contracts, and routes", false)
.option("--js", "generate js api module with declaration file", false)
.option(
"--module-name-index <number>",
Expand All @@ -72,11 +63,7 @@ program
.option("--default-response <type>", "default type for empty response schema", TS_KEYWORDS.VOID)
.option("--type-prefix <string>", "data contract name prefix", "")
.option("--type-suffix <string>", "data contract name suffix", "")
.option(
"--clean-output",
"clean output folder before generate api. WARNING: May cause data loss",
false,
)
.option("--clean-output", "clean output folder before generate api. WARNING: May cause data loss", false)
.option("--patch", "fix up small errors in the swagger source definition", false);

program.parse(process.argv);
Expand Down Expand Up @@ -140,4 +127,9 @@ generateApi({
typePrefix,
typeSuffix,
patch: !!patch,
}).catch((err) => {
// NOTE collect all errors on top level and shows to users in any case
console.error(err);

process.exit(1);
});
10 changes: 8 additions & 2 deletions src/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const parseSwaggerFile = (file) => {
};

const getSwaggerFile = (pathToSwagger, urlToSwagger, disableStrictSSL, disableProxy) =>
new Promise((resolve) => {
new Promise((resolve, reject) => {
if (pathIsExist(pathToSwagger)) {
logger.log(`try to get swagger by path "${pathToSwagger}"`);
resolve(getFileContent(pathToSwagger));
Expand All @@ -38,7 +38,13 @@ const getSwaggerFile = (pathToSwagger, urlToSwagger, disableStrictSSL, disablePr
axios
.get(urlToSwagger, axiosOptions)
.then((res) => resolve(res.data))
.catch((err) => logger.error(`error while getting swagger by URL ${urlToSwagger}:`, err));
.catch(() => {
const message = `error while getting swagger by URL ${urlToSwagger}`;

logger.error(message);

reject(message);
});
}
});

Expand Down