1use std::collections::BTreeMap;
2
3#[derive(Debug, Clone)]
5pub struct StreamingConfig {
6 pub endpoints: Vec<StreamingEndpoint>,
8 pub generate_client: bool,
10 pub client_module_name: String,
12 pub event_parser_helpers: bool,
14 pub reconnection_config: Option<ReconnectionConfig>,
16}
17
18impl Default for StreamingConfig {
19 fn default() -> Self {
20 Self {
21 endpoints: Vec::new(),
22 generate_client: true,
23 client_module_name: "streaming".to_string(),
24 event_parser_helpers: true,
25 reconnection_config: None,
26 }
27 }
28}
29
30#[derive(Debug, Clone, Default, PartialEq, Eq)]
32pub enum HttpMethod {
33 #[default]
34 Post,
35 Get,
36}
37
38#[derive(Debug, Clone)]
40pub struct StreamingEndpoint {
41 pub operation_id: String,
43 pub path: String,
45 pub http_method: HttpMethod,
47 pub stream_parameter: String,
50 pub query_parameters: Vec<QueryParameter>,
52 pub event_union_type: String,
54 pub content_type: Option<String>,
56 pub base_url: Option<String>,
58 pub event_flow: EventFlow,
60 pub required_headers: Vec<(String, String)>,
62 pub auth_header: Option<AuthHeader>,
64 pub optional_headers: Vec<OptionalHeader>,
66}
67
68#[derive(Debug, Clone)]
70pub struct QueryParameter {
71 pub name: String,
73 pub required: bool,
75}
76
77impl Default for StreamingEndpoint {
78 fn default() -> Self {
79 Self {
80 operation_id: String::new(),
81 path: String::new(),
82 http_method: HttpMethod::default(),
83 stream_parameter: String::new(),
84 query_parameters: Vec::new(),
85 event_union_type: String::new(),
86 content_type: Some("text/event-stream".to_string()),
87 base_url: None,
88 event_flow: EventFlow::Simple,
89 required_headers: Vec::new(),
90 auth_header: None,
91 optional_headers: Vec::new(),
92 }
93 }
94}
95
96#[derive(Debug, Clone)]
98pub enum AuthHeader {
99 Bearer(String),
101 ApiKey(String),
103}
104
105#[derive(Debug, Clone, Default)]
107pub enum EventFlow {
108 #[default]
110 Simple,
111 StartDeltaStop {
113 start_events: Vec<String>,
115 delta_events: Vec<String>,
117 stop_events: Vec<String>,
119 },
120}
121
122#[derive(Debug, Clone)]
124pub struct ReconnectionConfig {
125 pub max_retries: u32,
127 pub initial_delay_ms: u64,
129 pub max_delay_ms: u64,
131 pub backoff_multiplier: f64,
133}
134
135impl Default for ReconnectionConfig {
136 fn default() -> Self {
137 Self {
138 max_retries: 3,
139 initial_delay_ms: 1000,
140 max_delay_ms: 30000,
141 backoff_multiplier: 2.0,
142 }
143 }
144}
145
146#[derive(Debug, Clone)]
148pub enum StreamingError {
149 Connection(String),
151 Parsing(String),
153 Authentication(String),
155 RateLimit(String),
157 ResponseTooLarge { limit: usize },
159 Api(String),
161}
162
163impl std::fmt::Display for StreamingError {
164 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
165 match self {
166 StreamingError::Connection(msg) => write!(f, "Connection error: {msg}"),
167 StreamingError::Parsing(msg) => write!(f, "Parsing error: {msg}"),
168 StreamingError::Authentication(msg) => write!(f, "Authentication error: {msg}"),
169 StreamingError::RateLimit(msg) => write!(f, "Rate limit error: {msg}"),
170 StreamingError::ResponseTooLarge { limit } => {
171 write!(
172 f,
173 "Response body exceeded configured limit of {limit} bytes"
174 )
175 }
176 StreamingError::Api(msg) => write!(f, "API error: {msg}"),
177 }
178 }
179}
180
181impl std::error::Error for StreamingError {}
182
183#[derive(Debug, Clone)]
185pub struct OptionalHeader {
186 pub name: String,
188 pub description: String,
190 pub multiple_values: bool,
192 pub default_value: Option<String>,
194 pub examples: Vec<String>,
196}
197
198#[derive(Debug, Clone)]
200pub struct StreamingDetectionConfig {
201 pub stream_parameter_names: Vec<String>,
203 pub sse_content_types: Vec<String>,
205 pub event_type_patterns: Vec<String>,
207}
208
209impl Default for StreamingDetectionConfig {
210 fn default() -> Self {
211 Self {
212 stream_parameter_names: vec!["stream".to_string()],
213 sse_content_types: vec!["text/event-stream".to_string()],
214 event_type_patterns: vec![
215 "*Event".to_string(),
216 "*StreamEvent".to_string(),
217 "*StreamResponse".to_string(),
218 ],
219 }
220 }
221}
222
223#[derive(Debug, Clone)]
225pub struct DetectedStreamingEndpoint {
226 pub operation_id: String,
228 pub stream_parameter: String,
230 pub event_union_type: Option<String>,
232 pub content_type: Option<String>,
234 pub event_types: Vec<String>,
236}
237
238#[derive(Debug, Clone)]
240pub struct StreamingDetectionResult {
241 pub endpoints: Vec<DetectedStreamingEndpoint>,
243 pub event_types: BTreeMap<String, Vec<String>>,
245 pub potential_event_unions: Vec<String>,
247}