diff --git a/xml_schema_derive/src/xsd/complex_type.rs b/xml_schema_derive/src/xsd/complex_type.rs index d531559..095a257 100644 --- a/xml_schema_derive/src/xsd/complex_type.rs +++ b/xml_schema_derive/src/xsd/complex_type.rs @@ -58,7 +58,7 @@ impl Implementation for ComplexType { let complex_content_type = complex_content.get_field_implementation(context, prefix); quote!( #[yaserde(flatten)] - #complex_content_type, + #complex_content_type ) }) .unwrap_or_default(); diff --git a/xml_schema_derive/src/xsd/extension.rs b/xml_schema_derive/src/xsd/extension.rs index 7a3c5b8..d71ab18 100644 --- a/xml_schema_derive/src/xsd/extension.rs +++ b/xml_schema_derive/src/xsd/extension.rs @@ -42,10 +42,17 @@ impl Implementation for Extension { TokenStream::new() }; + let sequences: TokenStream = self + .sequences + .iter() + .map(|sequence| sequence.implement(namespace_definition, prefix, context)) + .collect(); + quote!( #inner_attribute pub base: #rust_type, #attributes + #sequences ) } } @@ -65,16 +72,22 @@ impl Extension { let group_type = group.get_type_implementation(context, prefix); quote!( - , #[serde(flatten)] - pub extension : #group_type + pub extension : #group_type, ) }) .unwrap_or_default(); + let sequences: TokenStream = self + .sequences + .iter() + .map(|sequence| sequence.get_field_implementation(context, prefix)) + .collect(); + quote!( - pub base : #rust_type + pub base : #rust_type, #group_content + #sequences ) } } @@ -156,4 +169,102 @@ mod tests { assert_eq!(implementation.to_string(), expected.to_string()); } + + #[test] + fn extension_with_sequences() { + use crate::xsd::complex_content::ComplexContent; + use crate::xsd::complex_type::ComplexType; + use crate::xsd::element::Element; + + /* + + + + + + + + + + + + */ + + let extension = Extension { + base: "personinfo".to_string(), + attributes: vec![], + sequences: vec![Sequence { + elements: vec![ + Element { + name: "address".to_string(), + kind: Some("xs:string".to_string()), + refers: None, + min_occurences: None, + max_occurences: None, + complex_type: None, + simple_type: None, + annotation: None, + }, + Element { + name: "city".to_string(), + kind: Some("xs:string".to_string()), + refers: None, + min_occurences: None, + max_occurences: None, + complex_type: None, + simple_type: None, + annotation: None, + }, + Element { + name: "country".to_string(), + kind: Some("xs:string".to_string()), + refers: None, + min_occurences: None, + max_occurences: None, + complex_type: None, + simple_type: None, + annotation: None, + }, + ], + }], + group: None, + }; + + let st = ComplexType { + name: "fullpersoninfo".to_string(), + annotation: None, + attributes: vec![], + sequence: None, + simple_content: None, + complex_content: Some(ComplexContent { + extension: Some(extension), + }), + }; + + let context = + XsdContext::new(r#""#) + .unwrap(); + + //let implementation = extension.implement(&TokenStream::new(), &None, &context); + let implementation = st.implement(&TokenStream::new(), &None, &context); + + let expected = TokenStream::from_str( + " + # [derive (Clone , Debug , Default , PartialEq , yaserde_derive :: YaDeserialize , yaserde_derive :: YaSerialize)] + pub struct Fullpersoninfo { + # [yaserde (flatten)] + pub base : Personinfo , + # [yaserde (rename = \"address\")] + pub address : String , + # [yaserde (rename = \"city\")] + pub city : String , + # [yaserde (rename = \"country\")] + pub country : String , + } + ", + ) + .unwrap(); + + assert_eq!(implementation.to_string(), expected.to_string()); + } }