Skip to content

Commit

Permalink
fix: incorrect priority merge (api7#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzp2010 authored May 15, 2024
1 parent 7c0610b commit 0ffe9c8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions apps/cli/src/differ/differv3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,20 +628,23 @@ export class DifferV3 {
private mergeDefault(resource: ADCSDK.Resource, defaults: object): object {
const defaultsClone = cloneDeep(defaults);
const resourceClone = cloneDeep(resource);
const isObject = (val: unknown) =>
const isObjectButNotArray = (val: unknown) =>
typeof val === 'object' && !Array.isArray(val);

Object.entries(defaultsClone).forEach(([key, value]) => {
// If a specific key does not exist in the resource
if (!resourceClone[key]) {
// If the default value to be merged is an object and not an array,
// it should not be merged.
if (isObject(value)) return; // include any array value
if (isObjectButNotArray(value) || Array.isArray(value)) return; // include any array value
resourceClone[key] = value;
} else {
// If the default value and the value in the resource are both
// objects, they need to be deeply merged, recursively it
if (isObject(value) && isObject(resourceClone[key]))
if (
isObjectButNotArray(value) &&
isObjectButNotArray(resourceClone[key])
)
resourceClone[key] = this.mergeDefault(resourceClone[key], value);

// If the default value is an array then the default value of the
Expand Down

0 comments on commit 0ffe9c8

Please # to comment.