Skip to content

Support array type in v2 Attachment field#44

Open
doneill wants to merge 4 commits into
developfrom
task/43-attachment-field-array
Open

Support array type in v2 Attachment field#44
doneill wants to merge 4 commits into
developfrom
task/43-attachment-field-array

Conversation

@doneill

@doneill doneill commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Add support for #42

Proposed Changes

  • Update ATTACHMENT case with array support
  • Updated the typed model to support uuid format
  • Update tests

Implementation Test

In React Native client app, e.g. EarthRanger

- yarn remove @earthranger/react-native-jsonforms-formatter
- yarn add @earthranger/react-native-jsonforms-formatter@2.0.0-beta.33

Unit Tests

 PASS  test/v2.test.ts
  V2 generateUISchema
    ✓ should generate UI schema for basic V2 schema (2 ms)
    ✓ should create controls with proper scopes and labels
    ✓ should handle text field options correctly (1 ms)
    ✓ should handle numeric field options correctly
    ✓ should handle choice list field options correctly
    ✓ should handle date-time field options correctly
    ✓ should handle location field options correctly
    ✓ should handle collection field options correctly (1 ms)
    ✓ should exclude deprecated fields
    ✓ should handle inactive sections
    ✓ should respect section order
    ✓ should handle collection constraints and column layout (1 ms)
    ✓ should handle single column sections correctly
    ✓ should handle two column sections correctly (React Native single-column)
    ✓ should apply UI field properties to collection item fields
    ✓ should resolve same-named fields at different nesting levels using qualified ids (1 ms)
    ✓ should not apply a top-level field config to a collection child when the section id matches the collection local name
    ✓ should handle old-format schema where collection child shares name with parent collection
    ✓ should handle doubly-nested collections with shared field names (Nested.Nest_1.Nest_Text) (1 ms)
    ✓ should support nested collections (collection within collection)
  BOOLEAN field type
    ✓ generates a Control with boolean format
    ✓ includes the description in options
    ✓ deprecated boolean field is not rendered (1 ms)
  ATTACHMENT field type
    ✓ generates a file control with array semantics
    ✓ omits maxItems/minItems when not declared
    ✓ joins multiple allowableFileTypes into accept
    ✓ supports ATTACHMENT inside a COLLECTION
    ✓ throws when an ATTACHMENT field is not an array (6 ms)
    ✓ throws when an ATTACHMENT array lacks items.required (2 ms)
  V2 generateUISchema — enum + x-enumExtra format (issue #41)
    ✓ accepts single-select CHOICE_LIST with enum format without throwing
    ✓ accepts multi-select CHOICE_LIST with enum format on items without throwing
    ✓ generates dropdown control for single-select enum field with placeholder
    ✓ injects options.oneOf with display titles for single-select enum field
    ✓ generates multi dropdown control for array enum field with placeholder
    ✓ injects options.oneOf with display titles for multi-select array enum field (1 ms)
    ✓ falls back to raw enum value as title when x-enumExtra is missing an entry
    ✓ injects options.oneOf using raw values as titles when x-enumExtra is entirely absent
    ✓ does not inject options.oneOf for old-format oneOf schemas (backward compatibility)
    ✓ does not mutate the original schema.json

Test Suites: 1 passed, 1 total
Tests:       39 passed, 39 total
Snapshots:   0 total
Time:        0.307 s, estimated 1 s

Copilot AI review requested due to automatic review settings June 21, 2026 21:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for V2 ATTACHMENT fields modeled as arrays of objects (e.g., { uploadId: <uuid> }), updates the V2 type model to recognize uuid format (and unevaluatedProperties), and expands unit tests to cover attachment behaviors and validation.

Changes:

  • Extend ATTACHMENT control generation to support array semantics (multi, min/max items, uniqueness, item key, accept).
  • Add V2 schema validation for ATTACHMENT shape requirements.
  • Update shared V2 types to include format: 'uuid' and unevaluatedProperties, plus add/expand ATTACHMENT-focused tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/v2/utils.ts Adds ATTACHMENT array semantics to createControl.
src/v2/generateUISchema.ts Adds schema validation rules for ATTACHMENT fields.
src/common/types.ts Extends V2 property typing (uuid format, unevaluatedProperties).
test/v2.test.ts Adds unit tests for ATTACHMENT array behavior, constraints, and validation failures.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/v2/utils.ts
Comment on lines +152 to +167
if (property.type === "array") {
control.options!.multi = true;
if (property.maxItems !== undefined) {
control.options!.maxItems = property.maxItems;
}
if (property.minItems !== undefined) {
control.options!.minItems = property.minItems;
}
if (property.uniqueItems) {
control.options!.uniqueItems = true;
}
const itemKey = Object.keys(property.items?.properties ?? {})[0];
if (itemKey) {
control.options!.itemKey = itemKey;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants