Skip to content

Commit

Permalink
Fix option type path
Browse files Browse the repository at this point in the history
  • Loading branch information
matzipan committed Jan 3, 2024
1 parent 3cfb3c2 commit 5495f12
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions xml_schema_derive/src/xsd/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,6 @@ impl Element {
rust_type
};

let rust_type = if optional || (!multiple && self.min_occurences == Some(0)) {
quote!(Option<#rust_type>)
} else {
rust_type
};

let prefix_attribute = prefix
.as_ref()
.map(|prefix| quote!(, prefix=#prefix))
.unwrap_or_default();

let module = (!context.is_in_sub_module()
&& !self
.kind
Expand All @@ -170,9 +159,22 @@ impl Element {
.then_some(quote!(xml_schema_types::))
.unwrap_or_default();

let rust_type = quote!(#module#rust_type);

let rust_type = if optional || (!multiple && self.min_occurences == Some(0)) {
quote!(Option<#rust_type>)
} else {
rust_type
};

let prefix_attribute = prefix
.as_ref()
.map(|prefix| quote!(, prefix=#prefix))
.unwrap_or_default();

quote! {
#[yaserde(rename=#yaserde_rename #prefix_attribute)]
pub #attribute_name: #module#rust_type,
pub #attribute_name: #rust_type,
}
}
}
Expand Down

0 comments on commit 5495f12

Please sign in to comment.