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 Api(String),
159}
160
161impl std::fmt::Display for StreamingError {
162 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
163 match self {
164 StreamingError::Connection(msg) => write!(f, "Connection error: {msg}"),
165 StreamingError::Parsing(msg) => write!(f, "Parsing error: {msg}"),
166 StreamingError::Authentication(msg) => write!(f, "Authentication error: {msg}"),
167 StreamingError::RateLimit(msg) => write!(f, "Rate limit error: {msg}"),
168 StreamingError::Api(msg) => write!(f, "API error: {msg}"),
169 }
170 }
171}
172
173impl std::error::Error for StreamingError {}
174
175#[derive(Debug, Clone)]
177pub struct OptionalHeader {
178 pub name: String,
180 pub description: String,
182 pub multiple_values: bool,
184 pub default_value: Option<String>,
186 pub examples: Vec<String>,
188}
189
190#[derive(Debug, Clone)]
192pub struct StreamingDetectionConfig {
193 pub stream_parameter_names: Vec<String>,
195 pub sse_content_types: Vec<String>,
197 pub event_type_patterns: Vec<String>,
199}
200
201impl Default for StreamingDetectionConfig {
202 fn default() -> Self {
203 Self {
204 stream_parameter_names: vec!["stream".to_string()],
205 sse_content_types: vec!["text/event-stream".to_string()],
206 event_type_patterns: vec![
207 "*Event".to_string(),
208 "*StreamEvent".to_string(),
209 "*StreamResponse".to_string(),
210 ],
211 }
212 }
213}
214
215#[derive(Debug, Clone)]
217pub struct DetectedStreamingEndpoint {
218 pub operation_id: String,
220 pub stream_parameter: String,
222 pub event_union_type: Option<String>,
224 pub content_type: Option<String>,
226 pub event_types: Vec<String>,
228}
229
230#[derive(Debug, Clone)]
232pub struct StreamingDetectionResult {
233 pub endpoints: Vec<DetectedStreamingEndpoint>,
235 pub event_types: BTreeMap<String, Vec<String>>,
237 pub potential_event_unions: Vec<String>,
239}