pub fn from_path<P>(path: P) -> Result<Spec>Expand description
deserialize an open api spec from a path
Examples found in repository?
examples/printer.rs (line 7)
5fn main() {
6 if let Some(path) = std::env::args().nth(1) {
7 match openapi::from_path(path) {
8 Ok(spec) => {
9 /*for (path, op) in spec.paths {
10 println!("{}", path);
11 println!("{:#?}", op);
12 }
13 for (name, definition) in spec.definitions {
14 println!("{}", name);
15 println!("{:#?}", definition);
16 }*/
17 println!("{}", openapi::to_json(&spec).unwrap());
18 }
19 Err(e) => {
20
21 let stderr = &mut ::std::io::stderr();
22 let errmsg = "Error writing to stderr";
23
24 writeln!(stderr, "error: {}", e).expect(errmsg);
25
26 for e in e.iter().skip(1) {
27 writeln!(stderr, "caused by: {}", e).expect(errmsg);
28 }
29
30 // The backtrace is not always generated. Try to run this example
31 // with `RUST_BACKTRACE=1`.
32 if let Some(backtrace) = e.backtrace() {
33 writeln!(stderr, "backtrace: {:?}", backtrace).expect(errmsg);
34 }
35
36 ::std::process::exit(1);
37 }
38 }
39 }
40}