@@ -16,7 +16,15 @@ const supportElementSchema = module.exports.schema = require('./support-element-
16
16
17
17
module . exports . defaultPackageSupport = 'package-support.json'
18
18
19
- module . exports . validateSupportElement = ( obj ) => {
19
+ function getBetterAjvErrorsOptions ( cli ) {
20
+ const options = { format : 'js' }
21
+ if ( cli === true ) {
22
+ options . format = 'cli'
23
+ }
24
+ return options
25
+ }
26
+
27
+ module . exports . validateSupportElement = ( obj , cli = false ) => {
20
28
if ( ! ajvElement ) {
21
29
ajvElement = new Ajv ( { jsonPointers : true } )
22
30
compiledSchemaElement = ajvElement . compile ( supportElementSchema )
@@ -26,14 +34,14 @@ module.exports.validateSupportElement = (obj) => {
26
34
if ( ! validates ) {
27
35
const err = new Error ( 'Validation Failed' )
28
36
err . validationErrors = compiledSchemaElement . errors
29
- err . prettyValidationErrors = betterAjvErrors ( supportElementSchema , obj , compiledSchemaElement . errors )
37
+ err . prettyValidationErrors = betterAjvErrors ( supportElementSchema , obj , compiledSchemaElement . errors , getBetterAjvErrorsOptions ( cli ) )
30
38
err . validationSchema = compiledSchemaElement . schema
31
39
throw err
32
40
}
33
41
return true
34
42
}
35
43
36
- module . exports . validate = ( obj ) => {
44
+ module . exports . validate = ( obj , cli = false ) => {
37
45
if ( ! ajv ) {
38
46
ajv = new Ajv ( { jsonPointers : true } )
39
47
compiledSchema = ajv . compile ( schema )
@@ -43,7 +51,7 @@ module.exports.validate = (obj) => {
43
51
if ( ! validates ) {
44
52
const err = new Error ( 'Validation Failed' )
45
53
err . validationErrors = compiledSchema . errors
46
- err . prettyValidationErrors = betterAjvErrors ( schema , obj , compiledSchema . errors )
54
+ err . prettyValidationErrors = betterAjvErrors ( schema , obj , compiledSchema . errors , getBetterAjvErrorsOptions ( cli ) )
47
55
err . validationSchema = compiledSchema . schema
48
56
throw err
49
57
}
0 commit comments