Skip to main content
Version: Current (v7.0.0-beta.1)

@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<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 is ataOptionsOverrides, which is spread on top of the default ata-validator options.
  • The ata-validator format set is always installed, so there is no opt-in flag for formats.
  • A localizer gets copies of the errors with the property names in their missingProperty and property params quoted, such as 'foo', so that the validator can replace them in its messages with the property's title or ui:title. Only the message it sets on each error is kept.
  • Precompiled validators (compileSchemaValidators / createPrecompiledValidator) are supported. ata-validator's bundleStandalone output is adapted into the validator function map the precompiled consumer expects. Error output matches the non-precompiled validator, including per-field errors for schema-valued additionalProperties (with ata-validator >= 0.17.4); an invalid anyOf reports 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. ata-validator compiles each schema as a document of its own and resolves a $ref only to an entry of the definitions or $defs in it, so each schema is compiled as a document carrying every subschema of the root it reaches through a $ref, such as a definition, a property or the root itself, as a definition of its own in one container, the $ref renamed to it. A $ref beside other keywords is compiled as an allOf entry beside them. A $ref that names nothing in the root, or one into another document, leaves a schema with no compiled function, which throws was not compiled to a standalone validator when the form validates against it.

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. The package also re-exports ata-validator's ValidationError, the type of the errors rawValidation() returns, so an app doesn't need ata-validator as its own dependency to name it.

APIs​

customizeValidator<S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = FormContextType>()​

Creates and returns an ATAValidator, an implementation of ValidatorType customized with the given options if provided. If a localizer is provided, it is used to translate the messages generated by the underlying ata-validator validation. The validator keeps what it compiled for the last two root schemas it validated against, and drops the older one's when a third arrives. Every form that uses the package's default export shares one validator, and so its cache: on a page with three or more such forms, moving between them compiles again. A form given its own validator from customizeValidator() keeps its own cache.

Parameters​

  • [options={}]: CustomValidatorOptionsType - The optional map of CustomValidatorOptionsType options that are used to create the ValidatorType instance. Supported options:
    • additionalMetaSchemas: Additional schemas registered for cross-schema $ref resolution
    • customFormats: Custom format checkers; values can be functions, RegExps, or pre-anchored regex source strings
    • ataOptionsOverrides: Overrides spread on top of the default ata-validator options (e.g. coerceTypes, removeAdditional, verbose, abortEarly)
    • extenderFn: A function called against the constructed Validator instance for additional setup; returning a different instance is supported
    • suppressDuplicateFiltering: Controls filtering of duplicate anyOf/oneOf errors using the SuppressDuplicateFilteringType type. 'none' (default) filters duplicates for both; 'anyOf' suppresses filtering for anyOf (oneOf duplicates still filtered); 'oneOf' suppresses filtering for oneOf (anyOf duplicates still filtered); 'all' disables all duplicate filtering.
  • [localizer]: Localizer | undefined - If provided, is used to localize a list of ata-validator ValidationErrors after running the form validation

Returns​

  • ATAValidator<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.customFormats must 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 options accepted by customizeValidator(). The schemas compiled are the ones getValidationSchemas() lists. The customizeValidator() options have limits: extenderFn, extra schemas without an $id and the ataOptionsOverrides keys coerceTypes, removeAdditional and keywords cannot be carried into the generated file and are ignored with a warning, the generated file never fills in default values, and suppressDuplicateFiltering belongs to createPrecompiledValidator(). See the precompiled section of usage/validation.md

createPrecompiledValidator<S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = FormContextType>()​

Creates and returns an ATAPrecompiledValidator, an implementation of ValidatorType that uses the precompiled validator functions. If a localizer is provided, it is used to translate the messages generated by the underlying ata-validator validation.

NOTE: The validateFns parameter is an object obtained by importing from a precompiled validation file created via the compileSchemaValidators() 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
  • [options]: PrecompiledValidatorOptionsType<S> | undefined - The options the validator is constructed with: a localizer, used to localize the engine's errors; a suppressDuplicateFiltering, controlling filtering of duplicate anyOf/oneOf errors (see customizeValidator()); and the form's customMergeAllOf, used when the validator resolves its own root schema to check the schema it is handed against it

Returns​

  • ATAPrecompiledValidator<S, F>: The precompiled validator implementation resulting from the set of parameters provided, a ValidatorType whose rawValidation() reports ata-validator's ValidationErrors