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

fix: #38 #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 3 additions & 6 deletions lib/patterns/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var ObjectSchema = module.exports = Schema.patterns.ObjectSchema = Schema.extend
if (error = self.stringProps[key].value.errors(instance[key])) {
errors[key] = error
}
} else if (self.stringProps[key].min > 0) {
} else if (self.stringProps[key].min > 0 && self.stringProps[key].value.validate(instance[key])) {
errors[key] = 'key is not present in the object'
}
})
Expand Down Expand Up @@ -88,11 +88,8 @@ var ObjectSchema = module.exports = Schema.patterns.ObjectSchema = Schema.extend

// Simple string properties
var stringPropsValid = Object.keys(this.stringProps).every(function(key) {
if (key in instance) {
return self.stringProps[key].value.validate(instance[key])
} else {
return self.stringProps[key].min === 0
}
return (self.stringProps[key].min === 0 && !(key in instance)) ||
(self.stringProps[key].value.validate(instance[key]));
})
if (!stringPropsValid) return false

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
"engines": {
"node": "*"
},
"scripts": {
"test":"./test.sh"
},
"main": "./index.js"
}