Skip to content

Fix UI schema generation and restore enable condition delegation#36

Merged
thuva9872 merged 5 commits intowso2:1.x.x-jdk17from
iamvirul:fix-connector-schema-generation-jdk17
Apr 26, 2026
Merged

Fix UI schema generation and restore enable condition delegation#36
thuva9872 merged 5 commits intowso2:1.x.x-jdk17from
iamvirul:fix-connector-schema-generation-jdk17

Conversation

@iamvirul
Copy link
Copy Markdown
Member

@iamvirul iamvirul commented Apr 9, 2026

Purpose

Fix three connector schema generation bugs that cause runtime failures in generated WSO2 MI Ballerina connectors:

  1. Union map parameter pointer mismatch — connections using a map<string> union member (e.g. DestinationConfig|map<string>) could not be saved in MI Studio because the init.xml property pointer used config_map (underscore) while both the <parameter> declaration and the uischema field name used configMap (camelCase). At runtime lookupTemplateParameter returned null, propagating as a null argument to createObjectValue and ultimately causing a NullPointerException inside the Ballerina connector's init method.

  2. TypeDescriptor union parameter generation — when a function parameter is a typedesc-backed union (e.g. typedesc<SomeRecord|OtherRecord>), the generated functions XML incorrectly emitted individual union member <parameter> declarations and union pointer properties as if it were a regular union. This produced spurious parameters in the Synapse template and wrong property values that the runtime could not resolve.

  3. Attribute group enable condition propagation — when all fields inside a grouped union member share the same enableCondition, the condition was not being promoted to the enclosing attributeGroup element. MI Studio rendered the group as always-visible even when its containing union branch was not selected.

Goals

  • Generated init.xml and uischema JSON are fully consistent for union parameters containing map<string> members, so the connection can be saved and the runtime can resolve the value correctly.
  • TypeDescriptor union parameters produce only the discriminator DataType property in the Synapse template; individual member parameters and union pointer properties are suppressed, matching the runtime's typedesc resolution path.
  • Attribute groups whose members all share one enableCondition automatically inherit that condition (merged with any parent condition), so the group is hidden/shown correctly in MI Studio without requiring individual field conditions on every element.

Approach

1. Union map pointer fix (XmlPropertyWriter.java)

writeXmlParamProperties was building the union member pointer value as sanitizedParamName + "_map" (e.g. config_map), but writeXmlParameterElements and JsonGenerator both derive the parameter/field name as sanitizedParamName + "Map" (camelCase, via StringUtils.capitalize). Changed the format string to use sanitizedParamName + "Map" so all three are consistent:

Before: <property name="SAP_JCO_CLIENT_param0UnionMap" value="config_map"/>
After:  <property name="SAP_JCO_CLIENT_param0UnionMap" value="configMap"/>

2. TypeDescriptor union template fix (functions_template.xml)

Added {{#unless typeDescriptor}} guards around:

  • The union member <parameter> declarations in the template header section
  • The param{{index}}Union* property block in the sequence section

Also corrected the param{{index}} property value for typedesc union parameters to emit {{sanitizeParamName value}}DataType (pointing at the discriminator template parameter) rather than the bare param name, and simplified the union pointer value expression to always use {{sanitizeParamName value}} (removing the now-incorrect typeDescriptor branch that had been there).

3. Enable condition delegation (JsonGenerator.java)

When building an AttributeGroup for grouped union member fields, the logic now inspects the child fields' enableCondition values. If all children share the same condition, that condition is promoted to the group level (merged with any parent condition on the union parameter). This replaces the previous approach of only propagating the parent's own condition, which left groups without a condition when the parent condition was null but all children had one.

User stories

  • As a connector developer, when I generate an MI connector from a Ballerina module with a Type1|map<string> init parameter, the generated connection form saves successfully and the runtime resolves the map value.
  • As a connector developer, when I generate an MI connector with typedesc<T> parameters, the generated XML template does not emit unnecessary union member parameters that break runtime resolution.
  • As a connector user, when I open a connection form that contains union parameters, the MI Studio correctly hides or shows field groups based on which union member is selected.

Release note

Fixed connector schema generation for union parameters containing map<string> members (connection save failure due to parameter name mismatch), typedesc union parameters (spurious XML declarations causing runtime errors), and attribute group enable condition propagation (groups not correctly hidden/shown in MI Studio when a union branch is deselected).

Documentation

N/A — internal schema generation fixes; no user-facing documentation change required.

Training

N/A

Certification

N/A

Marketing

N/A

Automation tests

  • Unit tests

    • All 32 existing XmlPropertyWriterTest tests pass.
    • All 63 existing ParamHandlerTest tests pass.
    • No new test cases added in this PR; the three bugs are regression candidates for a follow-up.
  • Integration tests

    • Manually verified with the SAP JCo connector (ballerinax/sap.jco) that a connection using DestinationConfig as the union member saves successfully and the AdvancedConfig (map<string>) branch no longer causes a null argument to createObjectValue.

Security checks

Samples

N/A

Related PRs

N/A

Migrations (if applicable)

Connectors regenerated after this fix will have a corrected init.xml property pointer (configMap instead of config_map). Existing connections created from a pre-fix connector zip must be deleted and recreated in MI Studio after redeploying the regenerated connector, as the localEntry field names are derived from the uischema at connection-creation time.

Test environment

  • JDK 17
  • macOS 15.3
  • WSO2 MI 4.5.0

Learning

Root cause of bug #1 traced by comparing the writeXmlParameterElements path (which uses StringUtils.capitalize on the member type label to produce camelCase) against the writeXmlParamProperties path (which used a hardcoded underscore concatenation). The two code paths were independently written and diverged without a test that covered the full round-trip from generation through runtime resolution.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 9, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d18a6ed-3654-4a0f-a585-255908fdbd05

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@iamvirul iamvirul force-pushed the fix-connector-schema-generation-jdk17 branch from 1cc9f64 to a9bfba2 Compare April 9, 2026 11:33
@iamvirul iamvirul closed this Apr 24, 2026
@iamvirul iamvirul reopened this Apr 24, 2026
@thuva9872 thuva9872 merged commit 27ea287 into wso2:1.x.x-jdk17 Apr 26, 2026
5 of 6 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.

2 participants