diff options
author | Fabio Berger <me@fabioberger.com> | 2017-06-01 20:46:09 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-06-01 20:46:09 +0800 |
commit | c74b16eda9465104e1969b1635ac826835d203eb (patch) | |
tree | ecf750865f425d65a830fb786359ad07451a805c /src/utils | |
parent | 0991191a9b6c00fac80cd9f5ffa8e76c62f82eb5 (diff) | |
download | dexon-sol-tools-c74b16eda9465104e1969b1635ac826835d203eb.tar dexon-sol-tools-c74b16eda9465104e1969b1635ac826835d203eb.tar.gz dexon-sol-tools-c74b16eda9465104e1969b1635ac826835d203eb.tar.bz2 dexon-sol-tools-c74b16eda9465104e1969b1635ac826835d203eb.tar.lz dexon-sol-tools-c74b16eda9465104e1969b1635ac826835d203eb.tar.xz dexon-sol-tools-c74b16eda9465104e1969b1635ac826835d203eb.tar.zst dexon-sol-tools-c74b16eda9465104e1969b1635ac826835d203eb.zip |
Add convertToJSONSchemaCompatibleObject method
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/schema_validator.ts | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/utils/schema_validator.ts b/src/utils/schema_validator.ts index cf45d0343..9ff7259d9 100644 --- a/src/utils/schema_validator.ts +++ b/src/utils/schema_validator.ts @@ -5,6 +5,13 @@ import {tokenSchema} from '../schemas/token_schema'; 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 represenation. 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: object): object { + return JSON.parse(JSON.stringify(obj)); + } constructor() { this.validator = new Validator(); this.validator.addSchema(tokenSchema, tokenSchema.id); |