use thiserror::Error;
pub type OpenApiResult<T> = Result<T, OpenApiError>;
#[derive(Debug, Error)]
pub enum OpenApiError {
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("YAML error: {0}")]
Yaml(#[from] serde_yaml::Error),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("Schema generation error: {0}")]
Schema(String),
#[error("Route discovery error: {0}")]
RouteDiscovery(String),
#[error("Configuration error: {0}")]
Config(String),
#[error("Export format error: {0}")]
Export(String),
#[error("Validation error: {0}")]
Validation(String),
#[error("OpenAPI error: {0}")]
Generic(String),
}
impl OpenApiError {
pub fn schema_error<T: ToString>(msg: T) -> Self {
Self::Schema(msg.to_string())
}
pub fn route_discovery_error<T: ToString>(msg: T) -> Self {
Self::RouteDiscovery(msg.to_string())
}
pub fn config_error<T: ToString>(msg: T) -> Self {
Self::Config(msg.to_string())
}
pub fn export_error<T: ToString>(msg: T) -> Self {
Self::Export(msg.to_string())
}
pub fn validation_error<T: ToString>(msg: T) -> Self {
Self::Validation(msg.to_string())
}
pub fn generic<T: ToString>(msg: T) -> Self {
Self::Generic(msg.to_string())
}
}