Skip to content

Comments

Fix enum type misinterpretation as union in record fields #663

Merged
pasindufernando1 merged 5 commits intoballerina-platform:1.5.xfrom
pasindufernando1:1381Fix
Jan 30, 2026
Merged

Fix enum type misinterpretation as union in record fields #663
pasindufernando1 merged 5 commits intoballerina-platform:1.5.xfrom
pasindufernando1:1381Fix

Conversation

@pasindufernando1
Copy link
Contributor

@pasindufernando1 pasindufernando1 commented Jan 28, 2026

Purpose

This PR fixes the issue of the inability of the enum members of a record getting treated as unions in the data-mapper backend model. Here when a union type is encountered, all its members are checked if they are singleton (which is the case of enum) and if so it is treated as a enum.
Fixes : wso2/product-ballerina-integrator#1381

Copilot AI review requested due to automatic review settings January 28, 2026 11:44
Copy link
Contributor

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

This pull request fixes an issue where enum types were being misinterpreted as union types when used in record fields. The fix introduces logic to detect when a union type consists entirely of singleton members, which indicates it should be treated as an enum type instead.

Changes:

  • Added enum detection logic in the union type processing to identify when all members are singletons
  • Refactored enum type creation into a reusable createEnumType helper method
  • Updated test data files to reflect the correct enum representation (using "members" instead of "memberTypes" and "enum" instead of "union")

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
misc/diagram-util/src/main/java/org/ballerinalang/diagramutil/connector/models/connector/ReferenceType.java Added singleton detection logic to differentiate enums from unions, and refactored enum creation into a helper method
misc/diagram-util/src/test/resources/RefTypeTest/TestData/enumSample1.json Updated test data to use correct enum structure (members/enum) instead of union structure (memberTypes/union)
misc/diagram-util/src/test/resources/RefTypeTest/TestData/enumSample2.json New test data file for validating enum type handling in records
misc/diagram-util/src/test/resources/RefTypeTest/BalProject7/main.bal Added Color enum and Person2 record for testing enum field handling
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/data_mapper_model/config/enum.json Updated member names to use qualified enum notation and changed type representation from union to enum
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/data_mapper_model/config/enum2.json Updated member names to use qualified enum notation and changed type representation from union to enum
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/data_mapper_custom_function/config/enum_member.json New test configuration file for enum member handling in custom functions
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/data_mapper_custom_function/source/proj4/main.bal New test source file with function transforming optional patient data
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/data_mapper_custom_function/source/proj4/Ballerina.toml New Ballerina project configuration for test project
flow-model-generator/modules/flow-model-generator-ls-extension/src/test/resources/data_mapper_custom_function/source/proj4/functions.bal Empty functions file for test project

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

Copy link
Contributor

@NipunaRanasinghe NipunaRanasinghe left a comment

Choose a reason for hiding this comment

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

@pasindufernando1 could you please attach the valid issue link in the PR description? current link seems to be pointing to the issues tab

@pasindufernando1 pasindufernando1 merged commit 25fce26 into ballerina-platform:1.5.x Jan 30, 2026
3 checks passed
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.

4 participants