import * as Jsonschema from 'jsonschema' ; import * as Winston from 'winston' ; export const validateJson = ( input , schema , description , logger ) => { const validationResult = Jsonschema . validate ( input , schema ) ; if ( validationResult . valid ) { logger . verbose ( `${ description } json is valid` ) ; } else { const error = new Error ( ) ; const errorAt = validationResult . errors . map ( ( validationError , index ) => `\n${ index }. error at ${ JSON . stringify ( validationError . instance ) }` ) . reduce ( ( previous , current ) => ( previous += current ) ) ; error . message = `${ description } json is invalid${ errorAt }` ; throw error ; } } ;