openapi-nexus 0.1.1

OpenAPI 3.x multi-language code generator
Documentation
/// Errors that can occur during API calls.
#[derive(Debug)]
pub enum Error {
    /// Network-level error from reqwest.
    Network(reqwest::Error),
    /// API returned a non-success status code.
    Api {
        status: reqwest::StatusCode,
        body: String,
    },
    /// Failed to deserialize the response body.
    Deserialize(serde_json::Error),
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Error::Network(e) => write!(f, "network error: {e}"),
            Error::Api { status, body } => write!(f, "API error {status}: {body}"),
            Error::Deserialize(e) => write!(f, "deserialization error: {e}"),
        }
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Error::Network(e) => Some(e),
            Error::Deserialize(e) => Some(e),
            Error::Api { .. } => None,
        }
    }
}

impl From<reqwest::Error> for Error {
    fn from(e: reqwest::Error) -> Self {
        Error::Network(e)
    }
}

impl From<serde_json::Error> for Error {
    fn from(e: serde_json::Error) -> Self {
        Error::Deserialize(e)
    }
}