Skip to content

Commit d35de42

Browse files
committed
since validation results contain warnings, do not throw on warns
1 parent f1c775c commit d35de42

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

src/openAPIGenerator.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -195,23 +195,29 @@ class OpenAPIGenerator {
195195

196196
this.log(`Validating generated OpenAPI Description`, this.logTypes.NOTICE);
197197

198-
await generator.validate().catch((err) => {
198+
const validationResults = await generator.validate().catch((err) => {
199199
this.log(
200200
`ERROR: An error was thrown validating the OpenAPI v3 Description`,
201201
this.logTypes.ERROR
202202
);
203203

204-
this.validationErrorDetails(err);
204+
throw new this.serverless.classes.Error(err);
205+
});
205206

206-
if (this.config.validationWarn === false) {
207-
let message = "Error validating OpenAPI Description:\r\n";
208-
for (const errorMessage of err) {
209-
message += `${errorMessage.message}\r\n`;
210-
}
207+
this.validationErrorDetails(validationResults);
211208

212-
throw new this.serverless.classes.Error(message);
209+
if (validationResults.length && this.config.validationWarn === false) {
210+
let message = "Error validating OpenAPI Description:\r\n";
211+
let shouldThrow = false;
212+
for (const error of validationResults) {
213+
message += `${error.message}\r\n`;
214+
if (error.severity === "error") {
215+
shouldThrow = true;
216+
}
213217
}
214-
});
218+
219+
if (shouldThrow) throw new this.serverless.classes.Error(message);
220+
}
215221

216222
this.log(
217223
"OpenAPI v3 Description Successfully Generated",
@@ -306,24 +312,30 @@ class OpenAPIGenerator {
306312
this.config = config;
307313
}
308314

309-
validationErrorDetails(validationError) {
310-
this.log(
311-
`${chalk.bold.yellow(
312-
"[VALIDATION]"
313-
)} Validation errors found in OpenAPI Description: \n`,
314-
this.logTypes.ERROR
315-
);
316-
317-
for (const error of validationError) {
315+
validationErrorDetails(validationErrors) {
316+
if (validationErrors.length) {
318317
this.log(
319-
`${chalk.bold.yellow("Message:")} ${error.message}`,
318+
`${chalk.bold.yellow(
319+
"[VALIDATION]"
320+
)} Validation errors found in OpenAPI Description: \n`,
320321
this.logTypes.ERROR
321322
);
322-
for (const location of error.location) {
323+
324+
for (const error of validationErrors) {
323325
this.log(
324-
`${chalk.bold.yellow("found at location:")} ${location.pointer}`,
326+
`${chalk.bold.red("Severity:")} ${error.severity}`,
325327
this.logTypes.ERROR
326328
);
329+
this.log(
330+
`${chalk.bold.yellow("Message:")} ${error.message}`,
331+
this.logTypes.ERROR
332+
);
333+
for (const location of error.location) {
334+
this.log(
335+
`${chalk.bold.yellow("found at location:")} ${location.pointer}`,
336+
this.logTypes.ERROR
337+
);
338+
}
327339
}
328340
}
329341
}

0 commit comments

Comments
 (0)