11import { URL } from 'url'
2- import Ajv , { ValidateFunction , Options } from 'ajv'
2+ import Ajv , { ValidateFunction , Options } from 'ajv/dist/2019 '
33import addKeywords from 'ajv-keywords'
44import addFormats from 'ajv-formats'
5+ import draft7MetaSchema from "ajv/dist/refs/json-schema-draft-07.json"
56import callsite = require( 'callsite' )
67import { InvalidOperationError , io , NotFoundError } from 'common-errors'
78import _debug = require( 'debug' )
89import fs = require( 'fs' )
910import { promises as fsAsync } from 'fs'
1011import glob = require( 'glob' )
1112import path = require( 'path' )
13+
1214import { HttpStatusError } from './HttpStatusError'
1315
1416const debug = _debug ( '@microfleet/validation' )
@@ -49,12 +51,12 @@ export class Validator {
4951 removeAdditional : false ,
5052 useDefaults : true ,
5153 verbose : true ,
52- } ;
54+ }
5355
54- private readonly schemaDir : string | undefined ;
55- private readonly $ajv : Ajv ;
56- private readonly filterOpt : globFilter ;
57- private readonly schemaOptions : Options ;
56+ private readonly schemaDir : string | undefined
57+ private readonly $ajv : Ajv
58+ private readonly filterOpt : globFilter
59+ private readonly schemaOptions : Options
5860
5961 /**
6062 * Initializes validator with schemas in the schemaDir with a given filter function
@@ -89,6 +91,7 @@ export class Validator {
8991 return false
9092 }
9193 } )
94+ ajvInstance . addMetaSchema ( draft7MetaSchema )
9295
9396 addKeywords ( ajvInstance )
9497 addFormats ( ajvInstance )
@@ -238,7 +241,7 @@ export class Validator {
238241 } )
239242 } )
240243 } catch ( err ) {
241- const error = new io . IOError ( `was unable to read ${ dir } ` , err )
244+ const error = new io . IOError ( `was unable to read ${ dir } ` , err as Error )
242245 throw error
243246 }
244247 }
@@ -252,7 +255,7 @@ export class Validator {
252255
253256 return glob . sync ( '**' , { cwd : dir } )
254257 } catch ( err ) {
255- const error = new io . IOError ( `was unable to read ${ dir } ` , err )
258+ const error = new io . IOError ( `was unable to read ${ dir } ` , err as Error )
256259 throw error
257260 }
258261 }
@@ -305,7 +308,7 @@ export class Validator {
305308 * @param schema - schema name
306309 * @param data
307310 */
308- private $validate < T extends unknown = unknown > ( schema : string , data : unknown ) : ValidationResponse < T > {
311+ private $validate < T = unknown > ( schema : string , data : unknown ) : ValidationResponse < T > {
309312 const validate = this . $ajv . getSchema < T > ( schema )
310313
311314 if ( ! validate ) {
0 commit comments