Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Commit d295a81

Browse files
committed
Fix AnalysedExport serialization
1 parent a9796cc commit d295a81

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/analysis/model.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::component::{ComponentExternalKind, PrimitiveValueType};
2020

2121
#[derive(Debug, Clone, PartialEq, Hash, Eq)]
2222
#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
23+
#[cfg_attr(feature = "json", serde(tag = "type"))]
2324
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
2425
#[cfg_attr(feature = "poem_openapi", derive(poem_openapi::Union))]
2526
#[cfg_attr(
@@ -522,3 +523,38 @@ impl AnalysisFailure {
522523
}
523524
}
524525
}
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

Comments
 (0)