jsonforms icon indicating copy to clipboard operation
jsonforms copied to clipboard

schemaMatches not working as expected when using an array schema with refs

Open lovervoorde opened this issue 10 months ago • 2 comments

Describe the bug

When using schemaMatches for an array control, it does not behave as expected in terms of resolving refs.

Expected behavior

When using schemaMatches for an array control, I would expect to be able to do:

const MultiAutocompleteTester = rankWith(
  4,
  and(
    isPrimitiveArrayControl,
    schemaMatches(
      schema => schema.items.enum != null
    )
  )
)

However, I need to do:

const MultiAutocompleteTester = rankWith(
  4,
  and(
    isPrimitiveArrayControl,
    schemaMatches(
      (schema, rootSchema) =>
        resolveSchema(schema, 'items', rootSchema).enum != null
    )
  )
)

With the following root schema:

{
  "type": "object",
  "properties": {
    "foo": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/Foo"
      }
    }
  },
  "definitions": {
    "Foo": {
      "enum": ["a", "b"],
      "type": "string"
    }
  }
}

Steps to reproduce the issue

Try to create a custom tester for a string array renderer

Screenshots

No response

Which Version of JSON Forms are you using?

3.2.1

Package

Core

Additional context

No response

lovervoorde avatar Feb 10 '25 13:02 lovervoorde

Hi @lovervoorde,

This is the intended behavior. We only resolve exactly to the "ref" element, we do not automatically resolve all sub properties.

sdirix avatar Feb 10 '25 14:02 sdirix

Hi @sdirix, thanks for the quick reply! I understand not wanting to fully dereference, because it could in principal be infinite, but I'd argue that this specific level in would make sense? Anyway, no worries if not, just thought it was worth a shot, I have the work-around anyway.

lovervoorde avatar Feb 10 '25 14:02 lovervoorde

We do not intend to change the behavior for now. If you disagree, feel free to reopen

sdirix avatar Jul 17 '25 09:07 sdirix