1use thiserror::Error;
2
3pub type OpenApiResult<T> = Result<T, OpenApiError>;
5
6#[derive(Debug, Error)]
8pub enum OpenApiError {
9 #[error("JSON error: {0}")]
11 Json(#[from] serde_json::Error),
12
13 #[error("YAML error: {0}")]
15 Yaml(#[from] serde_yaml::Error),
16
17 #[error("I/O error: {0}")]
19 Io(#[from] std::io::Error),
20
21 #[error("HTTP error: {0}")]
23 Http(#[from] reqwest::Error),
24
25 #[error("Schema generation error: {0}")]
27 Schema(String),
28
29 #[error("Route discovery error: {0}")]
31 RouteDiscovery(String),
32
33 #[error("Configuration error: {0}")]
35 Config(String),
36
37 #[error("Export format error: {0}")]
39 Export(String),
40
41 #[error("Validation error: {0}")]
43 Validation(String),
44
45 #[error("OpenAPI error: {0}")]
47 Generic(String),
48}
49
50impl OpenApiError {
51 pub fn schema_error<T: ToString>(msg: T) -> Self {
53 Self::Schema(msg.to_string())
54 }
55
56 pub fn route_discovery_error<T: ToString>(msg: T) -> Self {
58 Self::RouteDiscovery(msg.to_string())
59 }
60
61 pub fn config_error<T: ToString>(msg: T) -> Self {
63 Self::Config(msg.to_string())
64 }
65
66 pub fn export_error<T: ToString>(msg: T) -> Self {
68 Self::Export(msg.to_string())
69 }
70
71 pub fn validation_error<T: ToString>(msg: T) -> Self {
73 Self::Validation(msg.to_string())
74 }
75
76 pub fn generic<T: ToString>(msg: T) -> Self {
78 Self::Generic(msg.to_string())
79 }
80}