Comparing version 0.3.1 to 0.3.2
@@ -33,2 +33,6 @@ // Load modules | ||
if (config instanceof Types.Base) { | ||
return validateKeyConfig(config, '', object); | ||
} | ||
var unprocessedObject = Utils.clone(object || {}); | ||
@@ -35,0 +39,0 @@ var keys = Object.keys(config || {}); |
@@ -0,0 +0,0 @@ // Load modules |
@@ -64,4 +64,13 @@ // Load modules | ||
internals.ObjectType.prototype.allowOtherKeys = function () { | ||
this._allowOtherKeys = true; | ||
return this; | ||
}; | ||
internals.ObjectType.prototype._traverse = function (topObj, topConfig, errors, topKeyPath) { | ||
var self = this; | ||
var traverse = function (obj, config, errors, keyPath) { | ||
@@ -92,3 +101,3 @@ | ||
if (keys.length) { // Only error on unknown keys when config specifies a structure | ||
if (self._allowOtherKeys !== true && keys.length) { // Only error on unknown keys when config specifies a structure | ||
Object.keys(unprocessedObject).forEach(function (unprocessedKey) { | ||
@@ -95,0 +104,0 @@ |
{ | ||
"name": "joi", | ||
"description": "Object schema validation", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"author": "Van Nguyen <the.gol.effect@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -330,3 +330,3 @@ <a href="https://github.com/spumko"><img src="https://raw.github.com/spumko/spumko/master/images/from.png" align="right" /></a> | ||
Specifies allowed types for the array value to exclude. The values of n1, n2, ... are Type Registry constraints (usually of other types). | ||
Specifies allowed types for the array value to exclude. The values of n1, n2, ... are Type Registry constraints (usually of other types). | ||
@@ -336,5 +336,7 @@ | ||
*Note: Object has no special methods other than those inherited from BaseType* | ||
##### Object.allowOtherKeys() | ||
Will cause any unknown keys in the object being validated to not cause the object to be invalid. | ||
## Usage | ||
@@ -434,3 +436,3 @@ | ||
By default Joi tries to parse and convert object's values into correct type. You might want to disable this behaviour e.g. when you are validating program's internal objects instead of user input. | ||
By default Joi tries to parse and convert object's values into correct type. You might want to disable this behaviour e.g. when you are validating program's internal objects instead of user input. | ||
@@ -437,0 +439,0 @@ To force Joi to not convert object values, use the `skipConversions` option: |
@@ -141,2 +141,13 @@ // Load modules | ||
it('should validate config where the root item is a joi type', function (done) { | ||
expect(Joi.validate(true, T.Boolean().nullOk())).to.be.null; | ||
expect(Joi.validate({ auth: { mode: 'try' } }, T.Object())).to.be.null; | ||
expect(Joi.validate(true, T.Object())).to.not.be.null; | ||
expect(Joi.validate(true, T.String())).to.not.be.null; | ||
expect(Joi.validate('test@test.com', T.String().email())).to.be.null; | ||
done(); | ||
}); | ||
it('should validate an unknown option', function (done) { | ||
@@ -143,0 +154,0 @@ |
@@ -53,2 +53,24 @@ // Load modules | ||
it('should prevent extra keys from existing by default', function (done) { | ||
var t = O({ item: Joi.types.String().required() }).required(); | ||
verifyBehavior(t, [ | ||
[{ item: 'something' }, true], | ||
[{ item: 'something', item2: 'something else' }, false], | ||
['', false] | ||
], done); | ||
}); | ||
it('should allow extra keys when using allowOtherKeys', function (done) { | ||
var t = O({ item: Joi.types.String().required() }).allowOtherKeys(); | ||
verifyBehavior(t, [ | ||
[{ item: 'something' }, true], | ||
[{ item: 'something', item2: 'something else' }, true], | ||
[{ item: 'something', item1: 'something', item2: 'something else' }, true], | ||
[{ item1: 'something', item2: 'something else' }, false], | ||
['', false] | ||
], done); | ||
}); | ||
it('should traverse an object and validate all properties in the top level', function (done) { | ||
@@ -55,0 +77,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
285914
3176
536
1