@@ -6,38 +6,37 @@ const util = require('util');
6
6
7
7
const yaml = require ( 'yaml' ) ;
8
8
const 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' ) ;
12
10
13
11
const schema = { } ;
14
12
schema [ "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' ) ) ;
16
13
schema [ "v3.0" ] = yaml . parse ( fs . readFileSync ( './schemas/v3.0/schema.yaml' , 'utf8' ) ) ;
17
14
18
- validator . addSchema ( schema . draft4 ) ;
15
+ jsonschema . add ( schema [ "v2.0" ] ) ;
16
+ jsonschema . add ( schema [ "v3.0" ] ) ;
19
17
20
18
async function main ( path , schema , propName ) {
21
19
return new Promise ( async function ( resolve , reject ) {
22
20
let files = await rf ( path , { readContents : false , filenameFormat : rf . FULL_PATH } ) ;
23
21
files = files . sort ( ) ;
24
22
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 ;
27
25
try {
28
- contentObj = yaml . parse ( contentStr , { prettyErrors :true } ) ;
26
+ instanceObj = yaml . parse ( instanceStr , { prettyErrors :true } ) ;
29
27
}
30
28
catch ( ex ) {
31
29
process . exitCode = 1 ;
32
30
console . warn ( file , ex . message ) ;
33
31
}
34
- if ( contentObj && contentObj [ propName ] ) {
32
+ if ( instanceObj && instanceObj [ propName ] ) {
35
33
console . log ( 'Validating' , file ) ;
36
34
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 ) {
39
38
process . exitCode = 1 ;
40
- console . warn ( file , util . inspect ( result . errors ) ) ;
39
+ console . warn ( file , util . inspect ( result . errors , { depth : null } ) ) ;
41
40
}
42
41
}
43
42
catch ( ex ) {
0 commit comments