Skip to content

Implement support for advanced enum deserialization#240

Merged
Bergmann89 merged 3 commits intomasterfrom
issue-217
Feb 20, 2026
Merged

Implement support for advanced enum deserialization#240
Bergmann89 merged 3 commits intomasterfrom
issue-217

Conversation

@Bergmann89
Copy link
Owner

Related to #217

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.
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 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 ValueGenerator and ValueRenderer trait system to enable flexible code generation for default values and enum constants with different modes (Literal, Constant, Value)
  • Added ADVANCED_ENUMS generator flag and EnumConstantsRenderStep to 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 the xsd_parser_types::xml::QName type (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 UnknownNamespacePrefix contains a Namespace field 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 to NamespacePrefix, 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 is b"b", it will incorrectly become "" instead of "b". Consider using strip_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.

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.
@Bergmann89 Bergmann89 merged commit 846774a into master Feb 20, 2026
2 checks passed
@Bergmann89 Bergmann89 deleted the issue-217 branch February 20, 2026 11:44
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.

2 participants