File tree Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -48,27 +48,27 @@ export const createSuccessMessage = (backend?: string) =>
48
48
49
49
export const ibmOpenapiValidatorWarnings = (
50
50
warnings : {
51
- path : string ;
51
+ path : string [ ] ;
52
52
message : string ;
53
53
} [ ] ,
54
54
) => {
55
55
log ( chalk . yellow ( '(!) Warnings' ) ) ;
56
56
57
57
warnings . forEach ( ( i ) =>
58
- log ( chalk . yellow ( `Message : ${ i . message } \nPath : ${ i . path } ` ) ) ,
58
+ log ( chalk . yellow ( `Message : ${ i . message } \nPath : ${ i . path . join ( ', ' ) } ` ) ) ,
59
59
) ;
60
60
} ;
61
61
62
62
export const ibmOpenapiValidatorErrors = (
63
63
errors : {
64
- path : string ;
64
+ path : string [ ] ;
65
65
message : string ;
66
66
} [ ] ,
67
67
) => {
68
68
log ( chalk . red ( '(!) Errors' ) ) ;
69
69
70
70
errors . forEach ( ( i ) =>
71
- log ( chalk . red ( `Message : ${ i . message } \nPath : ${ i . path } ` ) ) ,
71
+ log ( chalk . red ( `Message : ${ i . message } \nPath : ${ i . path . join ( ', ' ) } ` ) ) ,
72
72
) ;
73
73
} ;
74
74
Original file line number Diff line number Diff line change @@ -15,13 +15,30 @@ const { Spectral } = require('@stoplight/spectral-core');
15
15
export const ibmOpenapiValidator = async ( specs : OpenAPIObject ) => {
16
16
const spectral = new Spectral ( ) ;
17
17
spectral . setRuleset ( ibmOpenapiRuleset ) ;
18
- const { errors , warnings } = await spectral . run ( specs ) ;
18
+ const results = await spectral . run ( specs ) ;
19
19
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 ) {
21
37
ibmOpenapiValidatorWarnings ( warnings ) ;
22
38
}
23
39
24
- if ( errors && errors . length ) {
40
+ if ( errors . length ) {
25
41
ibmOpenapiValidatorErrors ( errors ) ;
42
+ process . exit ( 1 ) ;
26
43
}
27
44
} ;
You can’t perform that action at this time.
0 commit comments