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