Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disallow arrays as the object type #194

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ValidationError.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,14 @@ describe("Validation", () => {
(msg) => expect(msg).toMatchSnapshot()
);

createFailedTestCase(
"object type",
{
devServer: [],
},
(msg) => expect(msg).toMatchSnapshot()
);

createFailedTestCase(
"array type",
{
Expand Down
Loading