@@ -3,17 +3,7 @@ import * as os from 'os';
33import * as jju from 'jju' ;
44import Validator = require( 'z-schema' ) ;
55
6- export type ValidateErrorCallback = ( errorDetail : string ) => void ;
7-
8- interface ISchemaError extends ZSchema . SchemaError {
9- // Ex. "z-schema validation error"
10- name : string ;
11- details : Array < IErrorDetail > ;
12- }
13-
14- interface IErrorDetail extends ZSchema . SchemaError {
15- inner ?: IErrorDetail [ ] ;
16- }
6+ export type ValidateErrorCallback = ( errorDescription : string ) => void ;
177
188/**
199 * Utilities for reading/writing JSON files.
@@ -30,18 +20,18 @@ export default class JsonFile {
3020 // tslint:disable-next-line:no-string-literal
3121 delete jsonSchemaObject [ '$schema' ] ;
3222
33- const validator : ZSchema . Validator = new Validator ( {
23+ const validator : Validator = new Validator ( {
3424 breakOnFirstError : false ,
3525 noTypeless : true
3626 } ) ;
3727
3828 if ( ! validator . validate ( jsonObject , jsonSchemaObject ) ) {
39- const error : ISchemaError = validator . getLastError ( ) as ISchemaError ;
29+ const errorDetails : Validator . SchemaErrorDetail [ ] = validator . getLastErrors ( ) ;
4030
41- let errorDetail : string = 'JSON schema validation failed:' ;
31+ let buffer : string = 'JSON schema validation failed:' ;
4232
43- errorDetail = JsonFile . _formatErrorDetails ( error . details , ' ' , errorDetail ) ;
44- errorCallback ( errorDetail ) ;
33+ buffer = JsonFile . _formatErrorDetails ( errorDetails , ' ' , buffer ) ;
34+ errorCallback ( buffer ) ;
4535 }
4636 }
4737
@@ -87,18 +77,17 @@ export default class JsonFile {
8777
8878 }
8979
90- private static _formatErrorDetails ( errorDetails : IErrorDetail [ ] , indent : string ,
91- result : string ) : string {
92- for ( const detail of errorDetails ) {
93- result += os . EOL + indent + `Error: ${ detail . path } ` ;
94- // result += os.EOL + indent + ` ${detail.code}`;
95- result += os . EOL + indent + ` ${ detail . message } ` ;
80+ private static _formatErrorDetails ( errorDetails : Validator . SchemaErrorDetail [ ] , indent : string ,
81+ buffer : string ) : string {
82+ for ( const errorDetail of errorDetails ) {
83+ buffer += os . EOL + indent + `Error: ${ errorDetail . path } ` ;
84+ buffer += os . EOL + indent + ` ${ errorDetail . message } ` ;
9685
97- if ( detail . inner ) {
98- result = JsonFile . _formatErrorDetails ( detail . inner , indent + ' ' , result ) ;
86+ if ( errorDetail . inner ) {
87+ buffer = JsonFile . _formatErrorDetails ( errorDetail . inner , indent + ' ' , buffer ) ;
9988 }
10089 }
101- return result ;
90+ return buffer ;
10291 }
10392
10493 /**
0 commit comments