support merging multiple SMP into one patch

This commit is contained in:
Mengqi Yu 2018-04-04 10:22:48 -07:00
parent 2bf111a619
commit 48b6786632

View File

@ -880,6 +880,29 @@ func StrategicMergeMapPatchUsingLookupPatchMeta(original, patch JSONMap, schema
return mergeMap(original, patch, schema, mergeOptions)
}
// MergeStrategicMergeMapPatchUsingLookupPatchMeta merges strategic merge
// patches retaining `null` fields and parallel lists. If 2 patches change the
// same fields and the latter one will override the former one. If you don't
// want that happen, you need to run func MergingMapsHaveConflicts before
// merging these patches. Applying the resulting merged merge patch to a JSONMap
// yields the same as merging each strategic merge patch to the JSONMap in
// succession.
func MergeStrategicMergeMapPatchUsingLookupPatchMeta(schema LookupPatchMeta, patches ...JSONMap) (JSONMap, error) {
mergeOptions := MergeOptions{
MergeParallelList: false,
IgnoreUnmatchedNulls: false,
}
merged := JSONMap{}
var err error
for _, patch := range patches {
merged, err = mergeMap(merged, patch, schema, mergeOptions)
if err != nil {
return nil, err
}
}
return merged, nil
}
// handleDirectiveInMergeMap handles the patch directive when merging 2 maps.
func handleDirectiveInMergeMap(directive interface{}, patch map[string]interface{}) (map[string]interface{}, error) {
if directive == replaceDirective {