use std::collections::BTreeMap;
#[derive(Debug, Clone)]
pub struct StreamingConfig {
pub endpoints: Vec<StreamingEndpoint>,
pub generate_client: bool,
pub client_module_name: String,
pub event_parser_helpers: bool,
pub reconnection_config: Option<ReconnectionConfig>,
}
impl Default for StreamingConfig {
fn default() -> Self {
Self {
endpoints: Vec::new(),
generate_client: true,
client_module_name: "streaming".to_string(),
event_parser_helpers: true,
reconnection_config: None,
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub enum HttpMethod {
#[default]
Post,
Get,
}
#[derive(Debug, Clone)]
pub struct StreamingEndpoint {
pub operation_id: String,
pub path: String,
pub http_method: HttpMethod,
pub stream_parameter: String,
pub query_parameters: Vec<QueryParameter>,
pub event_union_type: String,
pub content_type: Option<String>,
pub base_url: Option<String>,
pub event_flow: EventFlow,
pub required_headers: Vec<(String, String)>,
pub auth_header: Option<AuthHeader>,
pub optional_headers: Vec<OptionalHeader>,
}
#[derive(Debug, Clone)]
pub struct QueryParameter {
pub name: String,
pub required: bool,
}
impl Default for StreamingEndpoint {
fn default() -> Self {
Self {
operation_id: String::new(),
path: String::new(),
http_method: HttpMethod::default(),
stream_parameter: String::new(),
query_parameters: Vec::new(),
event_union_type: String::new(),
content_type: Some("text/event-stream".to_string()),
base_url: None,
event_flow: EventFlow::Simple,
required_headers: Vec::new(),
auth_header: None,
optional_headers: Vec::new(),
}
}
}
#[derive(Debug, Clone)]
pub enum AuthHeader {
Bearer(String),
ApiKey(String),
}
#[derive(Debug, Clone, Default)]
pub enum EventFlow {
#[default]
Simple,
StartDeltaStop {
start_events: Vec<String>,
delta_events: Vec<String>,
stop_events: Vec<String>,
},
}
#[derive(Debug, Clone)]
pub struct ReconnectionConfig {
pub max_retries: u32,
pub initial_delay_ms: u64,
pub max_delay_ms: u64,
pub backoff_multiplier: f64,
}
impl Default for ReconnectionConfig {
fn default() -> Self {
Self {
max_retries: 3,
initial_delay_ms: 1000,
max_delay_ms: 30000,
backoff_multiplier: 2.0,
}
}
}
#[derive(Debug, Clone)]
pub enum StreamingError {
Connection(String),
Parsing(String),
Authentication(String),
RateLimit(String),
Api(String),
}
impl std::fmt::Display for StreamingError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
StreamingError::Connection(msg) => write!(f, "Connection error: {msg}"),
StreamingError::Parsing(msg) => write!(f, "Parsing error: {msg}"),
StreamingError::Authentication(msg) => write!(f, "Authentication error: {msg}"),
StreamingError::RateLimit(msg) => write!(f, "Rate limit error: {msg}"),
StreamingError::Api(msg) => write!(f, "API error: {msg}"),
}
}
}
impl std::error::Error for StreamingError {}
#[derive(Debug, Clone)]
pub struct OptionalHeader {
pub name: String,
pub description: String,
pub multiple_values: bool,
pub default_value: Option<String>,
pub examples: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct StreamingDetectionConfig {
pub stream_parameter_names: Vec<String>,
pub sse_content_types: Vec<String>,
pub event_type_patterns: Vec<String>,
}
impl Default for StreamingDetectionConfig {
fn default() -> Self {
Self {
stream_parameter_names: vec!["stream".to_string()],
sse_content_types: vec!["text/event-stream".to_string()],
event_type_patterns: vec![
"*Event".to_string(),
"*StreamEvent".to_string(),
"*StreamResponse".to_string(),
],
}
}
}
#[derive(Debug, Clone)]
pub struct DetectedStreamingEndpoint {
pub operation_id: String,
pub stream_parameter: String,
pub event_union_type: Option<String>,
pub content_type: Option<String>,
pub event_types: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct StreamingDetectionResult {
pub endpoints: Vec<DetectedStreamingEndpoint>,
pub event_types: BTreeMap<String, Vec<String>>,
pub potential_event_unions: Vec<String>,
}