mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 17:23:37 +08:00
refactor(schema): share reference site recording (#17379)
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
|
||||
type SchemaObject = Readonly<Record<string, unknown>>;
|
||||
type Dialect = "draft-07" | "draft-2020-12";
|
||||
const referenceKeywords = ["$ref", "$dynamicRef", "$recursiveRef"] as const;
|
||||
|
||||
/** A fragment's resource and URI base are distinct facts. */
|
||||
export interface JsonSchemaScope {
|
||||
@@ -170,31 +171,16 @@ export class JsonSchemaReferences {
|
||||
scope: JsonSchemaScope,
|
||||
pending: { value: unknown; scope: JsonSchemaScope }[],
|
||||
): void {
|
||||
if (Object.hasOwn(value, "$ref") && typeof value.$ref === "string") {
|
||||
const reference = value.$ref;
|
||||
this.#referenceSites.push({ scope, reference, keyword: "$ref" });
|
||||
for (const keyword of referenceKeywords) {
|
||||
if (!Object.hasOwn(value, keyword) || typeof value[keyword] !== "string")
|
||||
continue;
|
||||
const reference = value[keyword];
|
||||
this.#referenceSites.push({ scope, reference, keyword });
|
||||
if (keyword !== "$ref") continue;
|
||||
const target = this.resolve(scope, reference);
|
||||
if (target.kind === "target" && isObject(target.value))
|
||||
pending.push({ value: target.value, scope });
|
||||
}
|
||||
if (
|
||||
Object.hasOwn(value, "$dynamicRef") &&
|
||||
typeof value.$dynamicRef === "string"
|
||||
)
|
||||
this.#referenceSites.push({
|
||||
scope,
|
||||
reference: value.$dynamicRef,
|
||||
keyword: "$dynamicRef",
|
||||
});
|
||||
if (
|
||||
Object.hasOwn(value, "$recursiveRef") &&
|
||||
typeof value.$recursiveRef === "string"
|
||||
)
|
||||
this.#referenceSites.push({
|
||||
scope,
|
||||
reference: value.$recursiveRef,
|
||||
keyword: "$recursiveRef",
|
||||
});
|
||||
}
|
||||
|
||||
enter(
|
||||
|
||||
Reference in New Issue
Block a user