@rjsf/utils
Version:
Utility functions for @rjsf/core
33 lines (32 loc) • 2.22 kB
TypeScript
import { FormContextType, Registry, RJSFSchema, StrictRJSFSchema, UiSchema } from './types.js';
/** Expands `ui:definitions` into the uiSchema by walking the schema tree and finding all `$ref`s.
* Called once at form initialization to pre-expand definitions into the uiSchema structure.
*
* For recursive schemas, expansion stops at recursion points to avoid infinite loops.
* Runtime resolution via `resolveUiSchema` handles these cases using registry definitions.
*
* @param currentSchema - The current schema node being processed
* @param uiSchema - The uiSchema at the current path
* @param registry - The registry containing rootSchema and uiSchemaDefinitions
* @param visited - Set of $refs already visited (to detect recursion)
* @returns - The expanded uiSchema with definitions merged in
*/
export declare function expandUiSchemaDefinitions<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(currentSchema: S, uiSchema: UiSchema<T, S, F>, registry: Registry<T, S, F>, visited?: Set<string>): UiSchema<T, S, F>;
/** Resolves the uiSchema for a given schema, considering `ui:definitions` stored in the registry.
*
* This function is called at runtime for each field. It handles recursive schemas where the
* pre-expansion in `expandUiSchemaDefinitions` couldn't go deeper.
*
* When the schema contains a `$ref`, this function looks up the corresponding uiSchema definition
* from `registry.uiSchemaDefinitions` and merges it with any local uiSchema overrides.
*
* Resolution order (later sources override earlier):
* 1. `ui:definitions[$ref]` - base definition from registry
* 2. `localUiSchema` - local overrides at current path
*
* @param schema - The JSON schema (may still contain `$ref` for recursive schemas)
* @param localUiSchema - The uiSchema at the current path (local overrides)
* @param registry - The registry containing `uiSchemaDefinitions`
* @returns - The resolved uiSchema with definitions merged in
*/
export default function resolveUiSchema<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(schema: S, localUiSchema: UiSchema<T, S, F> | undefined, registry: Registry<T, S, F>): UiSchema<T, S, F>;