Skip to content
Open
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
2 changes: 1 addition & 1 deletion xml_schema_derive/src/xsd/complex_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
117 changes: 114 additions & 3 deletions xml_schema_derive/src/xsd/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
Expand All @@ -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
)
}
}
Expand Down Expand Up @@ -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;

/*
<xs:complexType name="fullpersoninfo">
<xs:complexContent>
<xs:extension base="personinfo">
<xs:sequence>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
*/

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#"<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"></xs:schema>"#)
.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());
}
}