Skip to content

Commit d6afa5b

Browse files
chore: rename
1 parent c922796 commit d6afa5b

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

next/src/utils.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,22 @@ function isObject(value: any): boolean {
6060
}
6161

6262
/**
63-
* Merges obj1 with obj2 recursively
64-
* @param obj1 - The first object to merge
65-
* @param obj2 - The second object to merge
63+
* Merges schema 2 into schema 1 recursively
64+
* @param schema1 - The first schema to merge
65+
* @param schema2 - The second schema to merge
6666
*/
67-
export function deepMergeSchemas<T extends Record<string, any>>(obj1: T, obj2: T): void {
67+
export function deepMergeSchemas<T extends Record<string, any>>(schema1: T, schema2: T): void {
6868
// Handle null/undefined
69-
if (!obj1 || !obj2) {
69+
if (!schema1 || !schema2) {
7070
return
7171
}
7272

7373
// Handle non-objects
74-
if (typeof obj1 !== 'object' || typeof obj2 !== 'object')
74+
if (typeof schema1 !== 'object' || typeof schema2 !== 'object')
7575
return
7676

7777
// Merge all properties from obj2 into obj1
78-
for (const [key, value] of Object.entries(obj2)) {
78+
for (const [key, value] of Object.entries(schema2)) {
7979
// let's skip merging conditionals such as if, oneOf, then ,else, allOf, anyOf, etc.
8080
if (KEYS_TO_SKIP.includes(key)) {
8181
continue
@@ -84,17 +84,17 @@ export function deepMergeSchemas<T extends Record<string, any>>(obj1: T, obj2: T
8484
// If the value is an object, merge recursively
8585
if (isObject(value)) {
8686
// If both objects have this key and it's an object, merge recursively
87-
if (isObject(obj1[key])) {
88-
deepMergeSchemas(obj1[key], value)
87+
if (isObject(schema1[key])) {
88+
deepMergeSchemas(schema1[key], value)
8989
}
9090
// Otherwise, if the value is different, assign it
91-
else if (obj1[key] !== value) {
92-
obj1[key as keyof T] = value
91+
else if (schema1[key] !== value) {
92+
schema1[key as keyof T] = value
9393
}
9494
}
9595
// If the value is an array, cycle through it and merge values if they're different (take objects into account)
96-
else if (obj1[key] && Array.isArray(value)) {
97-
const originalArray = obj1[key]
96+
else if (schema1[key] && Array.isArray(value)) {
97+
const originalArray = schema1[key]
9898
// If the destiny value exists and it's an array, cycle through the incoming values and merge if they're different (take objects into account)
9999
for (const item of value) {
100100
if (item && typeof item === 'object') {
@@ -109,12 +109,12 @@ export function deepMergeSchemas<T extends Record<string, any>>(obj1: T, obj2: T
109109
}
110110
// Otherwise, just assign it
111111
else {
112-
obj1[key as keyof T] = value as T[keyof T]
112+
schema1[key as keyof T] = value as T[keyof T]
113113
}
114114
}
115115
}
116-
else if (obj1[key] !== value) {
117-
obj1[key as keyof T] = value
116+
else if (schema1[key] !== value) {
117+
schema1[key as keyof T] = value
118118
}
119119
}
120120
}

0 commit comments

Comments
 (0)