1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use super::*;

#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum InputSource {
    InputFile {
        #[serde(rename = "inputFile")]
        input_file: PathBuf,
    },
    InputUrl {
        #[serde(rename = "inputURL")]
        input_url: String,
    },
}

impl InputSource {
    pub fn load(&self, base: &Path) -> io::Result<OpenAPI> {
        match self {
            Self::InputFile { input_file } => {
                let path = base.join(input_file);
                load_json_file(path)
            }
            Self::InputUrl { .. } => todo!(),
        }
    }
}

impl fmt::Display for InputSource {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::InputFile { input_file } => input_file.display().fmt(f),
            Self::InputUrl { input_url } => input_url.fmt(f),
        }
    }
}