1use std::path::PathBuf;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum Error {
6 #[error("IO error: {0}")]
7 Io(#[from] std::io::Error),
8
9 #[error("YAML parsing error: {0}")]
10 Yaml(#[from] serde_yaml::Error),
11
12 #[error("JSON parsing error: {0}")]
13 Json(#[from] serde_json::Error),
14
15 #[error("TOML parsing error: {0}")]
16 Toml(#[from] toml::de::Error),
17
18 #[error("Syntactic parsing error in file {file:?}: {source}")]
19 Parse { file: PathBuf, source: syn::Error },
20
21 #[error(
22 "Validation failed: No Root OpenAPI definition found. One definition must contain 'openapi' and 'info' fields."
23 )]
24 NoRootFound,
25
26 #[error(
27 "Validation failed: Multiple Root OpenAPI definitions found. Only one definition can be the Root."
28 )]
29 MultipleRootsFound,
30
31 #[error("Empty input: No files found in the specified directories.")]
32 NoFilesFound,
33
34 #[error("YAML error in {file}:{line}: {source}\nContext:\n{context}")]
35 SourceMapped {
36 file: PathBuf,
37 line: usize,
38 source: serde_yaml::Error,
39 context: String,
40 },
41}
42
43pub type Result<T> = std::result::Result<T, Error>;