diff --git a/xml_schema/tests/dmarc_rua.rs b/xml_schema/tests/dmarc_rua.rs new file mode 100644 index 0000000..718f136 --- /dev/null +++ b/xml_schema/tests/dmarc_rua.rs @@ -0,0 +1,60 @@ +use xml_schema_derive::XmlSchema; +use yaserde::de::from_str; + +#[test] +fn dmarc_rua_string() { + #[derive(Debug, XmlSchema)] + #[xml_schema(source = "xml_schema/tests/dmarc_rua.xsd", target_prefix = "dmarc")] + struct DmarcRuaSchema; + + let xml_1 = r#" + + + google.com + noreply-dmarc-support@google.com + https://support.google.com/a/answer/2466580 + 5717107811868587391 + + 1706832000 + 1706918399 + + + + example.com + r + r +

none

+ none + 100 + none +
+ + + 185.70.43.17 + 1 + + none + pass + pass + + + + example.com + + + + example.com + pass + protonmail2 + + + example.com + pass + + + +
+ "#; + + let _: Feedback = from_str(xml_1).unwrap(); +} diff --git a/xml_schema/tests/dmarc_rua.xsd b/xml_schema/tests/dmarc_rua.xsd new file mode 100644 index 0000000..17b1b64 --- /dev/null +++ b/xml_schema/tests/dmarc_rua.xsd @@ -0,0 +1,244 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xml_schema_derive/src/xsd/element.rs b/xml_schema_derive/src/xsd/element.rs index efee534..c8dd087 100644 --- a/xml_schema_derive/src/xsd/element.rs +++ b/xml_schema_derive/src/xsd/element.rs @@ -140,23 +140,6 @@ impl Element { ); }; - let rust_type = if multiple { - quote!(Vec<#rust_type>) - } else { - rust_type - }; - - let rust_type = if !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 @@ -169,9 +152,22 @@ impl Element { .then_some(quote!(xml_schema_types::)) .unwrap_or_default(); + let rust_type = if multiple { + quote!(Vec<#module#rust_type>) + } else if self.min_occurences == Some(0) { + quote!(Option<#module#rust_type>) + } else { + quote!(#module#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, } } }