feat: improve support for `minItems` and `maxItems` for array layout and control by Typiqally · Pull Request #2387 · eclipsesource/jsonforms
Added improved support for the minItems and maxItems properties, to allow for more fine-grained control and validation in ArrayControl and ArrayLayout applications. I have also added additional tests to cover these properties.
While working on this, I realized that the current handling of array (or items) schemas is too restrictive for custom implementations. Specifically, the schema is being completely replaced by the items schema, which typically only includes a basic type description and hides important details like the min and max item properties from the original array schema.
| export const mapStateToArrayControlProps = ( | |
| state: JsonFormsState, | |
| ownProps: OwnPropsOfControl | |
| ): StatePropsOfArrayControl => { | |
| const { path, schema, uischema, label, ...props } = | |
| mapStateToControlWithDetailProps(state, ownProps); | |
| const resolvedSchema = Resolve.schema(schema, 'items', props.rootSchema); | |
| const childErrors = getSubErrorsAt(path, resolvedSchema)(state); | |
| return { | |
| ...props, | |
| label, | |
| path, | |
| uischema, | |
| schema: resolvedSchema, | |
| childErrors, | |
| renderers: ownProps.renderers || getRenderers(state), | |
| cells: ownProps.cells || getCells(state), | |
| }; | |
| }; |
To address these limitations, I see two possible approaches:
- Add a
parentSchemaproperty to preserve the original schema, keeping the existing behavior while easing the constraints. This might introduce some confusion around naming. - Store the original schema in the
schemaproperty and put the resolved schema in a newarraySchemaoritemsSchemaproperty. However, this would change the current behavior, requiring migration.
I’d appreciate your thoughts on these options.