refactor(schema): build type-list branches once (#17459)

This commit is contained in:
Vincent Koc
2026-12-06 17:10:15 +08:00
committed by GitHub
parent 8fce350bf4
commit fc5fd502b8
+7 -17
View File
@@ -321,25 +321,15 @@ const factorObjectEnumUnions = (branches: readonly unknown[]): unknown[] => {
const typeListForm = (out: Schema): Schema => {
if (!isStringList(out.type)) return out;
const { type, description, items, ...constraints } = out;
const branches: Schema[] = [];
for (const member of type as readonly string[]) {
if (member === "null") {
branches.push({ type: "null" });
} else if (member === "array") {
branches.push({
type: "array",
...constraints,
// An open item schema can require reduced presentation, but it
// cannot imply that the array accepts only object items.
items: isRecord(items) ? items : {},
});
} else {
branches.push({ type: member, ...constraints });
}
}
return {
...(description === undefined ? {} : { description }),
anyOf: branches,
anyOf: Array.from(type as readonly string[], (member) => {
if (member === "null") return { type: member };
const branch: Schema = { type: member, ...constraints };
// An open item schema cannot imply that the array accepts only object items.
if (member === "array") branch.items = isRecord(items) ? items : {};
return branch;
}),
};
};