Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // extensible takes a jsonnet value and if it's an object it recursively
- // computes a version of the object where each of its fields is converted
- // to the "+:" form.
- local extensible(o) = if std.isObject(o) then {
- [n]+: extensible(o[n])
- for n in std.objectFields(o)
- } else o;
- // merge takes two objects and merges them recursively.
- local merge(a, b) = a + extensible(b);
- local testCases = [
- [
- {
- a: 1,
- },
- {
- b: 2,
- },
- {
- a: 1,
- b: 2,
- },
- ],
- [
- {
- x: {
- a: 1,
- },
- },
- {
- x: {
- b: 2,
- },
- },
- {
- x: {
- a: 1,
- b: 2,
- },
- },
- ],
- ];
- local check = [
- std.assertEqual(merge(e[0], e[1]), e[2])
- for e in testCases
- ];
- check
Add Comment
Please, Sign In to add comment