Skip to content

Commit

Permalink
Add yaml support
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb committed Nov 7, 2022
1 parent 6aa3d69 commit d0f876b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions progenitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ anyhow = "1.0"
openapiv3 = "1.0.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9"
clap = { version = "4.0.18", features = ["derive"] }

[dev-dependencies]
Expand Down
16 changes: 14 additions & 2 deletions progenitor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::{
fs::{File, OpenOptions},
io::Read,
io::Write,
path::{Path, PathBuf},
};
Expand Down Expand Up @@ -171,7 +172,18 @@ pub fn load_api<P>(p: P) -> Result<OpenAPI>
where
P: AsRef<Path>,
{
let f = File::open(p)?;
let api = serde_json::from_reader(f)?;
let mut f = File::open(p)?;

let mut buf = [b' '];
while buf[0].is_ascii_whitespace() {
f.read_exact(&mut buf)?;
}
let reader = buf.as_ref().chain(f);

let api = if buf[0] == b'{' {
serde_json::from_reader(reader)?
} else {
serde_yaml::from_reader(reader)?
};
Ok(api)
}

0 comments on commit d0f876b

Please sign in to comment.