openapi_merge/input/
source.rs

1use super::*;
2
3#[derive(Debug, Deserialize)]
4#[serde(untagged)]
5pub enum InputSource {
6    InputFile {
7        #[serde(rename = "inputFile")]
8        input_file: PathBuf,
9    },
10    InputUrl {
11        #[serde(rename = "inputURL")]
12        input_url: String,
13    },
14}
15
16impl InputSource {
17    pub fn load(&self, base: &Path) -> io::Result<OpenAPI> {
18        match self {
19            Self::InputFile { input_file } => {
20                let path = base.join(input_file);
21                load_json_file(path)
22            }
23            Self::InputUrl { .. } => todo!(),
24        }
25    }
26}
27
28impl fmt::Display for InputSource {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            Self::InputFile { input_file } => input_file.display().fmt(f),
32            Self::InputUrl { input_url } => input_url.fmt(f),
33        }
34    }
35}