@@ -7,18 +7,43 @@ use std::collections::HashMap;
77#[ serde( rename_all = "camelCase" ) ]
88#[ serde( deny_unknown_fields) ]
99pub struct Schema {
10+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1011 pub definitions : Option < HashMap < String , Schema > > ,
12+
13+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1114 pub nullable : Option < bool > ,
15+
16+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1217 pub ref_ : Option < String > ,
18+
19+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1320 pub type_ : Option < String > ,
21+
22+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1423 pub enum_ : Option < Vec < String > > ,
24+
25+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1526 pub elements : Option < Box < Schema > > ,
27+
28+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1629 pub properties : Option < HashMap < String , Schema > > ,
30+
31+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1732 pub optional_properties : Option < HashMap < String , Schema > > ,
33+
34+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1835 pub additional_properties : Option < bool > ,
36+
37+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
1938 pub values : Option < Box < Schema > > ,
39+
40+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
2041 pub discriminator : Option < String > ,
42+
43+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
2144 pub mapping : Option < HashMap < String , Schema > > ,
45+
46+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
2247 pub metadata : Option < HashMap < String , Value > > ,
2348}
2449
@@ -174,6 +199,19 @@ impl From<schema::Schema> for Schema {
174199mod tests {
175200 use serde_json:: json;
176201
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+
177215 #[ test]
178216 fn parse_empty ( ) {
179217 assert_eq ! (
0 commit comments