diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-06-10 18:23:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-10 18:23:41 +0800 |
commit | 1cff9fdf77e39aa707f2a13a00d07d73543f0f00 (patch) | |
tree | e69bcf1bdb24de596023dbf55f2a464600c36a38 /src/utils | |
parent | 81e3b180a9f764989bc76e68a1d55006e2eff80e (diff) | |
parent | b739ae24944876c28a2ff474993e72a7178b3d1b (diff) | |
download | dexon-sol-tools-1cff9fdf77e39aa707f2a13a00d07d73543f0f00.tar dexon-sol-tools-1cff9fdf77e39aa707f2a13a00d07d73543f0f00.tar.gz dexon-sol-tools-1cff9fdf77e39aa707f2a13a00d07d73543f0f00.tar.bz2 dexon-sol-tools-1cff9fdf77e39aa707f2a13a00d07d73543f0f00.tar.lz dexon-sol-tools-1cff9fdf77e39aa707f2a13a00d07d73543f0f00.tar.xz dexon-sol-tools-1cff9fdf77e39aa707f2a13a00d07d73543f0f00.tar.zst dexon-sol-tools-1cff9fdf77e39aa707f2a13a00d07d73543f0f00.zip |
Merge branch 'master' into subscribe-async-tests
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/schema_validator.ts | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/utils/schema_validator.ts b/src/utils/schema_validator.ts index 755f6e715..9097dce88 100644 --- a/src/utils/schema_validator.ts +++ b/src/utils/schema_validator.ts @@ -7,13 +7,6 @@ import {orderFillOrKillRequestsSchema} from '../schemas/order_fill_or_kill_reque export class SchemaValidator { private validator: Validator; - // In order to validate a complex JS object using jsonschema, we must replace any complex - // sub-types (e.g BigNumber) with a simpler string representation. Since BigNumber and other - // complex types implement the `toString` method, we can stringify the object and - // then parse it. The resultant object can then be checked using jsonschema. - public static convertToJSONSchemaCompatibleObject(obj: any): any { - return JSON.parse(JSON.stringify(obj)); - } constructor() { this.validator = new Validator(); this.validator.addSchema(tokenSchema, tokenSchema.id); @@ -25,7 +18,12 @@ export class SchemaValidator { this.validator.addSchema(ecSignatureParameterSchema, ecSignatureParameterSchema.id); this.validator.addSchema(orderFillOrKillRequestsSchema, orderFillOrKillRequestsSchema.id); } - public validate(instance: object, schema: Schema): ValidatorResult { - return this.validator.validate(instance, schema); + // In order to validate a complex JS object using jsonschema, we must replace any complex + // sub-types (e.g BigNumber) with a simpler string representation. Since BigNumber and other + // complex types implement the `toString` method, we can stringify the object and + // then parse it. The resultant object can then be checked using jsonschema. + public validate(instance: any, schema: Schema): ValidatorResult { + const jsonSchemaCompatibleObject = JSON.parse(JSON.stringify(instance)); + return this.validator.validate(jsonSchemaCompatibleObject, schema); } } |