aboutsummaryrefslogtreecommitdiffstats
path: root/packages/json-schemas
diff options
context:
space:
mode:
authorFabio B <kandinsky454@protonmail.ch>2019-01-09 18:27:22 +0800
committerGitHub <noreply@github.com>2019-01-09 18:27:22 +0800
commit5dd55491b86bf8577405e37d0f2d668aa1273b10 (patch)
treedbcc96a20935ca97b24bc6a6066d72796b806ea1 /packages/json-schemas
parentc1bf2754a8638d568685e09269155464cb216a90 (diff)
parent28aa12691e00344fe80bd022188a1e7657397aa5 (diff)
downloaddexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.tar
dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.tar.gz
dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.tar.bz2
dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.tar.lz
dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.tar.xz
dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.tar.zst
dexon-sol-tools-5dd55491b86bf8577405e37d0f2d668aa1273b10.zip
Merge pull request #1494 from 0xProject/feature/order-watcher/dockerize
Dockerize OrderWatcher WS Server
Diffstat (limited to 'packages/json-schemas')
-rw-r--r--packages/json-schemas/src/schema_validator.ts8
1 files changed, 8 insertions, 0 deletions
diff --git a/packages/json-schemas/src/schema_validator.ts b/packages/json-schemas/src/schema_validator.ts
index 3f303137b..43647b594 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 _assertSchemaDefined(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._assertSchemaDefined(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._assertSchemaDefined(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,7 @@ export class SchemaValidator {
* @returns The results of the validation
*/
public validate(instance: any, schema: Schema): ValidatorResult {
+ SchemaValidator._assertSchemaDefined(schema);
const jsonSchemaCompatibleObject = JSON.parse(JSON.stringify(instance));
return this._validator.validate(jsonSchemaCompatibleObject, schema);
}