Repository: icebob/fastest-validator (js)

Issue:
Multiple validators + optional = false negative
```js
> (new (require('fastest-validator'))).validate({}, {
    a: [
        { type: 'number', optional: true },
        { type: 'string', optional: true },
    ]
})
[ { type: 'required',
    expected: undefined,
    actual: undefined,
    field: 'a',
    message: 'The \'a\' field is required!' } ]
```

I expected `a` not to be considered required.

Pull request description:
Fixes #25
Fixes #25 and adds a testcase for it.

Patch:
diff --git a/lib/validator.js b/lib/validator.js
index fc035c9..1e389c2 100644
--- a/lib/validator.js
+++ b/lib/validator.js
@@ -185,7 +185,7 @@ Validator.prototype._checkWrapper = function(rules, isMultipleRules) {
 
 			// Check required fields
 			if ((value === undefined || value === null) && check.type !== "forbidden") {
-				if (schema.optional !== true) {
+				if (schema.optional !== true && !Array.isArray(schema)) {
 					self.handleResult(errors, stack, self.makeError("required"));
 				} else
 					continue;


Test patch:
diff --git a/test/validator.spec.js b/test/validator.spec.js
index 01d2187..674aaf1 100644
--- a/test/validator.spec.js
+++ b/test/validator.spec.js
@@ -586,6 +586,15 @@ describe("Test multiple rules", () => {
 
 	let check = v.compile(schema);
 
+	let schemaOptional = {
+		a: [
+			{ type: 'number', optional: true },
+			{ type: 'string', optional: true },
+		]
+	};
+
+	let checkOptional = v.compile(schema);
+
 	it("should give true if value is string", () => {
 		let obj = { value: "John" };
 
@@ -630,6 +639,14 @@ describe("Test multiple rules", () => {
 
 	});
 
+	it("should work with optional", () => {
+		let obj = {};
+		let res = checkOptional(obj);
+
+		expect(res).toBe(true);
+
+	});
+
 });
 
 describe("Test multiple rules with objects", () => {