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 25, 2023
1 parent 7da8db8 commit 25b07ab
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 92 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 @@ -16,7 +16,6 @@ openapiv3 = "1.0.0"
proc-macro2 = "1.0"
quote = "1.0"
regex = "1.8"
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 @@ -32,5 +31,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.96"
20 changes: 0 additions & 20 deletions progenitor-impl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
method::{
OperationParameterKind, OperationParameterType, OperationResponseStatus,
},
space_out_items,
to_schema::ToSchema,
util::{sanitize, Case},
validate_openapi, Generator, Result,
Expand All @@ -23,25 +22,6 @@ struct CliOperation {
}

impl Generator {
pub fn cli_text(
&mut self,
spec: &OpenAPI,
crate_name: &str,
) -> 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)
}

/// Generate a `clap`-based CLI.
pub fn cli(
&mut self,
Expand Down
36 changes: 1 addition & 35 deletions progenitor-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,41 +506,7 @@ 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(),
)
}

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

space_out_items(content)
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
55 changes: 48 additions & 7 deletions progenitor-impl/tests/output/nexus-builder-tagged.out
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,20 @@ pub mod types {
impl std::str::FromStr for Ipv4Net {
type Err = &'static str;
fn from_str(value: &str) -> Result<Self, &'static str> {
if regress :: Regex :: new ("^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/([8-9]|1[0-9]|2[0-9]|3[0-2])$") . unwrap () . find (value) . is_none () { return Err ("doesn't match pattern \"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/([8-9]|1[0-9]|2[0-9]|3[0-2])$\"") ; }
if regress::Regex::new(
"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.\
){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/\
([8-9]|1[0-9]|2[0-9]|3[0-2])$",
)
.unwrap()
.find(value)
.is_none()
{
return Err("doesn't match pattern \
\"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.\
){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/\
([8-9]|1[0-9]|2[0-9]|3[0-2])$\"");
}
Ok(Self(value.to_string()))
}
}
Expand Down Expand Up @@ -2593,7 +2606,19 @@ pub mod types {
impl std::str::FromStr for Ipv6Net {
type Err = &'static str;
fn from_str(value: &str) -> Result<Self, &'static str> {
if regress :: Regex :: new ("^([fF][dD])[0-9a-fA-F]{2}:(([0-9a-fA-F]{1,4}:){6}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,6}:)\\/([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$") . unwrap () . find (value) . is_none () { return Err ("doesn't match pattern \"^([fF][dD])[0-9a-fA-F]{2}:(([0-9a-fA-F]{1,4}:){6}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,6}:)\\/([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$\"") ; }
if regress::Regex::new(
"^([fF][dD])[0-9a-fA-F]{2}:(([0-9a-fA-F]{1,4}:){6}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,\
4}:){1,6}:)\\/([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$",
)
.unwrap()
.find(value)
.is_none()
{
return Err("doesn't match pattern \
\"^([fF][dD])[0-9a-fA-F]{2}:(([0-9a-fA-F]{1,4}:){6}[0-9a-fA-F]{1,\
4}|([0-9a-fA-F]{1,4}:){1,6}:)\\/\
([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$\"");
}
Ok(Self(value.to_string()))
}
}
Expand Down Expand Up @@ -5241,7 +5266,9 @@ pub mod types {
.find(value)
.is_none()
{
return Err ("doesn't match pattern \"(([a-z]+[a-z0-9]*)(_([a-z0-9]+))*):(([a-z]+[a-z0-9]*)(_([a-z0-9]+))*)\"") ;
return Err("doesn't match pattern \
\"(([a-z]+[a-z0-9]*)(_([a-z0-9]+))*):(([a-z]+[a-z0-9]*\
)(_([a-z0-9]+))*)\"");
}
Ok(Self(value.to_string()))
}
Expand Down Expand Up @@ -23979,7 +24006,10 @@ pub mod builder {
where
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
{
self . end_time = value . try_into () . map (Some) . map_err (| _ | "conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for end_time failed" . to_string ()) ;
self.end_time = value.try_into().map(Some).map_err(|_| {
"conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for end_time failed"
.to_string()
});
self
}

Expand Down Expand Up @@ -24008,7 +24038,11 @@ pub mod builder {
where
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
{
self . start_time = value . try_into () . map (Some) . map_err (| _ | "conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for start_time failed" . to_string ()) ;
self.start_time = value.try_into().map(Some).map_err(|_| {
"conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for start_time \
failed"
.to_string()
});
self
}

Expand Down Expand Up @@ -34202,7 +34236,10 @@ pub mod builder {
where
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
{
self . end_time = value . try_into () . map (Some) . map_err (| _ | "conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for end_time failed" . to_string ()) ;
self.end_time = value.try_into().map(Some).map_err(|_| {
"conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for end_time failed"
.to_string()
});
self
}

Expand Down Expand Up @@ -34241,7 +34278,11 @@ pub mod builder {
where
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
{
self . start_time = value . try_into () . map (Some) . map_err (| _ | "conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for start_time failed" . to_string ()) ;
self.start_time = value.try_into().map(Some).map_err(|_| {
"conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for start_time \
failed"
.to_string()
});
self
}

Expand Down
55 changes: 48 additions & 7 deletions progenitor-impl/tests/output/nexus-builder.out
Original file line number Diff line number Diff line change
Expand Up @@ -2530,7 +2530,20 @@ pub mod types {
impl std::str::FromStr for Ipv4Net {
type Err = &'static str;
fn from_str(value: &str) -> Result<Self, &'static str> {
if regress :: Regex :: new ("^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/([8-9]|1[0-9]|2[0-9]|3[0-2])$") . unwrap () . find (value) . is_none () { return Err ("doesn't match pattern \"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/([8-9]|1[0-9]|2[0-9]|3[0-2])$\"") ; }
if regress::Regex::new(
"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.\
){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/\
([8-9]|1[0-9]|2[0-9]|3[0-2])$",
)
.unwrap()
.find(value)
.is_none()
{
return Err("doesn't match pattern \
\"^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.\
){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])/\
([8-9]|1[0-9]|2[0-9]|3[0-2])$\"");
}
Ok(Self(value.to_string()))
}
}
Expand Down Expand Up @@ -2613,7 +2626,19 @@ pub mod types {
impl std::str::FromStr for Ipv6Net {
type Err = &'static str;
fn from_str(value: &str) -> Result<Self, &'static str> {
if regress :: Regex :: new ("^([fF][dD])[0-9a-fA-F]{2}:(([0-9a-fA-F]{1,4}:){6}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,6}:)\\/([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$") . unwrap () . find (value) . is_none () { return Err ("doesn't match pattern \"^([fF][dD])[0-9a-fA-F]{2}:(([0-9a-fA-F]{1,4}:){6}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,6}:)\\/([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$\"") ; }
if regress::Regex::new(
"^([fF][dD])[0-9a-fA-F]{2}:(([0-9a-fA-F]{1,4}:){6}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,\
4}:){1,6}:)\\/([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$",
)
.unwrap()
.find(value)
.is_none()
{
return Err("doesn't match pattern \
\"^([fF][dD])[0-9a-fA-F]{2}:(([0-9a-fA-F]{1,4}:){6}[0-9a-fA-F]{1,\
4}|([0-9a-fA-F]{1,4}:){1,6}:)\\/\
([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])$\"");
}
Ok(Self(value.to_string()))
}
}
Expand Down Expand Up @@ -5283,7 +5308,9 @@ pub mod types {
.find(value)
.is_none()
{
return Err ("doesn't match pattern \"(([a-z]+[a-z0-9]*)(_([a-z0-9]+))*):(([a-z]+[a-z0-9]*)(_([a-z0-9]+))*)\"") ;
return Err("doesn't match pattern \
\"(([a-z]+[a-z0-9]*)(_([a-z0-9]+))*):(([a-z]+[a-z0-9]*\
)(_([a-z0-9]+))*)\"");
}
Ok(Self(value.to_string()))
}
Expand Down Expand Up @@ -23771,7 +23798,10 @@ pub mod builder {
where
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
{
self . end_time = value . try_into () . map (Some) . map_err (| _ | "conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for end_time failed" . to_string ()) ;
self.end_time = value.try_into().map(Some).map_err(|_| {
"conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for end_time failed"
.to_string()
});
self
}

Expand Down Expand Up @@ -23800,7 +23830,11 @@ pub mod builder {
where
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
{
self . start_time = value . try_into () . map (Some) . map_err (| _ | "conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for start_time failed" . to_string ()) ;
self.start_time = value.try_into().map(Some).map_err(|_| {
"conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for start_time \
failed"
.to_string()
});
self
}

Expand Down Expand Up @@ -33994,7 +34028,10 @@ pub mod builder {
where
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
{
self . end_time = value . try_into () . map (Some) . map_err (| _ | "conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for end_time failed" . to_string ()) ;
self.end_time = value.try_into().map(Some).map_err(|_| {
"conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for end_time failed"
.to_string()
});
self
}

Expand Down Expand Up @@ -34033,7 +34070,11 @@ pub mod builder {
where
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
{
self . start_time = value . try_into () . map (Some) . map_err (| _ | "conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for start_time failed" . to_string ()) ;
self.start_time = value.try_into().map(Some).map_err(|_| {
"conversion to `chrono :: DateTime < chrono :: offset :: Utc >` for start_time \
failed"
.to_string()
});
self
}

Expand Down
Loading

0 comments on commit 25b07ab

Please sign in to comment.