refactor(schema): use serializer result for resolution (#17407)

This commit is contained in:
Vincent Koc
2026-12-06 14:08:18 +08:00
committed by GitHub
parent c5aefe38fd
commit baf2afa75f
+3 -15
View File
@@ -100,7 +100,6 @@ const childSchemaPosition = (
class BudgetedSchemaSerializer {
readonly chunks: string[] = [];
resolved = true;
private readonly active = new Map<JsonSchemaScope, Set<string>>();
constructor(
@@ -222,7 +221,6 @@ class BudgetedSchemaSerializer {
Object.hasOwn(value, "$dynamicAnchor") ||
Object.hasOwn(value, "$recursiveAnchor")
) {
this.resolved = false;
return false;
}
if (!this.hasSchemaField(value, isRoot, "all"))
@@ -244,25 +242,18 @@ class BudgetedSchemaSerializer {
isRoot: boolean,
): boolean {
let scopeRefs = this.active.get(currentScope);
if (scopeRefs?.has(ref)) {
this.resolved = false;
return false;
}
if (scopeRefs?.has(ref)) return false;
const target = this.references.resolve(currentScope, ref);
if (
target.kind !== "target" ||
(this.strip && this.isStrippedTarget(currentScope, target.path))
) {
this.resolved = false;
return false;
}
const siblings = this.hasSchemaField(value, isRoot, "siblings");
// Draft 7 ignores siblings, while clients such as Ajv also apply them.
// Do not label either interpretation an equivalent inline advertisement.
if (currentScope.dialect === "draft-07" && siblings) {
this.resolved = false;
return false;
}
if (currentScope.dialect === "draft-07" && siblings) return false;
if (scopeRefs === undefined) {
scopeRefs = new Set();
this.active.set(currentScope, scopeRefs);
@@ -433,10 +424,7 @@ export const inlineWithinBudget = (
references,
options?.stripAnnotations === true,
);
if (
!serializer.visit(root, "schema", references.rootScope, true) ||
!serializer.resolved
)
if (!serializer.visit(root, "schema", references.rootScope, true))
return undefined;
const expanded: unknown = JSON.parse(serializer.chunks.join(""));
if (!isSchemaObject(expanded)) return undefined;