From 699e588d1fda7f7e8190a4b3347905964cef2d95 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 30 May 2017 12:00:23 +0200 Subject: Add signedOrderSchema and all subschemas --- src/utils/schema_validator.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/utils/schema_validator.ts') diff --git a/src/utils/schema_validator.ts b/src/utils/schema_validator.ts index 61f4c09c8..0159b6b0b 100644 --- a/src/utils/schema_validator.ts +++ b/src/utils/schema_validator.ts @@ -1,12 +1,17 @@ import {Validator, ValidatorResult} from 'jsonschema'; import {ecSignatureSchema, ecSignatureParameter} from '../schemas/ec_signature_schema'; +import {addressSchema, bigNumberSchema, orderSchema, signedOrderSchema} from '../schemas/signed_order_schema'; export class SchemaValidator { private validator: Validator; constructor() { this.validator = new Validator(); - this.validator.addSchema(ecSignatureParameter, ecSignatureParameter.id); + this.validator.addSchema(orderSchema, orderSchema.id); + this.validator.addSchema(addressSchema, addressSchema.id); + this.validator.addSchema(bigNumberSchema, bigNumberSchema.id); this.validator.addSchema(ecSignatureSchema, ecSignatureSchema.id); + this.validator.addSchema(signedOrderSchema, signedOrderSchema.id); + this.validator.addSchema(ecSignatureParameter, ecSignatureParameter.id); } public validate(instance: object, schema: Schema): ValidatorResult { return this.validator.validate(instance, schema); -- cgit v1.2.3 From cf63e1d1a6606c1b3ab82d5fec56df8ac4128eea Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 30 May 2017 12:16:33 +0200 Subject: Change BigNumber schema to Number schema --- src/utils/schema_validator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/utils/schema_validator.ts') diff --git a/src/utils/schema_validator.ts b/src/utils/schema_validator.ts index 0159b6b0b..5b2c4aaa5 100644 --- a/src/utils/schema_validator.ts +++ b/src/utils/schema_validator.ts @@ -1,14 +1,14 @@ import {Validator, ValidatorResult} from 'jsonschema'; import {ecSignatureSchema, ecSignatureParameter} from '../schemas/ec_signature_schema'; -import {addressSchema, bigNumberSchema, orderSchema, signedOrderSchema} from '../schemas/signed_order_schema'; +import {addressSchema, numberSchema, orderSchema, signedOrderSchema} from '../schemas/signed_order_schema'; export class SchemaValidator { private validator: Validator; constructor() { this.validator = new Validator(); this.validator.addSchema(orderSchema, orderSchema.id); + this.validator.addSchema(numberSchema, numberSchema.id); this.validator.addSchema(addressSchema, addressSchema.id); - this.validator.addSchema(bigNumberSchema, bigNumberSchema.id); this.validator.addSchema(ecSignatureSchema, ecSignatureSchema.id); this.validator.addSchema(signedOrderSchema, signedOrderSchema.id); this.validator.addSchema(ecSignatureParameter, ecSignatureParameter.id); -- cgit v1.2.3 From c74b16eda9465104e1969b1635ac826835d203eb Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 1 Jun 2017 14:46:09 +0200 Subject: Add convertToJSONSchemaCompatibleObject method --- src/utils/schema_validator.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/utils/schema_validator.ts') 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); -- cgit v1.2.3 From 1668a085049d3b065c47709ef0018a66f637b992 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 1 Jun 2017 14:59:03 +0200 Subject: rename signed_order_schema to order_schemas --- src/utils/schema_validator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils/schema_validator.ts') diff --git a/src/utils/schema_validator.ts b/src/utils/schema_validator.ts index 9ff7259d9..db8a960ba 100644 --- a/src/utils/schema_validator.ts +++ b/src/utils/schema_validator.ts @@ -1,6 +1,6 @@ import {Validator, ValidatorResult} from 'jsonschema'; import {ecSignatureSchema, ecSignatureParameter} from '../schemas/ec_signature_schema'; -import {addressSchema, numberSchema, orderSchema, signedOrderSchema} from '../schemas/signed_order_schema'; +import {addressSchema, numberSchema, orderSchema, signedOrderSchema} from '../schemas/order_schemas'; import {tokenSchema} from '../schemas/token_schema'; export class SchemaValidator { -- cgit v1.2.3 From ebe50848761876301dc3ef24d64a4cd416b475a5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 2 Jun 2017 18:33:57 +0200 Subject: Fix comment --- src/utils/schema_validator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/utils/schema_validator.ts') diff --git a/src/utils/schema_validator.ts b/src/utils/schema_validator.ts index db8a960ba..932ddf62a 100644 --- a/src/utils/schema_validator.ts +++ b/src/utils/schema_validator.ts @@ -6,7 +6,7 @@ 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 + // 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: object): object { -- cgit v1.2.3