From 87d11f99dd7875f4913e20efa12337bd8b9c4502 Mon Sep 17 00:00:00 2001 From: HelderSepu Date: Tue, 24 Oct 2017 17:49:46 -0400 Subject: [PATCH] Add objectCheck Squeeze fix for required object on this PR --- src/core/utils.js | 3 ++- test/core/utils.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/core/utils.js b/src/core/utils.js index 435f4cb0..c88a7f66 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -568,6 +568,7 @@ export const validateParam = (param, isXml, isOAS3 = false) => { // These checks should evaluate to true if the parameter's value is valid let stringCheck = type === "string" && value && !validateString(value) let arrayCheck = type === "array" && Array.isArray(value) && value.length + let objectCheck = type === "object" && value.length let listCheck = type === "array" && Im.List.isList(value) && value.count() let fileCheck = type === "file" && value instanceof win.File let booleanCheck = type === "boolean" && !validateBoolean(value) @@ -589,7 +590,7 @@ export const validateParam = (param, isXml, isOAS3 = false) => { if (err) errors.push(err) } - if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) { + if ( required && !(stringCheck || objectCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) { errors.push("Required field is not provided") return errors } diff --git a/test/core/utils.js b/test/core/utils.js index 19705b66..8f28612a 100644 --- a/test/core/utils.js +++ b/test/core/utils.js @@ -326,6 +326,24 @@ describe("utils", function() { expect( result ).toEqual( [] ) }) + it("validates required objects", function() { + // invalid object + param = { + required: true, + type: "object", + value: "" + } + assertValidateParam(param, ["Required field is not provided"]) + + // valid object + param = { + required: true, + type: "object", + value: "test" + } + assertValidateParam(param, []) + }) + it("validates required strings", function() { // invalid string param = {