Skip to content

Commit 4196a5a

Browse files
committed
feat: disallow arrays as the object type
1 parent f51eadb commit 4196a5a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/ValidationError.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ function canApplyNot(schema) {
234234
* @returns {boolean}
235235
*/
236236
function isObject(maybeObj) {
237-
return typeof maybeObj === "object" && maybeObj !== null;
237+
return (
238+
typeof maybeObj === "object" &&
239+
!Array.isArray(maybeObj) &&
240+
maybeObj !== null
241+
);
238242
}
239243

240244
/**

test/__snapshots__/index.test.js.snap

+7
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,13 @@ exports[`Validation should fail validation for object in object with anyOf 1`] =
15241524
[object { alias?, name?, onlyModule? }, ...]"
15251525
`;
15261526
1527+
exports[`Validation should fail validation for object type 1`] = `
1528+
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
1529+
- configuration.devServer should be an object:
1530+
object {}
1531+
-> Options for the webpack-dev-server"
1532+
`;
1533+
15271534
exports[`Validation should fail validation for object with dependencies #2 1`] = `
15281535
"Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
15291536
- configuration.objectWithPropertyDependency2 should be an object:

test/index.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,14 @@ describe("Validation", () => {
771771
(msg) => expect(msg).toMatchSnapshot()
772772
);
773773

774+
createFailedTestCase(
775+
"object type",
776+
{
777+
devServer: [],
778+
},
779+
(msg) => expect(msg).toMatchSnapshot()
780+
);
781+
774782
createFailedTestCase(
775783
"array type",
776784
{

0 commit comments

Comments
 (0)