Skip to content

Add Dynamic namespace serialization mode that collects xmlns declarations at runtime#259

Merged
Bergmann89 merged 1 commit intomasterfrom
copilot/fix-xmlns-xsi-emission
Mar 20, 2026
Merged

Add Dynamic namespace serialization mode that collects xmlns declarations at runtime#259
Bergmann89 merged 1 commit intomasterfrom
copilot/fix-xmlns-xsi-emission

Conversation

Copy link
Contributor

Copilot AI commented Mar 16, 2026

Related to #256

Copilot AI changed the title [WIP] Fix generated serializer unconditionally emitting xmlns:xsi Add Dynamic namespace serialization mode that collects xmlns declarations at runtime Mar 16, 2026
Copilot AI requested a review from Bergmann89 March 16, 2026 19:50
@Bergmann89 Bergmann89 force-pushed the copilot/fix-xmlns-xsi-emission branch from f653f73 to cc91aec Compare March 20, 2026 18:00
@Bergmann89 Bergmann89 requested a review from Copilot March 20, 2026 18:01
@Bergmann89 Bergmann89 marked this pull request as ready for review March 20, 2026 18:01
@Bergmann89 Bergmann89 force-pushed the copilot/fix-xmlns-xsi-emission branch from cc91aec to 6dba331 Compare March 20, 2026 18:04
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

Adds a new NamespaceSerialization::Dynamic mode for quick_xml codegen that collects namespace declarations from the runtime value before emitting the root start tag, preventing unconditional xmlns:xsi pollution when nillable support is enabled.

Changes:

  • Introduces NamespaceSerialization::Dynamic and wires it into Config to automatically add a new QuickXmlCollectNamespaces render step.
  • Adds a CollectNamespaces trait (with primitive/container impls) and codegen for generated types to traverse values and emit only required xmlns declarations on the root element.
  • Adds/updates integration tests and expected outputs to validate dynamic behavior (incl. xmlns:xsi only when a nil is present).

Reviewed changes

Copilot reviewed 25 out of 26 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
xsd-parser/tests/utils.rs Updates quick-xml event comparison (currently includes debug output).
xsd-parser/tests/feature/nillable/mod.rs Adds dynamic quick_xml generation + runtime serialization tests for nil vs non-nil.
xsd-parser/tests/feature/nillable/expected/dynamic_quick_xml.rs New expected generated code using CollectNamespaces at root.
xsd-parser/tests/feature/nillable/example/dynamic_with_nil.xml New expected output where root includes xmlns:xsi only when nil present.
xsd-parser/tests/feature/nillable/example/dynamic_no_nil.xml New expected output where xmlns:xsi is omitted when no nil present.
xsd-parser/tests/feature/namespaces_qualified/mod.rs Adds dynamic-mode test variants (alt / no-alt prefixes).
xsd-parser/tests/feature/namespaces_qualified/expected/quick_xml_dynamic_no_alt.rs New expected output for dynamic mode without alternative prefixes.
xsd-parser/tests/feature/namespaces_qualified/expected/quick_xml_dynamic_alt.rs New expected output for dynamic mode with alternative prefixes.
xsd-parser/tests/feature/namespaces_qualified/example/dynamic_no_alt.xml New expected XML for dynamic mode without alternative prefixes.
xsd-parser/tests/feature/namespaces_qualified/example/dynamic_alt.xml New expected XML for dynamic mode with alternative prefixes.
xsd-parser/src/pipeline/renderer/steps/quick_xml/serialize.rs Adds Dynamic variant and emits CollectNamespaces::collect_namespaces(...) on root.
xsd-parser/src/pipeline/renderer/steps/quick_xml/mod.rs Registers new collect_namespaces module and exports the render step.
xsd-parser/src/pipeline/renderer/steps/quick_xml/collect_namespaces.rs New render step generating CollectNamespaces impls for generated types.
xsd-parser/src/pipeline/renderer/steps/mod.rs Re-exports QuickXmlCollectNamespacesRenderStep.
xsd-parser/src/pipeline/renderer/mod.rs Re-exports QuickXmlCollectNamespacesRenderStep from the renderer.
xsd-parser/src/pipeline/generator/data/reference.rs Refactors nillable path handling (removes explicit absolute variable).
xsd-parser/src/pipeline/generator/data/mod.rs Centralizes “absolute paths” decision inside path_data_* helpers.
xsd-parser/src/pipeline/generator/data/complex.rs Updates call sites to refactored path_data_* helpers.
xsd-parser/src/models/data/path_data.rs Fixes generic rendering to include commas between generic arguments.
xsd-parser/src/lib.rs Exposes QuickXmlCollectNamespacesRenderStep from crate root exports.
xsd-parser/src/config/renderer.rs Adds RenderStep::QuickXmlCollectNamespaces to config system.
xsd-parser/src/config/mod.rs Auto-adds QuickXmlCollectNamespaces step when Dynamic is selected.
xsd-parser-types/src/xml/nillable.rs Implements CollectNamespaces for Nillable<T> (adds XSI only when nil).
xsd-parser-types/src/quick_xml/serialize.rs Introduces CollectNamespaces trait + impls for primitives/containers.
xsd-parser-types/src/quick_xml/mod.rs Re-exports CollectNamespaces.
.gitignore Ignores .devcontainer/.

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

@Bergmann89 Bergmann89 force-pushed the copilot/fix-xmlns-xsi-emission branch 2 times, most recently from cdd43be to f62f3af Compare March 20, 2026 18:26
@Bergmann89 Bergmann89 requested a review from Copilot March 20, 2026 18:27
@Bergmann89 Bergmann89 removed their request for review March 20, 2026 18:28
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

Copilot reviewed 24 out of 25 changed files in this pull request and generated 1 comment.


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

THis commits adds a new `Dynamic` variant to the `NamespaceEvaluation` enum,
which allows for dynamic evaluation of namespaces during serialization.
In contrast to the other variants, which evaluates the namespaces during
code generation, the `Dynamic` variant evaluates the namespaces at runtime,
allowing for more flexibility and reducing the number of namespaces emitted
for a XML document.
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

Copilot reviewed 24 out of 25 changed files in this pull request and generated no new comments.


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

@Bergmann89 Bergmann89 merged commit 5327482 into master Mar 20, 2026
6 checks passed
@Bergmann89 Bergmann89 deleted the copilot/fix-xmlns-xsi-emission branch March 20, 2026 18:47
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.

3 participants