@@ -149,23 +149,9 @@ class Parser {
149149 // Non-fatal errors, so let us try and create annotations for them and
150150 // continue with the parsing as best we can.
151151 if ( err . details ) {
152- const queue = [ err . details ] ;
153-
154- while ( queue . length ) {
155- _ . forEach ( queue [ 0 ] , ( item ) => {
156- this . createAnnotation ( annotations . VALIDATION_ERROR , item . path , item . message ) ;
157-
158- if ( item . inner ) {
159- // TODO: I am honestly not sure what the correct behavior is
160- // here. Some items will have within them a tree of other items,
161- // some of which might contain more info (but it's unclear).
162- // Do we treat them as their own error or do something else?
163- queue . push ( item . inner ) ;
164- }
165- } ) ;
166-
167- queue . shift ( ) ;
168- }
152+ err . details . forEach ( ( error ) => {
153+ this . createValidationAnnotation ( error ) ;
154+ } ) ;
169155
170156 return done ( null , this . result ) ;
171157 }
@@ -1562,7 +1548,24 @@ class Parser {
15621548
15631549 // Create annotation from swagger-parser error (ZSchema validation)
15641550 createValidationAnnotation ( error ) {
1565- this . createAnnotation ( annotations . VALIDATION_ERROR , error . path , error . message ) ;
1551+ let message ;
1552+
1553+ if ( error . code === 'ENUM_MISMATCH' ) {
1554+ const enumerations = error [ ZSchema . schemaSymbol ] . enum . map ( ( item , index , items ) => {
1555+ if ( index === items . length - 1 ) {
1556+ return `or '${ item } '` ;
1557+ }
1558+
1559+ return `'${ item } '` ;
1560+ } ) . join ( ', ' ) ;
1561+
1562+ const value = error . params [ 0 ] ;
1563+ message = `Value must be either ${ enumerations } not '${ value } '` ;
1564+ } else {
1565+ ( { message } = error ) ;
1566+ }
1567+
1568+ this . createAnnotation ( annotations . VALIDATION_ERROR , error . path , message ) ;
15661569
15671570 if ( error . inner ) {
15681571 error . inner . forEach ( ( innerError ) => {
0 commit comments