Skip to content

Commit

Permalink
feat: introduce expander for easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
drahnr committed Jun 15, 2024
1 parent 1ca04de commit 8a5bcf2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
46 changes: 46 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-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ serde_json = "1.0"
serde_yaml = "0.9"
serde_tokenstream = "0.2.0"
syn = { version = "2.0", features = ["full", "extra-traits"] }
expander = "2.2.1"
13 changes: 13 additions & 0 deletions progenitor-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
fmt::Display,
fs::File,
path::{Path, PathBuf},
str::FromStr,
};

use openapiv3::OpenAPI;
Expand Down Expand Up @@ -405,5 +406,17 @@ fn do_generate_api(item: TokenStream) -> Result<TokenStream, syn::Error> {
const _: &str = include_str!(#path_str);
};

let output = if let Some(dest) = std::env::var("PROGENITOR_OUTPUT_DEBUG")
.map(|ref s| {std::path::PathBuf::from_str(s).expect("Environment var `PROGENITOR_OUTPUT_DEBUG` must contain a valid path")}).ok()
{
eprintln!("Writing generated output to {}", path.display());
expander::Expander::new(dest.file_name().expect("Environment var `PROGENITOR_OUTPUT_DEBUG` must contain path with filename").to_string_lossy())
.fmt(expander::Edition::_2021)
.verbose(true)
.write_to(output, dest.parent().expect("If path has filename, parent must be root / drive at least. qed"))
.expect("Writing file works. qed")
} else {
output
};
Ok(output.into())
}
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 @@ progenitor-client = { version = "0.7.0", path = "../progenitor-client" }
progenitor-impl = { version = "0.7.0", path = "../progenitor-impl" }
progenitor-macro = { version = "0.7.0", path = "../progenitor-macro" }
serde_json = "1.0"
expander = "2.1.0"

[dev-dependencies]
base64 = "0.22"
Expand Down

0 comments on commit 8a5bcf2

Please sign in to comment.