Skip to content

Issues when using the library to implement an RJSF validator #218

@x0k

Description

@x0k

Related to rjsf-team/react-jsonschema-form#4923

I continued working on the validator using this library and encountered the following issues:

  • The library is not published, so it cannot be specified as a peer dependency.

  • Errors still cannot be retrieved synchronously, for two reasons:

  1. Localization - in addition to being synchronous, it would be preferable to avoid using platform-specific APIs and ensure tree-shaking support
  2. constructErrorIndex is asynchronous and not exposed in the public API

At the moment, I had to duplicate the implementations of Localization and constructErrorIndex in the validator project.

  • When validating an object with missing properties, the library returns an error like this:
[
  {
    "message": "Missing required ⁨properties: ⁨id, email, and age⁩⁩",
    "instanceLocation": "#",
    "schemaLocations": [
      "https://example.com/v0#/required"
    ]
  }
]

This is correct and suitable for something like a REST API, but for form validation it would be preferable to get the following list (not structurally identical, but equivalent in content), so that errors can be displayed for specific fields:

[
  {
    "message": "Missing required ⁨property: ⁨id",
    "path": ["id"]
  },
  {
    "message": "Missing required ⁨property: email⁩⁩",
    "path": ["email"]
  },
  {
    "message": "Missing required ⁨property: age⁩⁩",
    "path": ["age"]
  }
]

Here is how it currently works with AJV:

  • Each field has its own error
  • Errors include metadata such as missingProperty, propertyName
  • If metadata is present, the validator appends it to the instancePath during error processing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions