Skip to content

Conversation

@klasfahlberg
Copy link

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.

  • Updated ChangeNamespacePrefixProcessor to handle these cases and ensure compatibility.
  • Adjusted SimpleNamespaceResolver to avoid overwriting the tns prefix and improve prefix/URI mapping safety.
  • Minor update in XsdGeneratorHelper to prevent unnecessary prefix substitutions.

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.

Johan Fredlander and others added 2 commits April 4, 2025 13:47
…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.
@klasfahlberg klasfahlberg changed the title Add default namespace prefix for simple type references in generated XSDsLadok patches Add default namespace prefix for simple type references in generated XSDs Jun 2, 2025
@slachiewicz
Copy link
Member

Could You try to add some tests?

@xdy
Copy link

xdy commented Aug 15, 2025

Added some tests from Klas.

@klasfahlberg
Copy link
Author

slachiewicz Are the added tests sufficient?

@slachiewicz slachiewicz requested a review from Copilot October 5, 2025 18:07
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 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.

Comment on lines +204 to +205
String oldPrefix = uri2Prefix.get(nodeValue);
if (oldPrefix == null || !oldPrefix.equals("tns")) {
Copy link

Copilot AI Oct 5, 2025

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.

Suggested change
String oldPrefix = uri2Prefix.get(nodeValue);
if (oldPrefix == null || !oldPrefix.equals("tns")) {
if (uri2Prefix.get(nodeValue) == null || !uri2Prefix.get(nodeValue).equals("tns")) {

Copilot uses AI. Check for mistakes.
Comment on lines +132 to +133
// simpletypes, such as enum types => we want to add the default namespace prefix to those nodes in
// order to get xjc-compatible XSD:s
Copy link

Copilot AI Oct 5, 2025

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

Suggested change
// 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

Copilot uses AI. Check for mistakes.
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.

3 participants