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
36
37
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_yaml;

mod common;
mod definitions;
mod paths;

use definitions::Definitions;
use paths::Paths;

#[derive(Debug, PartialEq, Deserialize)]
pub struct Swagger {
    #[serde(rename = "swagger")]
    spec: Option<String>,
    definitions: Option<Definitions>,
    paths: Option<Paths>,
}

#[cfg(test)]
mod tests {
    extern crate yaml_rust;
    use std::fs::File;
    use std::path::PathBuf;
    use Swagger;

    #[test]
    fn load_test_yaml() {
        let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
        path.push("src/test.yaml");
        let file = File::open(path.to_str().unwrap()).unwrap();
        let root: Swagger = serde_yaml::from_reader(&file).unwrap();
        assert!(root.paths.unwrap().len() > 0);
        assert!(root.definitions.unwrap().len() > 0);
    }
}