@rjsf/validator-cfworker APIs
@rjsf/validator-cfworker is an additional, eval-free validator option for CSP-constrained applications. It is backed by @cfworker/json-schema, interprets schemas without eval or new Function, and defaults to JSON Schema draft 2020-12.
It is not an AJV replacement. See the package README for the unsupported-keyword matrix and current upstream-state notes.
Differences from @rjsf/validator-ajv8
- AJV-only options and extensions such as
AjvClass,$data,discriminator, andajv-errors'serrorMessageare not supported. $dynamicRefand$dynamicAnchorare not currently supported by the underlying engine.- Error messages differ from AJV, and there is no
ajv-i18nlocalizer equivalent. UsetransformErrorsto customize messages. - Precompiled-validator mode is not part of this initial package.
- The wrapper normalizes
undefinedform-data values before validation and caches validators by schema id to make repeated RJSFisValid()calls safe.
Types
The package exports CustomValidatorOptionsType, CFWorkerValidationError, CFWorkerFormatChecker, and SuppressDuplicateFilteringType from src/types.ts.
APIs
customizeValidator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>()
Creates a ValidatorType<T, S, F> backed by @cfworker/json-schema.
Parameters
options.additionalMetaSchemas: additional schemas registered for cross-schema$refresolutionoptions.customFormats: format checkers expressed as functions, regular expressions, or regular-expression source stringsoptions.draft:'4','7','2019-09', or'2020-12'; defaults to'2020-12'options.extenderFn: hook called with every newly constructed engine validatoroptions.shortCircuit: stop at the first error; defaults tofalseoptions.suppressDuplicateFiltering:'none','anyOf','oneOf', or'all'
Returns
ValidatorType<T, S, F>: the customized validator implementation
import { customizeValidator } from '@rjsf/validator-cfworker';
const validator = customizeValidator({
draft: '2020-12',
customFormats: { slug: /^[a-z0-9-]+$/ },
});