1
1
use crate :: xsd:: {
2
2
annotation:: Annotation , complex_type:: ComplexType , max_occurences:: MaxOccurences ,
3
- rust_types_mapping:: RustTypesMapping , Implementation , XsdContext ,
3
+ rust_types_mapping:: RustTypesMapping , simple_type :: SimpleType , Implementation , XsdContext ,
4
4
} ;
5
5
use heck:: { CamelCase , SnakeCase } ;
6
6
use log:: { debug, info} ;
@@ -23,7 +23,9 @@ pub struct Element {
23
23
#[ yaserde( rename = "maxOccurs" , attribute) ]
24
24
pub max_occurences : Option < MaxOccurences > ,
25
25
#[ yaserde( rename = "complexType" ) ]
26
- pub complex_type : Vec < ComplexType > ,
26
+ pub complex_type : Option < ComplexType > ,
27
+ #[ yaserde( rename = "simpleType" ) ]
28
+ pub simple_type : Option < SimpleType > ,
27
29
#[ yaserde( rename = "annotation" ) ]
28
30
pub annotation : Option < Annotation > ,
29
31
}
@@ -40,7 +42,7 @@ impl Implementation for Element {
40
42
Span :: call_site ( ) ,
41
43
) ;
42
44
43
- let fields = if let Some ( kind) = & self . kind {
45
+ let ( fields, extra_structs ) = if let Some ( kind) = & self . kind {
44
46
let subtype_mode = if RustTypesMapping :: is_xs_string ( context, kind) {
45
47
quote ! ( text)
46
48
} else {
@@ -49,16 +51,21 @@ impl Implementation for Element {
49
51
50
52
let extern_type = RustTypesMapping :: get ( context, kind) ;
51
53
52
- quote ! (
53
- #[ yaserde( #subtype_mode) ]
54
- pub content: #extern_type,
54
+ (
55
+ quote ! (
56
+ #[ yaserde( #subtype_mode) ]
57
+ pub content: #extern_type,
58
+ ) ,
59
+ quote ! ( ) ,
55
60
)
56
61
} else {
57
- self
62
+ let fields_definition = self
58
63
. complex_type
59
64
. iter ( )
60
- . map ( |complex_type| complex_type. get_field_implementation ( prefix, context) )
61
- . collect ( )
65
+ . map ( |complex_type| complex_type. get_field_implementation ( context, prefix) )
66
+ . collect ( ) ;
67
+
68
+ ( fields_definition, quote ! ( ) )
62
69
} ;
63
70
64
71
let docs = self
@@ -74,6 +81,8 @@ impl Implementation for Element {
74
81
pub struct #struct_name {
75
82
#fields
76
83
}
84
+
85
+ #extra_structs
77
86
}
78
87
}
79
88
}
@@ -85,7 +94,7 @@ impl Element {
85
94
prefix : & Option < String > ,
86
95
context : & XsdContext ,
87
96
) -> TokenStream {
88
- if self . complex_type . is_empty ( ) {
97
+ if self . complex_type . is_none ( ) {
89
98
return quote ! ( ) ;
90
99
}
91
100
@@ -115,8 +124,10 @@ impl Element {
115
124
let attribute_name = Ident :: new ( & name, Span :: call_site ( ) ) ;
116
125
let yaserde_rename = & self . name ;
117
126
118
- let rust_type = if let Some ( complex_type) = self . complex_type . first ( ) {
127
+ let rust_type = if let Some ( complex_type) = & self . complex_type {
119
128
complex_type. get_integrated_implementation ( & self . name )
129
+ } else if let Some ( simple_type) = & self . simple_type {
130
+ simple_type. get_type_implementation ( context, & Some ( self . name . to_owned ( ) ) )
120
131
} else if let Some ( kind) = & self . kind {
121
132
RustTypesMapping :: get ( context, kind)
122
133
} else {
@@ -168,7 +179,8 @@ mod tests {
168
179
refers : None ,
169
180
min_occurences : None ,
170
181
max_occurences : None ,
171
- complex_type : vec ! [ ] ,
182
+ complex_type : None ,
183
+ simple_type : None ,
172
184
annotation : Some ( Annotation {
173
185
id : None ,
174
186
attributes : vec ! [ ] ,
@@ -199,7 +211,8 @@ mod tests {
199
211
refers : None ,
200
212
min_occurences : None ,
201
213
max_occurences : None ,
202
- complex_type : vec ! [ ] ,
214
+ complex_type : None ,
215
+ simple_type : None ,
203
216
annotation : Some ( Annotation {
204
217
id : None ,
205
218
attributes : vec ! [ ] ,
0 commit comments