File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -21,3 +21,46 @@ pub struct SchemaObject {
2121 #[ serde( skip_serializing_if = "Option::is_none" ) ]
2222 pub example : Option < serde_json:: Value > ,
2323}
24+
25+ #[ cfg( test) ]
26+ mod tests {
27+ use crate :: openapi:: ExternalDocumentation ;
28+
29+ use super :: SchemaObject ;
30+ use schemars:: Schema ;
31+ use serde_json:: json;
32+
33+ #[ test]
34+ fn test_serialize_ref_schema ( ) {
35+ let serialized = serde_json:: to_value ( SchemaObject {
36+ json_schema : Schema :: new_ref ( "test" . to_owned ( ) ) ,
37+ external_docs : None ,
38+ example : None ,
39+ } )
40+ . unwrap ( ) ;
41+
42+ assert_eq ! ( serialized, json!( { "$ref" : "test" } ) ) ;
43+ }
44+
45+ #[ test]
46+ fn test_serialize_ref_schema_with_external_docs ( ) {
47+ let serialized = serde_json:: to_value ( SchemaObject {
48+ json_schema : Schema :: new_ref ( "test" . to_owned ( ) ) ,
49+ external_docs : Some ( ExternalDocumentation {
50+ description : None ,
51+ url : "http://example.org" . to_owned ( ) ,
52+ extensions : Default :: default ( ) ,
53+ } ) ,
54+ example : None ,
55+ } )
56+ . unwrap ( ) ;
57+
58+ assert_eq ! (
59+ serialized,
60+ json!( {
61+ "$ref" : "test" ,
62+ "externalDocs" : { "url" : "http://example.org" } ,
63+ } )
64+ ) ;
65+ }
66+ }
You can’t perform that action at this time.
0 commit comments