Skip to content

trouble with native compatibility with ajv-i18n #1195

@RUVATA

Description

@RUVATA

Prerequisites

Description

Current realization of errors object incomes in transformErrors (https://react-jsonschema-form.readthedocs.io/en/latest/validation/#custom-error-messages) is incompatible with ajv-i18n (https://github.com/epoberezkin/ajv-i18n)

Since the AJV is used internally, it would be nice to ensure compatibility with AJV native i18n gear, especially considering that such compatibility is very simple to provide by expanding the "erorrs" with one property "keyword", the value for which already exists in members of incoming errors array members as "name" property.

See my playground sample (https://codesandbox.io/embed/vm3lz56j53?fontsize=14), where basic erros array normalizing by map for full compilibility with ajv-i18n localization function.

Steps to Reproduce

  1. Install and import localization (as sample - directly ru) function for ajv-i18n npm package
  2. declare transformErrors fucntion where try to call localization function on basic (non modified) errors incoming argument
    function transformErrors(errors) { localize_ru(errors); return i18n_normalized; }
  3. You will take error about missing required 'keyword' property in ajv-i18n
  4. Then modify your transformErrors, where you previously normilize errors object with basic map
    function transformErrors(errors) { const i18n_normalized = errors.map(e => ({ ...e, keyword: e.name })); localize_ru(i18n_normalized); return i18n_normalized; }
  5. errors messages are succsefully localizated with ajv-i18n

Expected behavior

The erros array members (objects) will have 'keyword' property (duplicated 'name' property value)

PS: May be 'name' property will be renamed to 'keyword' with concurrent refactoring thats usages in other project sources

Actual behavior

The erros array members (objects) not have 'keyword' property, and ajv-i18n localization gear crashes called with the current errors array as argumnet

Version

current major - 1.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions