-
Notifications
You must be signed in to change notification settings - Fork 229
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
Return false for non-empty objects #143
Conversation
Hi @a-morn I've previously explained the goal of the function and probably discussed that as well but can't find these. The reason for this helper to be is to clean-up the specification before giving it to the user. So, it's not a question of an empty object, but an object with properties which are empty objects. The helper was added during the work on supporting open api specification because there is a difference between v2 and v3 of what properties are required in the final spec and what fields are required not to be present. It's not that all this logic shouldn't be refactored btw, it's just trying to plumb original logic with new rules ... |
Hi @kalinchernev! To clarify: the current functionality is that |
@a-morn that's my test:
I tested with current function and indeed it's also wrong. Though update does not achieve improvement. Thanks for making me double-checking it though, it's for sure wrong and needs to be fixed :) If you have a better way, please update the PR |
Rather than the object itself.
7bc644b
to
3dee229
Compare
Test added. Please check that the test cases look right. Thanks for maintaining this lib! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@a-morn nice! Thanks!
* @param {object} obj - the object to check | ||
*/ | ||
function hasEmptyProperty(obj) { | ||
return Object.values(obj).every( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.values
does not exist in Node v6
This should result in a major/braking change version update so as to not break those still using Node v6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could change it too:
return Object.values(obj).every( | |
return Object.keys(obj).map(key => obj[key]).every( |
and consider it a bug fix. This shouldn't warrant a major version bump.
Or transpile the entire lib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No transpilations please. I had to think about that, but didn't. Most certainly it's not a major version bump.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently always returns true. Should return false for non-empty objects.
Note that
Object.keys(obj).forEach(key => { if (key in obj) return false; });
doesn't do anything :(