refactor(schema): share nested default array walk (#17420)

This commit is contained in:
Vincent Koc
2026-12-06 14:43:36 +08:00
committed by GitHub
parent 9ae8b62d39
commit 8454d2a9bc
+3 -15
View File
@@ -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);