mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 17:23:37 +08:00
refactor(schema): build type-list branches once (#17459)
This commit is contained in:
@@ -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;
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user