react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Empty anyOf invalid schema on first validation

Open hunterpollpeter opened this issue 2 years ago • 2 comments

Prerequisites

What theme are you using?

core

Version

5.13.2

Current Behavior

An object with a property of type ["string", "null"] (foo in the example) that uses an empty anyOf has an invalid schema on the first validation, on subsequent validations the schema is valid. It does not matter if you use AJV raw validation or the RJSF validate button in the playground. The invalid schema error shows on the first of either, and not on subsequent of both.

Interestingly in the AJV raw validate the first validation returns:

{ "validationError": {} }

Expected Behavior

The schema should not be invalid on the first validation.

Steps To Reproduce

Here is a playground link

Must refresh to get "first" validation issue.

Environment

- OS: macOS 14.0
- Node: 16.20.1
- npm: 8.19.4

Anything else?

No response

hunterpollpeter avatar Oct 31 '23 19:10 hunterpollpeter

The issue alone is not a huge deal, but here is a playground that demonstrates where it becomes an issue. For us we want to have anyOfs that may be empty as dependencies of non-empty anyOfs. Because the schema is initially invalid dependencies do not work (RJSF resolves the schema before passing it to the field). You can see the same behavior I mentioned in the issue in this playground as well. The first validation failes, whether it's AJV raw validate or the RJSF validate. Subsequent validations are valid.

hunterpollpeter avatar Oct 31 '23 21:10 hunterpollpeter

This example highlights two issues:

  1. The AJV compilation error is NOT being properly shown in the playground
  2. The AJV compilation error only happens once and should happen every time, this is likely due to the AJV caching system, and thus we need to fix the validator-ajv8 package so that we remove the cached compile on an compilation error.

heath-freenome avatar Nov 17 '23 20:11 heath-freenome