Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce expander for easier debugging #826

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -13,6 +13,7 @@ categories = ["api-bindings", "compilers"]
progenitor-client = { workspace = true }
progenitor-impl = { workspace = true }
progenitor-macro = { workspace = true }
expander = "2.1.0"

[dev-dependencies]
base64 = { workspace = true }
Expand Down
Loading