Add Dynamic namespace serialization mode that collects xmlns declarations at runtime#259
Conversation
f653f73 to
cc91aec
Compare
cc91aec to
6dba331
Compare
There was a problem hiding this comment.
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::Dynamicand wires it intoConfigto automatically add a newQuickXmlCollectNamespacesrender step. - Adds a
CollectNamespacestrait (with primitive/container impls) and codegen for generated types to traverse values and emit only requiredxmlnsdeclarations on the root element. - Adds/updates integration tests and expected outputs to validate dynamic behavior (incl.
xmlns:xsionly 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.
xsd-parser/src/pipeline/renderer/steps/quick_xml/collect_namespaces.rs
Outdated
Show resolved
Hide resolved
cdd43be to
f62f3af
Compare
There was a problem hiding this comment.
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.
xsd-parser/src/pipeline/renderer/steps/quick_xml/collect_namespaces.rs
Outdated
Show resolved
Hide resolved
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.
f62f3af to
567ee6c
Compare
There was a problem hiding this comment.
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.
Related to #256