Support array type in v2 Attachment field#44
Open
doneill wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
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
ATTACHMENTcontrol generation to support array semantics (multi, min/max items, uniqueness, item key, accept). - Add V2 schema validation for
ATTACHMENTshape requirements. - Update shared V2 types to include
format: 'uuid'andunevaluatedProperties, 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 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for #42
Proposed Changes
ATTACHMENTcase with array supportuuidformatImplementation Test
In React Native client app, e.g. EarthRanger
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