diff options
author | Fabio Berger <me@fabioberger.com> | 2019-01-09 00:07:10 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2019-01-09 00:07:10 +0800 |
commit | e2df4b355ba97e4212f5e42251defe8d9e432763 (patch) | |
tree | e07019190442929469dd3bb699db86794fdb822a /packages | |
parent | 5e39eae84edc2bb8ad4d40936bf2005363dc1e59 (diff) | |
download | dexon-0x-contracts-e2df4b355ba97e4212f5e42251defe8d9e432763.tar dexon-0x-contracts-e2df4b355ba97e4212f5e42251defe8d9e432763.tar.gz dexon-0x-contracts-e2df4b355ba97e4212f5e42251defe8d9e432763.tar.bz2 dexon-0x-contracts-e2df4b355ba97e4212f5e42251defe8d9e432763.tar.lz dexon-0x-contracts-e2df4b355ba97e4212f5e42251defe8d9e432763.tar.xz dexon-0x-contracts-e2df4b355ba97e4212f5e42251defe8d9e432763.tar.zst dexon-0x-contracts-e2df4b355ba97e4212f5e42251defe8d9e432763.zip |
Add assertions to catch trying to add undefined schemas
Diffstat (limited to 'packages')
-rw-r--r-- | packages/json-schemas/src/schema_validator.ts | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/packages/json-schemas/src/schema_validator.ts b/packages/json-schemas/src/schema_validator.ts index 3f303137b..6ccd981be 100644 --- a/packages/json-schemas/src/schema_validator.ts +++ b/packages/json-schemas/src/schema_validator.ts @@ -8,12 +8,18 @@ import { schemas } from './schemas'; */ export class SchemaValidator { private readonly _validator: Validator; + private static _assertSchemaNotUndefined(schema: Schema): void { + if (schema === undefined) { + throw new Error(`Cannot add undefined schema`); + } + } /** * Instantiates a SchemaValidator instance */ constructor() { this._validator = new Validator(); for (const schema of values(schemas)) { + SchemaValidator._assertSchemaNotUndefined(schema); this._validator.addSchema(schema, schema.id); } } @@ -24,6 +30,7 @@ export class SchemaValidator { * @param schema The schema to add */ public addSchema(schema: Schema): void { + SchemaValidator._assertSchemaNotUndefined(schema); this._validator.addSchema(schema, schema.id); } // In order to validate a complex JS object using jsonschema, we must replace any complex @@ -37,6 +44,8 @@ export class SchemaValidator { * @returns The results of the validation */ public validate(instance: any, schema: Schema): ValidatorResult { + console.log('validating....'); + SchemaValidator._assertSchemaNotUndefined(schema); const jsonSchemaCompatibleObject = JSON.parse(JSON.stringify(instance)); return this._validator.validate(jsonSchemaCompatibleObject, schema); } |