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 Apr 18, 2023
1 parent b969813 commit 6efc117
Show file tree
Hide file tree
Showing 35 changed files with 69 additions and 22,017 deletions.
13 changes: 13 additions & 0 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
2 changes: 1 addition & 1 deletion progenitor-impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ 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 @@ -31,5 +30,6 @@ dropshot = { git = "https://github.com/oxidecomputer/dropshot", default-features
expectorate = "1.0"
http = "0.2.9"
hyper = "0.14.26"
rustfmt-wrapper = "0.2.0"
serde_yaml = "0.9"
serde_json = "1.0.95"
11 changes: 1 addition & 10 deletions progenitor-impl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,7 @@ impl Generator {
) -> Result<String> {
let output = self.cli(spec, crate_name)?;

let content = rustfmt_wrapper::rustfmt_config(
rustfmt_wrapper::config::Config {
format_strings: Some(true),
..Default::default()
},
output,
)
.unwrap();

space_out_items(content)
space_out_items(output.to_string())
}

pub fn cli(
Expand Down
30 changes: 4 additions & 26 deletions progenitor-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,41 +505,19 @@ impl Generator {

/// Render text output.
pub fn generate_text(&mut self, spec: &OpenAPI) -> Result<String> {
self.generate_text_impl(
spec,
rustfmt_wrapper::config::Config::default(),
)
self.generate_text_impl(spec)
}

/// 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()
},
)
self.generate_text_impl(spec)
}

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();

space_out_items(content)
fn generate_text_impl(&mut self, spec: &OpenAPI) -> Result<String> {
space_out_items(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 6efc117

Please sign in to comment.