jsonforms
jsonforms copied to clipboard
schemaMatches not working as expected when using an array schema with refs
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
Hi @lovervoorde,
This is the intended behavior. We only resolve exactly to the "ref" element, we do not automatically resolve all sub properties.
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.
We do not intend to change the behavior for now. If you disagree, feel free to reopen