Skip to content

Commit 1a9a57c

Browse files
Added support for field exemptions for std.prune
1 parent 913281d commit 1a9a57c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

stdlib/std.jsonnet

+4-4
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ limitations under the License.
16111611
local arr = std.split(f, '/');
16121612
std.join('/', std.makeArray(std.length(arr) - 1, function(i) arr[i]) + [r]),
16131613

1614-
prune(a)::
1614+
prune(a, ex=[])::
16151615
local isContent(b) =
16161616
if b == null then
16171617
false
@@ -1622,11 +1622,11 @@ limitations under the License.
16221622
else
16231623
true;
16241624
if std.isArray(a) then
1625-
[std.prune(x) for x in a if isContent($.prune(x))]
1625+
[$.prune(x, ex) for x in a if isContent($.prune(x, ex))]
16261626
else if std.isObject(a) then {
1627-
[x]: $.prune(a[x])
1627+
[x]: $.prune(a[x], ex)
16281628
for x in std.objectFields(a)
1629-
if isContent(std.prune(a[x]))
1629+
if std.member(ex, x) || isContent($.prune(a[x], ex))
16301630
} else
16311631
a,
16321632

test_suite/stdlib.jsonnet

+2
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,8 @@ std.assertEqual(std.prune([[], {}, null]), []) &&
14511451
std.assertEqual(std.prune({ a: [[], {}, null], b: { a: [], b: {}, c: null } }), {}) &&
14521452
std.assertEqual(std.prune([[[], {}, null], { a: [], b: {}, c: null }]), []) &&
14531453
std.assertEqual(std.prune({ a: [{ b: true }] }), { a: [{ b: true }] }) &&
1454+
std.assertEqual(std.prune({ a: [{ b: [] }] }, ['b']), { a: [{ b: [] }] }) &&
1455+
14541456

14551457
std.assertEqual(std.parseJson('"foo"'), 'foo') &&
14561458
std.assertEqual(std.parseJson('{}'), {}) &&

0 commit comments

Comments
 (0)