mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 17:23:37 +08:00
refactor(schema): use serializer result for resolution (#17407)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user