Implement support for advanced enum deserialization#240
Merged
Bergmann89 merged 3 commits intomasterfrom Feb 20, 2026
Merged
Conversation
This was a leftover from the old naming schema of the data types.
The new approach now also differentiates between the generator and the renderer stage, providing more flexibility and better separation of concerns and reusability of already implemented functions in the generator and render contexts. In addition to the stages a new mode was introduced to differentiate between literal, constant/compile-time, or normal/run-time value generation. This is needed by the planed advanced enumerations feature.
There was a problem hiding this comment.
Pull request overview
This pull request implements support for advanced enum deserialization to address issue #217, which concerns namespace preservation and comparison for enum values. The implementation adds a new ADVANCED_ENUMS flag and introduces a flexible value generation/rendering architecture that enables enums based on types like QName to properly serialize and deserialize with namespace resolution.
Changes:
- Introduced
ValueGeneratorandValueRenderertrait system to enable flexible code generation for default values and enum constants with different modes (Literal, Constant, Value) - Added
ADVANCED_ENUMSgenerator flag andEnumConstantsRenderStepto generate typed constants for enum variants based on their simple base types - Implemented QName support with proper namespace resolution for enum deserialization that compares namespace-qualified names instead of raw strings
Reviewed changes
Copilot reviewed 62 out of 62 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| xsd-parser/src/config/generator.rs | Added ADVANCED_ENUMS flag to enable advanced enum support |
| xsd-parser/src/config/mod.rs | Added with_advanced_enums() and with_qname_type() convenience methods |
| xsd-parser/src/config/renderer.rs | Added EnumConstants render step configuration |
| xsd-parser/src/models/data/enumeration.rs | Renamed EnumerationTypeVariant to EnumerationDataVariant, added EnumerationVariantValue and simple_base_type field |
| xsd-parser/src/models/data/constrains.rs | Changed range bounds from TokenStream to ValueRendererBox |
| xsd-parser/src/models/data/complex.rs | Changed default_value from TokenStream to ValueRendererBox |
| xsd-parser/src/models/meta/custom.rs | Replaced CustomDefaultImpl with ValueGenerator |
| xsd-parser/src/models/meta/type_.rs | Added Str build-in type |
| xsd-parser/src/models/ident.rs | Added STR constant for str type |
| xsd-parser/src/models/naming/default.rs | Added format_constant_name() for SCREAMING_SNAKE_CASE naming |
| xsd-parser/src/models/naming/explicit.rs | Added format_constant_name() implementation |
| xsd-parser/src/traits/naming.rs | Added format_constant_name() and format_constant_ident() to Naming trait |
| xsd-parser/src/pipeline/generator/custom.rs | Added ValueGenerator trait and ValueGeneratorMode enum |
| xsd-parser/src/pipeline/generator/context.rs | Refactored render_literal() to make_value_renderer() with mode support |
| xsd-parser/src/pipeline/generator/data/enumeration.rs | Updated to generate EnumerationVariantValue for advanced enums |
| xsd-parser/src/pipeline/generator/data/constrains.rs | Updated to use make_value_renderer() |
| xsd-parser/src/pipeline/generator/data/complex.rs | Updated to use make_value_renderer() for attribute defaults |
| xsd-parser/src/pipeline/generator/error.rs | Enhanced InvalidDefaultValue error with mode field |
| xsd-parser/src/pipeline/interpreter/mod.rs | Added with_qname_type() support and refactored to use ValueGenerator |
| xsd-parser/src/pipeline/renderer/custom.rs | Added ValueRenderer trait for rendering values in different contexts |
| xsd-parser/src/pipeline/renderer/steps/enum_const.rs | New step to render enum constants based on simple base type |
| xsd-parser/src/pipeline/renderer/steps/defaults.rs | Updated to use ValueRendererBox |
| xsd-parser/src/pipeline/renderer/steps/quick_xml/serialize.rs | Updated enum serialization to use constants for advanced enums |
| xsd-parser/src/pipeline/renderer/steps/quick_xml/deserialize.rs | Updated enum deserialization to support base type deserialization and comparison |
| xsd-parser/src/misc/qname.rs | Added qname_default() function for QName value generation |
| xsd-parser-types/src/xml/qname.rs | Added new_const(), SerializeBytes impl, with_namespace(), and index() getter |
| xsd-parser-types/src/quick_xml/serialize.rs | Added get_namespace_prefix() helper method |
| xsd-parser-types/src/quick_xml/error.rs | Added UnknownNamespace and UnknownNamespacePrefix error kinds |
| xsd-parser/tests/feature/advanced_enums/* | New test demonstrating advanced enum functionality |
| xsd-parser/tests/feature/*/mod.rs | Updated test configs to disable ADVANCED_ENUMS by default |
| xsd-parser/examples/update_schema.rs | Updated max_occurs_default to use new ValueGenerator signature |
| xsd-parser/examples/custom_render_step.rs | Updated to use EnumerationDataVariant |
| Cargo.toml | Added missing_errors_doc to allowed lints |
Comments suppressed due to low confidence (3)
xsd-parser/src/misc/qname.rs:11
- The documentation comment incorrectly references
crate::models::schema::QName, but based on the code, this function actually generates values for thexsd_parser_types::xml::QNametype (as imported on line 3 and used in the code). The doc comment should reference the correct type or use a more generic description.
/// Generates a default value or constant for the [`QName`](crate::models::schema::QName) type
/// from the passed `value` and returns it as a [`TokenStream`].
xsd-parser-types/src/quick_xml/error.rs:129
- The error variant
UnknownNamespacePrefixcontains aNamespacefield but the documentation and error message suggest it should be about a namespace prefix. This is potentially confusing or incorrect. Consider either renaming this variant, changing the field type toNamespacePrefix, or clarifying the documentation to explain why a Namespace is used for an unknown prefix error.
/// Unknown namespace prefix.
///
/// The namespace prefix was expected to be defined, but it was not.
#[error("Unknown namespace prefix: {0}")]
UnknownNamespacePrefix(Namespace),
xsd-parser/src/pipeline/renderer/steps/enum_const.rs:63
- The implementation uses
trim_start_matches('b')to remove the leading 'b' from byte string literals. However, this will remove ALL leading 'b' characters, not just the prefix 'b' before the quote. For example, if the value isb"b", it will incorrectly become""instead of"b". Consider usingstrip_prefix("b")instead, which removes only a single occurrence of the prefix.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9aea886 to
7ccea45
Compare
Advanced enums will define suitable constants for each variant (if possible) which is useful for deserialization and serialization. Instead of matching a byte string literal directly, the base type of the enum is used to for deserialization and is then compared to the constants defined for each variant. This allows for more flexible deserialization because the base type may implement additional checks or transformations on the input data.
7ccea45 to
ae191d9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #217