-
Notifications
You must be signed in to change notification settings - Fork 84
Add default namespace prefix for simple type references in generated XSDs #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…fix for references to simple types, such as enum types => we want to add the default namespace prefix to those nodes in order to get xjc-compatible XSD:s.
|
Could You try to add some tests? |
|
Added some tests from Klas. |
|
slachiewicz Are the added tests sufficient? |
There was a problem hiding this 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 addresses namespace prefix issues in generated XSD files to improve compatibility with xjc by ensuring simple type references (like enums) include appropriate default namespace prefixes.
- Enhanced ChangeNamespacePrefixProcessor to detect and prefix unprefixed element references in the default namespace (tns)
- Improved SimpleNamespaceResolver to preserve "tns" prefix mappings and handle prefix conflicts more safely
- Added validation in XsdGeneratorHelper to prevent unnecessary prefix substitutions
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| SimpleNamespaceResolver.java | Added logic to preserve "tns" prefix and handle prefix/URI mapping conflicts |
| ChangeNamespacePrefixProcessor.java | Added detection and prefixing of unprefixed element references for default namespace |
| XsdGeneratorHelper.java | Added check to prevent unnecessary prefix substitutions when old and new prefixes are identical |
| SimpleNamespaceResolverTest.java | Added comprehensive tests for "tns" prefix preservation and conflict detection |
| ChangeNamespacePrefixProcessorTest.java | Added tests for element reference prefixing behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| String oldPrefix = uri2Prefix.get(nodeValue); | ||
| if (oldPrefix == null || !oldPrefix.equals("tns")) { |
Copilot
AI
Oct 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable oldPrefix is retrieved but not used in the main logic flow within the if block. Consider retrieving it only when needed or clarify its purpose with better variable naming.
| String oldPrefix = uri2Prefix.get(nodeValue); | |
| if (oldPrefix == null || !oldPrefix.equals("tns")) { | |
| if (uri2Prefix.get(nodeValue) == null || !uri2Prefix.get(nodeValue).equals("tns")) { |
| // simpletypes, such as enum types => we want to add the default namespace prefix to those nodes in | ||
| // order to get xjc-compatible XSD:s |
Copilot
AI
Oct 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'simpletypes' to 'simple types' and 'XSD:s' to 'XSDs'.
| // simpletypes, such as enum types => we want to add the default namespace prefix to those nodes in | |
| // order to get xjc-compatible XSD:s | |
| // simple types, such as enum types => we want to add the default namespace prefix to those nodes in | |
| // order to get xjc-compatible XSDs |
This patch addresses an issue where schemagen does not generate the default namespace prefix for references to simple types (such as enum types), resulting in XSDs that are not fully compatible with xjc. The following changes were made:
Added logic to detect element references without a namespace prefix and prepend the default namespace prefix where appropriate.
These changes ensure that generated XSDs include the correct namespace prefixes, improving compatibility with tools expecting explicit prefixes.
These two PR:s, written by a former colleague, are no longer relevant and can be closed.