Skip to content

Comments

Support NMTOKENS as built in type#38

Merged
Nuvindu merged 5 commits intoballerina-platform:mainfrom
Nuvindu:nmtokens
Feb 18, 2026
Merged

Support NMTOKENS as built in type#38
Nuvindu merged 5 commits intoballerina-platform:mainfrom
Nuvindu:nmtokens

Conversation

@Nuvindu
Copy link
Contributor

@Nuvindu Nuvindu commented Feb 6, 2026

Purpose

Fixes: ballerina-platform/ballerina-library#8660

Summary

This pull request adds support for additional XSD built-in types (xs:NMTOKENS, xs:ENTITY, xs:ENTITIES, and xs:NAME) to the Ballerina XSD tool. Previously, when an XSD schema contained these types, the generated Ballerina records would reference unknown types, causing compilation failures.

Key Changes

Type Support Enhancement

  • Added public constants in Utils.java for the four previously unsupported built-in types: NMTOKENS, ENTITY, ENTITIES, and NAME
  • Extended the type recognition and mapping logic to properly handle these types by treating them as STRING types in the generated code
  • Consolidated type checking by introducing a centralized SIMPLE_TYPES set for improved maintainability

Testing and Validation

  • Introduced a new test case (44_elements_with_builtin_string_types) with corresponding XSD and expected Ballerina output
  • Added test resource files demonstrating proper generation of records for elements using the newly supported types

Version Updates

  • Bumped module version from 1.2.0 to 1.2.1 across BalTool.toml, Ballerina.toml, and Dependencies.toml to reflect the new functionality

Outcome

Generated Ballerina code now correctly compiles when working with XSD schemas that use xs:NMTOKENS and related built-in types, eliminating unknown type reference errors that previously blocked code generation.

Copy link

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 PR updates the XSD-to-Ballerina type mapping to treat additional XML Schema built-in simple types (notably NMTOKENS) as supported built-ins, and bumps the Ballerina tool package version to 1.2.1 for the fix linked in ballerina-library#8660.

Changes:

  • Add new XSD built-in type constants (NMTOKENS, ENTITY, ENTITIES, Name) and map them to Ballerina string.
  • Expand the “simple type” detection list to include these newly supported built-ins.
  • Bump module-ballerina-xsd package/dependency versions to 1.2.1 and update BalTool jar paths.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
xsd-core/src/main/java/io/ballerina/xsd/core/visitor/Utils.java Adds new built-in XSD type constants and updates type mapping / simple-type detection logic.
module-ballerina-xsd/Dependencies.toml Updates dependency version to 1.2.1.
module-ballerina-xsd/Ballerina.toml Updates package version to 1.2.1.
module-ballerina-xsd/BalTool.toml Updates local jar paths to 1.2.1-SNAPSHOT.

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

@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

The PR bumps module version from 1.2.0 to 1.2.1 across configuration files and extends the XSD-to-Record converter to support additional XSD built-in string types: NMTOKENS, ENTITY, ENTITIES, and NAME by mapping them to string in the type generator.

Changes

Cohort / File(s) Summary
Configuration & Version Updates
BalTool.toml, Ballerina.toml, Dependencies.toml
Version bumps from 1.2.0 to 1.2.1 across module configuration and dependency files; BalTool.toml also updates to SNAPSHOT qualifier for XSD dependencies.
Core Type Support Enhancement
xsd-core/src/main/java/io/ballerina/xsd/core/visitor/Utils.java
Adds public constants for XSD string types (NMTOKENS, ENTITY, ENTITIES, NAME), introduces centralized SIMPLE_TYPES set, and extends type-to-string mapping in switch-case to recognize newly added types.
Test Infrastructure
xsd-core/src/test/java/io/ballerina/xsd/core/XSDToRecordTest.java, xsd-core/src/test/resources/xml/44_elements_with_builtin_string_types.xsd, xsd-core/src/test/resources/expected/44_elements_with_builtin_string_types.bal
Adds test case and resources for XSD-to-Ballerina record conversion of the newly supported built-in string types with corresponding expected output record declarations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #8660: The PR directly addresses the reported issue by introducing constants and type mappings for xs:NMTOKENS (and related XSD built-in types like ENTITY, ENTITIES, NAME) in the core visitor Utils class, enabling proper code generation for XSD schemas using these types.

Poem

A rabbit hops with glee so bright,
New types are mapped, the schemas light!
NMTOKENS, ENTITY, and NAME so true,
String-bound conversions, fresh and new! 🐰✨

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete; it only provides the Purpose section with a linked issue, but lacks Goals, Approach, Release notes, and other required template sections. Complete the PR description by filling in Goals, Approach, Release note, and other relevant template sections to provide comprehensive context for reviewers.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Out of Scope Changes check ❓ Inconclusive While most changes align with supporting NMTOKENS, the addition of ENTITY, ENTITIES, and NAME types appears broader than the specific issue scope, and version bumps lack clear justification in the description. Clarify in the PR description why ENTITY, ENTITIES, and NAME types were added beyond NMTOKENS, and provide rationale for the version bumps in BalTool.toml and Dependencies.toml.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Support NMTOKENS as built in type' clearly and concisely summarizes the main change, matching the primary objective of adding support for the xs:NMTOKENS built-in type.
Linked Issues check ✅ Passed The code changes fully address the linked issue #8660 by adding support for xs:NMTOKENS and related built-in string types (ENTITY, ENTITIES, NAME) in the XSD tool's type recognition system.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@Nuvindu Nuvindu merged commit 900280e into ballerina-platform:main Feb 18, 2026
4 checks passed
Copilot AI added a commit that referenced this pull request Feb 19, 2026
Co-authored-by: Nuvindu <63797478+Nuvindu@users.noreply.github.com>
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.

Support xs:NMTOKENS built-in type from the XSD tool

3 participants