@@ -6,38 +6,37 @@ const util = require('util');
66
77const yaml = require ( 'yaml' ) ;
88const rf = require ( 'node-readfiles' ) ;
9- const jsonschema = require ( 'jsonschema' ) . Validator ;
10- const options = { } ;
11- const validator = new jsonschema ( options ) ;
9+ const jsonschema = require ( '@hyperjump/json-schema' ) ;
1210
1311const schema = { } ;
1412schema [ "v2.0" ] = yaml . parse ( fs . readFileSync ( './schemas/v2.0/schema.json' , 'utf8' ) ) ;
15- schema . draft4 = yaml . parse ( fs . readFileSync ( './schemas/jsonSchema/draft-04/metaschema.json' , 'utf8' ) ) ;
1613schema [ "v3.0" ] = yaml . parse ( fs . readFileSync ( './schemas/v3.0/schema.yaml' , 'utf8' ) ) ;
1714
18- validator . addSchema ( schema . draft4 ) ;
15+ jsonschema . add ( schema [ "v2.0" ] ) ;
16+ jsonschema . add ( schema [ "v3.0" ] ) ;
1917
2018async function main ( path , schema , propName ) {
2119 return new Promise ( async function ( resolve , reject ) {
2220 let files = await rf ( path , { readContents : false , filenameFormat : rf . FULL_PATH } ) ;
2321 files = files . sort ( ) ;
2422 for ( let file of files ) {
25- const contentStr = fs . readFileSync ( file , 'utf8' ) ;
26- let contentObj ;
23+ const instanceStr = fs . readFileSync ( file , 'utf8' ) ;
24+ let instanceObj ;
2725 try {
28- contentObj = yaml . parse ( contentStr , { prettyErrors :true } ) ;
26+ instanceObj = yaml . parse ( instanceStr , { prettyErrors :true } ) ;
2927 }
3028 catch ( ex ) {
3129 process . exitCode = 1 ;
3230 console . warn ( file , ex . message ) ;
3331 }
34- if ( contentObj && contentObj [ propName ] ) {
32+ if ( instanceObj && instanceObj [ propName ] ) {
3533 console . log ( 'Validating' , file ) ;
3634 try {
37- const result = await validator . validate ( contentObj , schema ) ;
38- if ( result . errors && result . errors . length ) {
35+ const schemaObj = await jsonschema . get ( schema . id ) ;
36+ const result = await jsonschema . validate ( schemaObj , instanceObj , jsonschema . DETAILED ) ;
37+ if ( ! result . valid ) {
3938 process . exitCode = 1 ;
40- console . warn ( file , util . inspect ( result . errors ) ) ;
39+ console . warn ( file , util . inspect ( result . errors , { depth : null } ) ) ;
4140 }
4241 }
4342 catch ( ex ) {
0 commit comments