Skip to content

Commit 95f9298

Browse files
committed
remove: improve removal of array items
This commit improves the “remove” action of overlays when targeting an array element. Instead of using `delete` on the array item, we remove the item from the array completely with [`Array.prototype.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) method. This avoids ending up with `undefined` values in arrays of the resulting API description.
1 parent 2496500 commit 95f9298

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/overlay.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ function applyOverlayToOpenAPI(spec, overlay) {
1515
}
1616
var parent = jsonpath.parent(spec, a.target)
1717
const thingToRemove = path[0][path[0].length - 1]
18-
delete parent[thingToRemove]
18+
if (Array.isArray(parent)) {
19+
parent.splice(thingToRemove, 1);
20+
} else {
21+
delete parent[thingToRemove];
22+
}
1923
}
2024

2125
} else {

0 commit comments

Comments
 (0)