@@ -7,18 +7,43 @@ use std::collections::HashMap;
7
7
#[ serde( rename_all = "camelCase" ) ]
8
8
#[ serde( deny_unknown_fields) ]
9
9
pub struct Schema {
10
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
10
11
pub definitions : Option < HashMap < String , Schema > > ,
12
+
13
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
11
14
pub nullable : Option < bool > ,
15
+
16
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
12
17
pub ref_ : Option < String > ,
18
+
19
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
13
20
pub type_ : Option < String > ,
21
+
22
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
14
23
pub enum_ : Option < Vec < String > > ,
24
+
25
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
15
26
pub elements : Option < Box < Schema > > ,
27
+
28
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
16
29
pub properties : Option < HashMap < String , Schema > > ,
30
+
31
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
17
32
pub optional_properties : Option < HashMap < String , Schema > > ,
33
+
34
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
18
35
pub additional_properties : Option < bool > ,
36
+
37
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
19
38
pub values : Option < Box < Schema > > ,
39
+
40
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
20
41
pub discriminator : Option < String > ,
42
+
43
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
21
44
pub mapping : Option < HashMap < String , Schema > > ,
45
+
46
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
22
47
pub metadata : Option < HashMap < String , Value > > ,
23
48
}
24
49
@@ -174,6 +199,19 @@ impl From<schema::Schema> for Schema {
174
199
mod tests {
175
200
use serde_json:: json;
176
201
202
+ #[ test]
203
+ fn serialize_partial ( ) {
204
+ // Fields are None by default. These shouldn't be serialized.
205
+ assert_eq ! (
206
+ "{\" ref\" :\" foo\" }" ,
207
+ serde_json:: to_string( & super :: Schema {
208
+ ref_: Some ( "foo" . to_owned( ) ) ,
209
+ ..Default :: default ( )
210
+ } )
211
+ . unwrap( )
212
+ ) ;
213
+ }
214
+
177
215
#[ test]
178
216
fn parse_empty ( ) {
179
217
assert_eq ! (
0 commit comments