Skip to content

Add support for v2 schema enum choice lists#42

Open
doneill wants to merge 4 commits into
developfrom
41-enum-choice-list
Open

Add support for v2 schema enum choice lists#42
doneill wants to merge 4 commits into
developfrom
41-enum-choice-list

Conversation

@doneill
Copy link
Copy Markdown
Collaborator

@doneill doneill commented May 29, 2026

Add support for #41

Proposed Changes

src/v2/utils.ts

  • createControl extracts x-enumExtra from the property's anyOf and injects the following into the contol when enum present
options.oneOf = [{ const, title }] 

src/common/generateUISchema.ts

  • Add enum as valid choice item

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.31

-Verify the app continues to display anyOf choice lists and enum choice lists

Unit Tests

jest test/v2.test.ts
 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
    ✓ should handle single column sections correctly (1 ms)
    ✓ 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
    ✓ 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 (1 ms)
    ✓ should handle doubly-nested collections with shared field names (Nested.Nest_1.Nest_Text)
    ✓ 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
  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
    ✓ 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:       32 passed, 32 total
Snapshots:   0 total
Time:        0.379 s

Copilot AI review requested due to automatic review settings May 29, 2026 06:09
@doneill doneill self-assigned this May 29, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds V2 CHOICE_LIST support for enum-based schemas with x-enumExtra, aligning UI schema generation with the newer EarthRanger schema format while preserving legacy oneOf handling.

Changes:

  • Accepts enum choice list structures during V2 schema validation.
  • Maps enum values plus x-enumExtra.display into JSONForms control options.
  • Adds tests for single-select, multi-select, fallback labels, backward compatibility, and immutability.

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/v2/utils.ts Adds enum-to-options.oneOf mapping for choice controls.
src/v2/generateUISchema.ts Extends CHOICE_LIST validation to accept enum arrays.
src/common/types.ts Updates V2 property typing for enum/x-enumExtra choice items.
test/v2.test.ts Adds coverage for enum choice-list generation behavior.
package.json Bumps package version.
package-lock.json Updates lockfile package metadata, but remains out of sync with package.json.
yarn.lock Updates dependency lock entries.

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

Comment thread src/v2/utils.ts
Comment on lines +100 to +104
const enumItem = anyOfSource?.find((a: any) => a.enum && a["x-enumExtra"]);
if (enumItem) {
control.options!.oneOf = enumItem.enum.map((value: any) => ({
const: value,
title: enumItem["x-enumExtra"][value]?.display ?? String(value),
Comment on lines +49 to +51
const isValidChoiceItem = (anyOfItem: any): boolean =>
(anyOfItem.oneOf && Array.isArray(anyOfItem.oneOf)) ||
(anyOfItem.enum && Array.isArray(anyOfItem.enum));
@doneill doneill changed the title 41 enum choice list Add support for v2 schema enum choice lists May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants