apif_execution/
workflow.rs1use apif_ast::{Section, SectionType};
2
3pub struct WorkflowSummary {
4 pub total_requests: usize,
5 pub total_responses: usize,
6 pub total_errors: usize,
7 pub total_extractions: usize,
8 pub total_assertions: usize,
9 pub has_streaming: bool,
10}
11pub fn get_workflow_summary(sections: &[Section]) -> WorkflowSummary {
12 WorkflowSummary {
13 total_requests: sections
14 .iter()
15 .filter(|s| s.section_type == SectionType::Request)
16 .count(),
17 total_responses: sections
18 .iter()
19 .filter(|s| s.section_type == SectionType::Response)
20 .count(),
21 total_errors: sections
22 .iter()
23 .filter(|s| s.section_type == SectionType::Error)
24 .count(),
25 total_extractions: sections
26 .iter()
27 .filter(|s| s.section_type == SectionType::Extract)
28 .count(),
29 total_assertions: sections
30 .iter()
31 .filter(|s| s.section_type == SectionType::Asserts)
32 .count(),
33 has_streaming: false,
34 }
35}
36pub fn get_call_type(summary: &WorkflowSummary) -> &'static str {
37 if summary.total_errors > 0 && summary.total_requests == 1 && summary.total_responses == 0 {
38 "Unary Call Expecting Error"
39 } else if summary.total_requests == 1 && summary.total_responses > 1 {
40 "Server Streaming Call"
41 } else if summary.total_requests > 1 && summary.total_responses == 1 {
42 "Client Streaming Call"
43 } else if summary.total_requests > 1 && summary.total_responses > 1 {
44 "Bidirectional Streaming Call"
45 } else if summary.total_requests == 1 && summary.total_responses == 1 {
46 "Standard Unary Call"
47 } else {
48 "Multi-Step Workflow"
49 }
50}