Fix: xs:element default value ignored for simpleContent extension types - #285
Fix: xs:element default value ignored for simpleContent extension types#285Bergmann89 with Copilot wants to merge 3 commits into
Conversation
Thread `default` attribute from xs:element through meta-model, generator, and renderer to produce `default_content()` and use it in the generated deserializer for `Event::Empty` (self-closing element with no text content). Changes: - ComplexMeta: add `default: Option<String>` field - Interpreter: propagate xs:element `default` to inline ComplexMeta - Generator: pass default through to ComplexDataContent as ValueRendererBox - Renderer (defaults.rs): render `default_content()` method - Renderer (deserialize.rs): intercept Event::Empty and use default_content() - New feature test for xs:boolean + simpleContent default - Update ONIX expected output (also has an element with default)
|
@copilot Check the latest comment in the issue. There is still an edge case, that does not work correctly. |
Fixed in commit The fix introduces a Both forms now work:
|
When an
xs:elementcarriesdefault="false"and wraps an inline complex type withxs:simpleContent(e.g. extendingxs:boolean), a self-closing element like<Bar Baz="xxxx"/>fails deserialization withUnknownOrInvalidValue("")— the default is never applied.Root cause:
Event::Empty(self-closing XML element) was passed directly toContentDeserializer::init, which tried to parse an empty byte slice as a boolean. Thedefaultattribute fromxs:elementwas never threaded through the pipeline to the generated deserializer.Changes
ComplexMeta(models/meta/complex.rs): Adddefault: Option<String>field; include inTypeEqso types with different defaults remain distinct.pipeline/interpreter/state/generate_types/variant_processor.rs): Propagatexs:element.default→ComplexMeta.defaultwhen building inline complex types.pipeline/generator/data/complex.rs): Convert the default string to aValueRendererBox; store it inComplexDataContent.default_value. Thread adefault: Option<&str>parameter throughnew(),new_simple(), and all call sites.ComplexDataContent(models/data/complex.rs): Adddefault_value: Option<ValueRendererBox>field.pipeline/renderer/steps/defaults.rs): Emit apub fn default_content() -> T { … }associated function whendefault_valueis set.pipeline/renderer/steps/quick_xml/deserialize.rs): Inrender_deserializer_fn_next_content_simple, interceptEvent::Emptybefore callingContentDeserializer— if a default exists, calldefault_content()and return immediately.Generated output example