Skip to content

Commit 852dce7

Browse files
authored
fix: don't allow conversion if there are errors in the results of the validation (#1584)
1 parent a51064a commit 852dce7

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

packages/core/src/utils/logger.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@ export const createSuccessMessage = (backend?: string) =>
4848

4949
export const ibmOpenapiValidatorWarnings = (
5050
warnings: {
51-
path: string;
51+
path: string[];
5252
message: string;
5353
}[],
5454
) => {
5555
log(chalk.yellow('(!) Warnings'));
5656

5757
warnings.forEach((i) =>
58-
log(chalk.yellow(`Message : ${i.message}\nPath : ${i.path}`)),
58+
log(chalk.yellow(`Message : ${i.message}\nPath : ${i.path.join(', ')}`)),
5959
);
6060
};
6161

6262
export const ibmOpenapiValidatorErrors = (
6363
errors: {
64-
path: string;
64+
path: string[];
6565
message: string;
6666
}[],
6767
) => {
6868
log(chalk.red('(!) Errors'));
6969

7070
errors.forEach((i) =>
71-
log(chalk.red(`Message : ${i.message}\nPath : ${i.path}`)),
71+
log(chalk.red(`Message : ${i.message}\nPath : ${i.path.join(', ')}`)),
7272
);
7373
};
7474

packages/core/src/utils/validator.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,30 @@ const { Spectral } = require('@stoplight/spectral-core');
1515
export const ibmOpenapiValidator = async (specs: OpenAPIObject) => {
1616
const spectral = new Spectral();
1717
spectral.setRuleset(ibmOpenapiRuleset);
18-
const { errors, warnings } = await spectral.run(specs);
18+
const results = await spectral.run(specs);
1919

20-
if (warnings && warnings.length) {
20+
const errors: { message: string; path: string[] }[] = [];
21+
const warnings: { message: string; path: string[] }[] = [];
22+
23+
for (const { severity, message, path } of results) {
24+
const entry = { message, path };
25+
// 0: error, 1: "warning", see: https://github.com/IBM/openapi-validator/blob/a93e18a156108b6b946727d0b24bbcc69095b72e/packages/validator/src/spectral/spectral-validator.js#L222
26+
switch (severity) {
27+
case 0:
28+
errors.push(entry);
29+
break;
30+
case 1:
31+
warnings.push(entry);
32+
break;
33+
}
34+
}
35+
36+
if (warnings.length) {
2137
ibmOpenapiValidatorWarnings(warnings);
2238
}
2339

24-
if (errors && errors.length) {
40+
if (errors.length) {
2541
ibmOpenapiValidatorErrors(errors);
42+
process.exit(1);
2643
}
2744
};

0 commit comments

Comments
 (0)