UNPKG

@tsed/schema

Version:
13 lines (12 loc) 651 B
import { execMapper, registerJsonSchemaMapper } from "../../registries/JsonSchemaMapperContainer.js"; import { createRef, toRef } from "../../utils/ref.js"; export function lazyRefMapper(jsonLazyRef, options) { const name = jsonLazyRef.name; if (options.$refs?.find((t) => t === jsonLazyRef.target)) { return createRef(name, jsonLazyRef.schema, options); } options.$refs = [...(options.$refs || []), jsonLazyRef.target]; const schema = jsonLazyRef.getType() && execMapper("schema", [jsonLazyRef.schema], options); return toRef(jsonLazyRef.schema, schema, options); } registerJsonSchemaMapper("lazyRef", lazyRefMapper);