Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions xsd-parser/src/pipeline/renderer/steps/quick_xml/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3137,9 +3137,18 @@ impl ComplexDataElement<'_> {
Occurs::Optional => quote!(Ok(super::#type_ident::#variant_ident(None))),
Occurs::DynamicList => {
let min = self.meta().min_occurs;

quote! {
Ok(super::#type_ident::#variant_ident(helper.finish_vec_default(#min, Vec::new())?))
// finish_vec_default() requires the deserializer to implement Default.
// BUT, if min is 0, then it doesn't need to have a default value -- the
// underlying type doesn't need to be defaultable if a Vec of it is allowed
// to be empty
if min == 0 {
quote! {
Ok(super::#type_ident::#variant_ident(Vec::new()))
}
} else {
quote! {
Ok(super::#type_ident::#variant_ident(helper.finish_vec_default(#min, Vec::new())?))
}
}
}
Occurs::StaticList(sz) => {
Expand Down Expand Up @@ -4276,6 +4285,9 @@ impl DefaultableCache {
}

fn is_defaultable_element(&mut self, types: &MetaTypes, el: &ElementMeta) -> bool {
if el.min_occurs == 0 {
return true;
}
if let ElementMetaVariant::Type {
type_,
mode: ElementMode::Group,
Expand Down Expand Up @@ -4344,16 +4356,8 @@ impl DefaultableCache {
defaultable
}
Some(MetaTypeVariant::Choice(x)) => {
let defaultable = x.elements.len() == 1
&& x.elements[0].min_occurs >= 1
&& matches!(
&x.elements[0].variant,
ElementMetaVariant::Type {
mode: ElementMode::Group,
..
}
);

let defaultable =
x.elements.len() == 1 && self.is_defaultable_element(types, &x.elements[0]);
if defaultable {
Defaultable::Complete
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<foo:bar
xmlns:foo="http://example.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.com ../schema.xsd"
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<foo:foo
xmlns:foo="http://example.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.com ../schema.xsd"
>
<foo:info>test 1</foo:info>
<foo:info>test 2</foo:info>
</foo:foo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pub type Foo = FooType;
#[derive(Debug)]
pub struct FooType {
pub content: FooTypeContent,
}
#[derive(Debug)]
pub enum FooTypeContent {
Content2(Vec<FooContent2Type>),
}
#[derive(Debug)]
pub struct FooContent2Type {
pub info: String,
}
pub type Bar = BarType;
#[derive(Debug)]
pub struct BarType {
pub content: BarTypeContent,
}
#[derive(Debug)]
pub enum BarTypeContent {
Content4(Vec<BarContent4Type>),
}
#[derive(Debug)]
pub struct BarContent4Type {
pub info: String,
}
Loading
Loading