refactor(schema): pass alias callback directly (#17455)

This commit is contained in:
Vincent Koc
2026-12-06 16:46:13 +08:00
committed by GitHub
parent 3aa1ff8160
commit 698e766004
+12 -17
View File
@@ -315,23 +315,14 @@ const redirectWithAliases = (
node: unknown,
aliases: ReadonlyMap<string, string>,
prefix: string,
options?: {
readonly ownKeyword?: DefinitionKeyword;
readonly onTarget?: (target: string) => void;
},
onTarget?: (target: string) => void,
ownKeyword?: DefinitionKeyword,
): unknown => {
if (!isRecord(node)) return node;
const onTarget = options?.onTarget;
const rebuilt = mapSchemaChildren(
node,
(child) =>
redirectWithAliases(
child,
aliases,
prefix,
onTarget === undefined ? undefined : { onTarget },
),
options?.ownKeyword,
(child) => redirectWithAliases(child, aliases, prefix, onTarget),
ownKeyword,
);
if (!Object.hasOwn(rebuilt, "$ref")) return rebuilt;
const reference = rebuilt.$ref;
@@ -407,7 +398,7 @@ const runMergeRound = (
state.live.get(name),
roundMerged,
prefix,
{ onTarget: (target) => addReferrer(state.referrers, target, name) },
(target) => addReferrer(state.referrers, target, name),
);
state.live.set(name, nextBody);
}
@@ -459,8 +450,12 @@ const mergeIdenticalDefinitions = (
const mergedDefinitions: Schema = {};
for (const [name, body] of state.live)
setOwnSchemaProperty(mergedDefinitions, name, body);
const redirectedRoot = redirectWithAliases(root, resolvedAlias, prefix, {
ownKeyword: keyword,
}) as Schema;
const redirectedRoot = redirectWithAliases(
root,
resolvedAlias,
prefix,
undefined,
keyword,
) as Schema;
return { ...redirectedRoot, [keyword]: mergedDefinitions };
};