Merge pull request #385 from 0xProject/feature/0x_config_validation

Better validate ZeroExConfig on private networks
This commit is contained in:
Leonid Logvinov
2018-02-23 13:20:28 -08:00
committed by GitHub
10 changed files with 92 additions and 31 deletions

View File

@@ -1,5 +1,9 @@
# CHANGELOG
## v0.1.0 - _TBD, 2018_
* Add an optional parameter `subSchemas` to `doesConformToSchema` method (#385)
## v0.0.18 - _February 9, 2017_
* Fix publishing issue where .npmignore was not properly excluding undesired content (#389)

View File

@@ -66,8 +66,11 @@ export const assert = {
const isWeb3Provider = _.isFunction(value.send) || _.isFunction(value.sendAsync);
this.assert(isWeb3Provider, this.typeAssertionMessage(variableName, 'Web3.Provider', value));
},
doesConformToSchema(variableName: string, value: any, schema: Schema): void {
doesConformToSchema(variableName: string, value: any, schema: Schema, subSchemas?: Schema[]): void {
const schemaValidator = new SchemaValidator();
if (!_.isUndefined(subSchemas)) {
_.map(subSchemas, schemaValidator.addSchema.bind(schemaValidator));
}
const validationResult = schemaValidator.validate(value, schema);
const hasValidationErrors = validationResult.errors.length > 0;
const msg = `Expected ${variableName} to conform to schema ${schema.id}