From 4196a5a85c2ed7fb43d48962bdf862a33f2fd5ba Mon Sep 17 00:00:00 2001
From: Sergey Kudashev <kudashevs@gmail.com>
Date: Fri, 25 Oct 2024 23:25:14 +0300
Subject: [PATCH] feat: disallow arrays as the object type

---
 src/ValidationError.js                | 6 +++++-
 test/__snapshots__/index.test.js.snap | 7 +++++++
 test/index.test.js                    | 8 ++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/ValidationError.js b/src/ValidationError.js
index cec8556..1fe4e4f 100644
--- a/src/ValidationError.js
+++ b/src/ValidationError.js
@@ -234,7 +234,11 @@ function canApplyNot(schema) {
  * @returns {boolean}
  */
 function isObject(maybeObj) {
-  return typeof maybeObj === "object" && maybeObj !== null;
+  return (
+    typeof maybeObj === "object" &&
+    !Array.isArray(maybeObj) &&
+    maybeObj !== null
+  );
 }
 
 /**
diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap
index b970055..ea19e0f 100644
--- a/test/__snapshots__/index.test.js.snap
+++ b/test/__snapshots__/index.test.js.snap
@@ -1524,6 +1524,13 @@ exports[`Validation should fail validation for object in object with anyOf 1`] =
       [object { alias?, name?, onlyModule? }, ...]"
 `;
 
+exports[`Validation should fail validation for object type 1`] = `
+"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
+ - configuration.devServer should be an object:
+   object { … }
+   -> Options for the webpack-dev-server"
+`;
+
 exports[`Validation should fail validation for object with dependencies #2 1`] = `
 "Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
  - configuration.objectWithPropertyDependency2 should be an object:
diff --git a/test/index.test.js b/test/index.test.js
index 764a04a..83cabf0 100644
--- a/test/index.test.js
+++ b/test/index.test.js
@@ -771,6 +771,14 @@ describe("Validation", () => {
     (msg) => expect(msg).toMatchSnapshot()
   );
 
+  createFailedTestCase(
+    "object type",
+    {
+      devServer: [],
+    },
+    (msg) => expect(msg).toMatchSnapshot()
+  );
+
   createFailedTestCase(
     "array type",
     {