Skip to main content

openapi_nexus/parser/
error.rs

1//! Parse errors for OpenAPI files
2
3use snafu::Snafu;
4
5/// Parse errors for OpenAPI files
6#[derive(Debug, Snafu)]
7#[snafu(visibility(pub))]
8pub enum ParseError {
9    #[snafu(display("Failed to read file '{}': {}", path, source))]
10    FileRead {
11        path: String,
12        source: std::io::Error,
13    },
14
15    #[snafu(display("Failed to parse JSON: {}", source))]
16    JsonParse {
17        source: serde_json::Error,
18        context: Vec<String>,
19    },
20
21    #[snafu(display("Failed to parse YAML: {}", source))]
22    YamlParse {
23        source: serde_norway::Error,
24        context: Vec<String>,
25    },
26
27    #[snafu(display("Unsupported file format: {}", format))]
28    UnsupportedFormat { format: String },
29
30    #[snafu(display("Failed to deserialize OpenAPI schema from JSON: {}", source))]
31    OpenApiDeserializeJson { source: serde_json::Error },
32
33    #[snafu(display("Failed to deserialize OpenAPI schema from YAML: {}", source))]
34    OpenApiDeserializeYaml { source: serde_norway::Error },
35
36    #[snafu(display(
37        "Unsupported OpenAPI version: '{}'. Supported versions: 3.0.x, 3.1.x, 3.2.x",
38        version
39    ))]
40    UnsupportedVersion { version: String },
41
42    #[snafu(display("Missing 'openapi' version field in specification"))]
43    MissingVersionField,
44}