Skip to content

Commit

Permalink
Remove rustfmt from progenitor-impl
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb committed Mar 18, 2023
1 parent c922600 commit 2fac226
Show file tree
Hide file tree
Showing 28 changed files with 3,777 additions and 8,678 deletions.
26 changes: 19 additions & 7 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions example-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ serde = { version = "1.0", features = ["derive"] }
uuid = { version = "1.3", features = ["serde", "v4"] }

[build-dependencies]
prettyplease = "0.1.25"
progenitor = { path = "../progenitor" }
serde_json = "1.0"
syn = "1.0"
4 changes: 3 additions & 1 deletion example-build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ fn main() {
let spec = serde_json::from_reader(file).unwrap();
let mut generator = progenitor::Generator::default();

let content = generator.generate_text(&spec).unwrap();
let tokens = generator.generate_tokens(&spec).unwrap();
let ast = syn::parse2(tokens).unwrap();
let content = prettyplease::unparse(&ast);

let mut out_file = Path::new(&env::var("OUT_DIR").unwrap()).to_path_buf();
out_file.push("codegen.rs");
Expand Down
4 changes: 2 additions & 2 deletions progenitor-impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ indexmap = "1.9"
openapiv3 = "1.0.0"
proc-macro2 = "1.0"
quote = "1.0"
regex = "1.7"
rustfmt-wrapper = "0.2.0"
schemars = { version = "0.8.12", features = ["chrono", "uuid1"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand All @@ -24,11 +22,13 @@ thiserror = "1.0"
# To publish, use a numbered version
#typify = "0.0.10"
typify = { git = "https://github.com/oxidecomputer/typify" }

unicode-ident = "1.0.8"

[dev-dependencies]
dropshot = { git = "https://github.com/oxidecomputer/dropshot", default-features = false }
expectorate = "1.0"
http = "0.2.9"
hyper = "0.14.25"
rustfmt-wrapper = "0.2.0"
serde_yaml = "0.9"
24 changes: 1 addition & 23 deletions progenitor-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,46 +489,24 @@ impl Generator {
pub fn generate_text(&mut self, spec: &OpenAPI) -> Result<String> {
self.generate_text_impl(
spec,
rustfmt_wrapper::config::Config::default(),
)
}

/// Render text output and normalize doc comments
///
/// Requires a nightly install of `rustfmt` (even if the target project is
/// not using nightly).
pub fn generate_text_normalize_comments(
&mut self,
spec: &OpenAPI,
) -> Result<String> {
self.generate_text_impl(
spec,
rustfmt_wrapper::config::Config {
normalize_doc_attributes: Some(true),
wrap_comments: Some(true),
..Default::default()
},
)
}

fn generate_text_impl(
&mut self,
spec: &OpenAPI,
config: rustfmt_wrapper::config::Config,
) -> Result<String> {
let output = self.generate_tokens(spec)?;

// Format the file with rustfmt.
let content = rustfmt_wrapper::rustfmt_config(config, output).unwrap();

// Add newlines after end-braces at <= two levels of indentation.
Ok(if cfg!(not(windows)) {
let regex = regex::Regex::new(r#"(})(\n\s{0,8}[^} ])"#).unwrap();
regex.replace_all(&content, "$1\n$2").to_string()
} else {
let regex = regex::Regex::new(r#"(})(\r\n\s{0,8}[^} ])"#).unwrap();
regex.replace_all(&content, "$1\r\n$2").to_string()
})
Ok(self.generate_tokens(spec)?.to_string())
}

// TODO deprecate?
Expand Down
2 changes: 1 addition & 1 deletion progenitor-impl/src/to_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Convert<schemars::schema::Schema> for openapiv3::Schema {

// 2. It can be used within a oneOf or anyOf schema to determine which
// subschema is relevant. This is easier to detect because it doesn't
// required chasing references. For each subschema we can then make it
// require chasing references. For each subschema we can then make it
// an allOf union of the actual subschema along with a fixed-field
// structure.

Expand Down
Loading

0 comments on commit 2fac226

Please sign in to comment.