mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 17:23:37 +08:00
refactor(schema): share nested default array walk (#17420)
This commit is contained in:
@@ -207,10 +207,6 @@ const inputGroups = (
|
||||
});
|
||||
};
|
||||
|
||||
const isObjectKeyword = (key: string) => schemaMaps.has(key);
|
||||
const isArrayKeyword = (key: string) => schemaArrays.has(key);
|
||||
const isChildKeyword = (key: string) => schemaChildren.has(key);
|
||||
|
||||
/**
|
||||
* Remove every instance default below a schema, not only the one this keyword
|
||||
* carries, keeping the entries at `kept`. A nested default belongs to the group
|
||||
@@ -242,7 +238,7 @@ const omitNestedDefaults = (
|
||||
}
|
||||
if (key === "default") continue;
|
||||
let projected = value;
|
||||
if (isObjectKeyword(key) && isObject(value)) {
|
||||
if (schemaMaps.has(key) && isObject(value)) {
|
||||
const mapped: Record<string, unknown> = {};
|
||||
for (const [name, child] of Object.entries(value)) {
|
||||
setOwnSchemaProperty(
|
||||
@@ -257,17 +253,9 @@ const omitNestedDefaults = (
|
||||
}
|
||||
projected = mapped;
|
||||
} else if (
|
||||
(isArrayKeyword(key) || isChildKeyword(key)) &&
|
||||
Array.isArray(value)
|
||||
(schemaArrays.has(key) && Array.isArray(value)) ||
|
||||
schemaChildren.has(key)
|
||||
) {
|
||||
projected = value.map((child, index) =>
|
||||
omitNestedDefaults(
|
||||
child,
|
||||
kept,
|
||||
trackPaths ? [...childPath, String(index)] : path,
|
||||
),
|
||||
);
|
||||
} else if (isChildKeyword(key)) {
|
||||
projected = omitNestedDefaults(value, kept, childPath);
|
||||
}
|
||||
setOwnSchemaProperty(output, key, projected);
|
||||
|
||||
Reference in New Issue
Block a user