Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ test('should remove empty objects with only undefined properties', () => {
test('should not throw on arrays of primitives', () => {
expect(removeUndefinedObjects([null])).toEqual([null]);
});

test('should not throw for null', () => {
expect(removeUndefinedObjects({ a: null })).toEqual({ a: null });
});
2 changes: 1 addition & 1 deletion packages/api-explorer/src/lib/remove-undefined-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function isEmptyObject(obj) {
function stripEmptyObjects(obj) {
Object.keys(obj).forEach(key => {
const value = obj[key];
if (typeof value === 'object' && !Array.isArray(obj)) {
if (typeof value === 'object' && !Array.isArray(obj) && value !== null) {
// Recurse, strip out empty objects from children
stripEmptyObjects(value);
// Then remove all empty objects from the top level object
Expand Down