@rjsf/validator-ata APIs
@rjsf/validator-ata is an alternative to @rjsf/validator-ajv8, backed by ata-validator instead of AJV.
The public surface mirrors the AJV package, so swapping the import is enough for the form to keep working: customizeValidator(), ValidatorType<T, S, F>, custom formats, transformErrors, customValidate, and suppressDuplicateFiltering all behave the same.
See the Validation documentation for examples of using these APIs.
Differences from @rjsf/validator-ajv8
- AJV-only options (
AjvClass,ajvFormatOptions,ajvOptionsOverrides) are not accepted. The closest equivalent isataOptionsOverrides, which is spread on top of the defaultata-validatoroptions. - The
ata-validatorformat set is always installed, so there is no opt-in flag for formats. ata-validator's error params are frozen, so the pre-quote pass thatvalidator-ajv8runs forajv-i18nis unnecessary. Localizers that mutatemessagein place still work as-is.- Precompiled validators (
compileSchemaValidators/createPrecompiledValidator) are supported.ata-validator'sbundleStandaloneoutput is adapted into the validator function map the precompiled consumer expects. Error output matches the non-precompiled validator, including per-field errors for schema-valuedadditionalProperties(withata-validator>= 0.17.4); an invalidanyOfreports a single error on the field, the same as the runtime path. One constraint carries over from the standalone (AOT) path: custom formats must be a RegExp or pre-anchored string pattern, since a function checker cannot be serialized into the bundle and is rejected at compile time.
Types
There are a few TypeScript types that are exported by @rjsf/validator-ata in support of the APIs. These types can be found on GitHub here.
APIs
customizeValidator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>()
Creates and returns a customized implementation of the ValidatorType with the given customization options if provided.
If a localizer is provided, it is used to translate the messages generated by the underlying ata-validator validation.
Parameters
- [options=]: CustomValidatorOptionsType - The optional map of
CustomValidatorOptionsTypeoptions that are used to create theValidatorTypeinstance. Supported options:additionalMetaSchemas: Additional schemas registered for cross-schema$refresolutioncustomFormats: Custom format checkers; values can be functions, RegExps, or pre-anchored regex source stringsataOptionsOverrides: Overrides spread on top of the defaultata-validatoroptions (e.g.coerceTypes,removeAdditional,verbose,abortEarly)extenderFn: A function called against the constructedValidatorinstance for additional setup; returning a different instance is supportedsuppressDuplicateFiltering: Controls filtering of duplicateanyOf/oneOferrors using theSuppressDuplicateFilteringTypetype.'none'(default) filters duplicates for both;'anyOf'suppresses filtering foranyOf(oneOf duplicates still filtered);'oneOf'suppresses filtering foroneOf(anyOf duplicates still filtered);'all'disables all duplicate filtering.
- [localizer]: Localizer | undefined - If provided, is used to localize a list of
ata-validatorValidationErrors after running the form validation
Returns
- ValidatorType<T, S, F>: The custom validator implementation resulting from the set of parameters provided
compileSchemaValidators<S extends StrictRJSFSchema = RJSFSchema>()
Compiles a schema into an output file that can be loaded later as a precompiled validator.
The main reasons for using a precompiled validator are reducing code size, improving startup time by skipping schema compilation, and avoiding dynamic code generation when a browser's Content Security Policy forbids it.
Under the hood this calls ata-validator's bundleStandalone and wraps the result in the map the precompiled consumer expects.
NOTE: Custom formats passed through
options.customFormatsmust be a RegExp or a pre-anchored string pattern. A function checker cannot be serialized into the standalone bundle and is rejected at compile time.
Parameters
- schema: S - The schema to be compiled into a set of precompiled validator functions
- output: string - The name of the file into which the precompiled validator functions are generated
- [options=]: CustomValidatorOptionsType - The same
CustomValidatorOptionsTypeoptions accepted bycustomizeValidator(), used to alter the validator that compiles the schema
createPrecompiledValidator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>()
Creates and returns a ValidatorType interface that is implemented with a precompiled validator.
If a localizer is provided, it is used to translate the messages generated by the underlying ata-validator validation.
NOTE: The
validateFnsparameter is an object obtained by importing from a precompiled validation file created via thecompileSchemaValidators()function.
Parameters
- validateFns: ValidatorFunctions - The map of the validation functions that are created by the
compileSchemaValidators()function - rootSchema: S - The root schema that was used with the
compileSchemaValidators()function - [localizer]: Localizer | undefined - If provided, is used to localize the list of
ata-validatorValidationErrors after running the form validation - [suppressDuplicateFiltering]:
SuppressDuplicateFilteringType | undefined- Controls filtering of duplicateanyOf/oneOferrors. SeecustomizeValidator()for the full description of each value.
Returns
- ValidatorType<T, S, F>: The precompiled validator implementation resulting from the set of parameters provided