@@ -20,6 +20,7 @@ use crate::component::{ComponentExternalKind, PrimitiveValueType};
20
20
21
21
#[ derive( Debug , Clone , PartialEq , Hash , Eq ) ]
22
22
#[ cfg_attr( feature = "json" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
23
+ #[ cfg_attr( feature = "json" , serde( tag = "type" ) ) ]
23
24
#[ cfg_attr( feature = "bincode" , derive( bincode:: Encode , bincode:: Decode ) ) ]
24
25
#[ cfg_attr( feature = "poem_openapi" , derive( poem_openapi:: Union ) ) ]
25
26
#[ cfg_attr(
@@ -522,3 +523,38 @@ impl AnalysisFailure {
522
523
}
523
524
}
524
525
}
526
+
527
+ #[ cfg( test) ]
528
+ mod tests {
529
+ use crate :: analysis:: analysed_type:: { bool, list, str} ;
530
+ use crate :: analysis:: {
531
+ AnalysedExport , AnalysedFunction , AnalysedFunctionParameter , AnalysedFunctionResult ,
532
+ AnalysedInstance ,
533
+ } ;
534
+ use poem_openapi:: types:: ToJSON ;
535
+ use pretty_assertions:: assert_eq;
536
+
537
+ #[ cfg( feature = "poem_openapi" ) ]
538
+ #[ cfg( feature = "json" ) ]
539
+ #[ test]
540
+ fn analysed_export_poem_and_serde_are_compatible ( ) {
541
+ let export1 = AnalysedExport :: Instance ( AnalysedInstance {
542
+ name : "inst1" . to_string ( ) ,
543
+ functions : vec ! [ AnalysedFunction {
544
+ name: "func1" . to_string( ) ,
545
+ parameters: vec![ AnalysedFunctionParameter {
546
+ name: "param1" . to_string( ) ,
547
+ typ: bool ( ) ,
548
+ } ] ,
549
+ results: vec![ AnalysedFunctionResult {
550
+ name: None ,
551
+ typ: list( str ( ) ) ,
552
+ } ] ,
553
+ } ] ,
554
+ } ) ;
555
+ let poem_serialized = export1. to_json_string ( ) ;
556
+ let serde_deserialized: AnalysedExport = serde_json:: from_str ( & poem_serialized) . unwrap ( ) ;
557
+
558
+ assert_eq ! ( export1, serde_deserialized) ;
559
+ }
560
+ }
0 commit comments