Fix broken required-properties check

master
Sven Slootweg 4 years ago
parent ad7377b530
commit 588d151c25

@ -4,6 +4,7 @@ const asExpression = require("as-expression");
const defaultValue = require("default-value"); const defaultValue = require("default-value");
const assureArray = require("assure-array"); const assureArray = require("assure-array");
const flatten = require("flatten"); const flatten = require("flatten");
const arrayUnion = require("array-union");
const ValidationError = require("@validatem/error"); const ValidationError = require("@validatem/error");
const validationResult = require("@validatem/validation-result"); const validationResult = require("@validatem/validation-result");
@ -55,7 +56,14 @@ module.exports = function hasShape(rules) {
let errors = []; let errors = [];
let newObject = {}; let newObject = {};
for (let [ key, value ] of Object.entries(object)) { // We need to consider the keys from the ruleset (for detecting missing required properties) *and* the keys from the actual object (for handling extraneous values).
let allKeys = arrayUnion(
Object.keys(rules),
Object.keys(object)
);
for (let key of allKeys) {
let value = object[key];
let rule = rules[key]; let rule = rules[key];
if (rule != null) { if (rule != null) {

@ -16,6 +16,7 @@
"@validatem/combinator": "^0.1.0", "@validatem/combinator": "^0.1.0",
"@validatem/error": "^1.0.0", "@validatem/error": "^1.0.0",
"@validatem/validation-result": "^0.1.1", "@validatem/validation-result": "^0.1.1",
"array-union": "^2.1.0",
"as-expression": "^1.0.0", "as-expression": "^1.0.0",
"assure-array": "^1.0.0", "assure-array": "^1.0.0",
"default-value": "^1.0.0", "default-value": "^1.0.0",

@ -135,6 +135,11 @@
resolved "https://registry.yarnpkg.com/@validatem/virtual-property/-/virtual-property-0.1.0.tgz#880540dfd149f98ecf1095d93912e34443381fe4" resolved "https://registry.yarnpkg.com/@validatem/virtual-property/-/virtual-property-0.1.0.tgz#880540dfd149f98ecf1095d93912e34443381fe4"
integrity sha512-JUUvWtdqoSkOwlsl20oB3qFHYIL05a/TAfdY4AJcs55QeVTiX5iI1b8IoQW644sIWWooBuLv+XwoxjRsQFczlQ== integrity sha512-JUUvWtdqoSkOwlsl20oB3qFHYIL05a/TAfdY4AJcs55QeVTiX5iI1b8IoQW644sIWWooBuLv+XwoxjRsQFczlQ==
array-union@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==
as-expression@^1.0.0: as-expression@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/as-expression/-/as-expression-1.0.0.tgz#7bc620ca4cb2fe0ee90d86729bd6add33b8fd831" resolved "https://registry.yarnpkg.com/as-expression/-/as-expression-1.0.0.tgz#7bc620ca4cb2fe0ee90d86729bd6add33b8fd831"

Loading…
Cancel
Save