Remove rustfmt from progenitor-impl (#368)
This commit is contained in:
parent
f6f957f89f
commit
b717086ef3
|
@ -480,12 +480,14 @@ version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"prettyplease",
|
||||||
"progenitor",
|
"progenitor",
|
||||||
"progenitor-client",
|
"progenitor-client",
|
||||||
"rand",
|
"rand",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"syn 1.0.109",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1217,6 +1219,16 @@ version = "0.2.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "prettyplease"
|
||||||
|
version = "0.1.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.56"
|
version = "1.0.56"
|
||||||
|
@ -1245,6 +1257,7 @@ dependencies = [
|
||||||
"rand",
|
"rand",
|
||||||
"regress",
|
"regress",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
"rustfmt-wrapper",
|
||||||
"schemars",
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
|
@ -14,5 +14,7 @@ serde = { version = "1.0", features = ["derive"] }
|
||||||
uuid = { version = "1.3", features = ["serde", "v4"] }
|
uuid = { version = "1.3", features = ["serde", "v4"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
prettyplease = "0.1.25"
|
||||||
progenitor = { path = "../progenitor" }
|
progenitor = { path = "../progenitor" }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
syn = "1.0"
|
||||||
|
|
|
@ -13,7 +13,9 @@ fn main() {
|
||||||
let spec = serde_json::from_reader(file).unwrap();
|
let spec = serde_json::from_reader(file).unwrap();
|
||||||
let mut generator = progenitor::Generator::default();
|
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();
|
let mut out_file = Path::new(&env::var("OUT_DIR").unwrap()).to_path_buf();
|
||||||
out_file.push("codegen.rs");
|
out_file.push("codegen.rs");
|
||||||
|
|
|
@ -16,7 +16,6 @@ openapiv3 = "1.0.0"
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
regex = "1.8"
|
regex = "1.8"
|
||||||
rustfmt-wrapper = "0.2.0"
|
|
||||||
schemars = { version = "0.8.12", features = ["chrono", "uuid1"] }
|
schemars = { version = "0.8.12", features = ["chrono", "uuid1"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
@ -32,5 +31,6 @@ dropshot = { git = "https://github.com/oxidecomputer/dropshot", default-features
|
||||||
expectorate = "1.0"
|
expectorate = "1.0"
|
||||||
http = "0.2.9"
|
http = "0.2.9"
|
||||||
hyper = "0.14.26"
|
hyper = "0.14.26"
|
||||||
|
rustfmt-wrapper = "0.2.0"
|
||||||
serde_yaml = "0.9"
|
serde_yaml = "0.9"
|
||||||
serde_json = "1.0.96"
|
serde_json = "1.0.96"
|
||||||
|
|
|
@ -10,7 +10,6 @@ use crate::{
|
||||||
method::{
|
method::{
|
||||||
OperationParameterKind, OperationParameterType, OperationResponseStatus,
|
OperationParameterKind, OperationParameterType, OperationResponseStatus,
|
||||||
},
|
},
|
||||||
space_out_items,
|
|
||||||
to_schema::ToSchema,
|
to_schema::ToSchema,
|
||||||
util::{sanitize, Case},
|
util::{sanitize, Case},
|
||||||
validate_openapi, Generator, Result,
|
validate_openapi, Generator, Result,
|
||||||
|
@ -23,25 +22,6 @@ struct CliOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Generator {
|
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.
|
/// Generate a `clap`-based CLI.
|
||||||
pub fn cli(
|
pub fn cli(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -506,41 +506,7 @@ impl Generator {
|
||||||
|
|
||||||
/// Render text output.
|
/// Render text output.
|
||||||
pub fn generate_text(&mut self, spec: &OpenAPI) -> Result<String> {
|
pub fn generate_text(&mut self, spec: &OpenAPI) -> Result<String> {
|
||||||
self.generate_text_impl(
|
Ok(self.generate_tokens(spec)?.to_string())
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO deprecate?
|
// TODO deprecate?
|
||||||
|
|
|
@ -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
|
// 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
|
// 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
|
// an allOf union of the actual subschema along with a fixed-field
|
||||||
// structure.
|
// structure.
|
||||||
|
|
||||||
|
|
|
@ -2510,7 +2510,20 @@ pub mod types {
|
||||||
impl std::str::FromStr for Ipv4Net {
|
impl std::str::FromStr for Ipv4Net {
|
||||||
type Err = &'static str;
|
type Err = &'static str;
|
||||||
fn from_str(value: &str) -> Result<Self, &'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()))
|
Ok(Self(value.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2593,7 +2606,19 @@ pub mod types {
|
||||||
impl std::str::FromStr for Ipv6Net {
|
impl std::str::FromStr for Ipv6Net {
|
||||||
type Err = &'static str;
|
type Err = &'static str;
|
||||||
fn from_str(value: &str) -> Result<Self, &'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()))
|
Ok(Self(value.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5241,7 +5266,9 @@ pub mod types {
|
||||||
.find(value)
|
.find(value)
|
||||||
.is_none()
|
.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()))
|
Ok(Self(value.to_string()))
|
||||||
}
|
}
|
||||||
|
@ -23979,7 +24006,10 @@ pub mod builder {
|
||||||
where
|
where
|
||||||
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24008,7 +24038,11 @@ pub mod builder {
|
||||||
where
|
where
|
||||||
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34202,7 +34236,10 @@ pub mod builder {
|
||||||
where
|
where
|
||||||
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34241,7 +34278,11 @@ pub mod builder {
|
||||||
where
|
where
|
||||||
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2530,7 +2530,20 @@ pub mod types {
|
||||||
impl std::str::FromStr for Ipv4Net {
|
impl std::str::FromStr for Ipv4Net {
|
||||||
type Err = &'static str;
|
type Err = &'static str;
|
||||||
fn from_str(value: &str) -> Result<Self, &'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()))
|
Ok(Self(value.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2613,7 +2626,19 @@ pub mod types {
|
||||||
impl std::str::FromStr for Ipv6Net {
|
impl std::str::FromStr for Ipv6Net {
|
||||||
type Err = &'static str;
|
type Err = &'static str;
|
||||||
fn from_str(value: &str) -> Result<Self, &'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()))
|
Ok(Self(value.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5283,7 +5308,9 @@ pub mod types {
|
||||||
.find(value)
|
.find(value)
|
||||||
.is_none()
|
.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()))
|
Ok(Self(value.to_string()))
|
||||||
}
|
}
|
||||||
|
@ -23771,7 +23798,10 @@ pub mod builder {
|
||||||
where
|
where
|
||||||
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23800,7 +23830,11 @@ pub mod builder {
|
||||||
where
|
where
|
||||||
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33994,7 +34028,10 @@ pub mod builder {
|
||||||
where
|
where
|
||||||
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34033,7 +34070,11 @@ pub mod builder {
|
||||||
where
|
where
|
||||||
V: std::convert::TryInto<chrono::DateTime<chrono::offset::Utc>>,
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2216,7 +2216,20 @@ pub mod types {
|
||||||
impl std::str::FromStr for Ipv4Net {
|
impl std::str::FromStr for Ipv4Net {
|
||||||
type Err = &'static str;
|
type Err = &'static str;
|
||||||
fn from_str(value: &str) -> Result<Self, &'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()))
|
Ok(Self(value.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2293,7 +2306,19 @@ pub mod types {
|
||||||
impl std::str::FromStr for Ipv6Net {
|
impl std::str::FromStr for Ipv6Net {
|
||||||
type Err = &'static str;
|
type Err = &'static str;
|
||||||
fn from_str(value: &str) -> Result<Self, &'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()))
|
Ok(Self(value.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4635,7 +4660,9 @@ pub mod types {
|
||||||
.find(value)
|
.find(value)
|
||||||
.is_none()
|
.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()))
|
Ok(Self(value.to_string()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -964,9 +964,9 @@ pub mod types {
|
||||||
name: Err("no value supplied for name".to_string()),
|
name: Err("no value supplied for name".to_string()),
|
||||||
read_only: Err("no value supplied for read_only".to_string()),
|
read_only: Err("no value supplied for read_only".to_string()),
|
||||||
slot: Err("no value supplied for slot".to_string()),
|
slot: Err("no value supplied for slot".to_string()),
|
||||||
volume_construction_request: Err(
|
volume_construction_request: Err("no value supplied for \
|
||||||
"no value supplied for volume_construction_request".to_string(),
|
volume_construction_request"
|
||||||
),
|
.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -970,9 +970,9 @@ pub mod types {
|
||||||
name: Err("no value supplied for name".to_string()),
|
name: Err("no value supplied for name".to_string()),
|
||||||
read_only: Err("no value supplied for read_only".to_string()),
|
read_only: Err("no value supplied for read_only".to_string()),
|
||||||
slot: Err("no value supplied for slot".to_string()),
|
slot: Err("no value supplied for slot".to_string()),
|
||||||
volume_construction_request: Err(
|
volume_construction_request: Err("no value supplied for \
|
||||||
"no value supplied for volume_construction_request".to_string(),
|
volume_construction_request"
|
||||||
),
|
.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,12 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use progenitor_impl::{
|
use progenitor_impl::{
|
||||||
GenerationSettings, Generator, InterfaceStyle, TagStyle, TypeImpl,
|
space_out_items, GenerationSettings, Generator, InterfaceStyle, TagStyle,
|
||||||
TypePatch,
|
TypeImpl, TypePatch,
|
||||||
};
|
};
|
||||||
|
|
||||||
use openapiv3::OpenAPI;
|
use openapiv3::OpenAPI;
|
||||||
|
use proc_macro2::TokenStream;
|
||||||
|
|
||||||
fn load_api<P>(p: P) -> OpenAPI
|
fn load_api<P>(p: P) -> OpenAPI
|
||||||
where
|
where
|
||||||
|
@ -26,6 +27,24 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn generate_formatted(generator: &mut Generator, spec: &OpenAPI) -> String {
|
||||||
|
let content = generator.generate_tokens(&spec).unwrap();
|
||||||
|
reformat_code(content)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reformat_code(content: TokenStream) -> String {
|
||||||
|
let rustfmt_config = rustfmt_wrapper::config::Config {
|
||||||
|
format_strings: Some(true),
|
||||||
|
normalize_doc_attributes: Some(true),
|
||||||
|
wrap_comments: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
space_out_items(
|
||||||
|
rustfmt_wrapper::rustfmt_config(rustfmt_config, content).unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn verify_apis(openapi_file: &str) {
|
fn verify_apis(openapi_file: &str) {
|
||||||
let mut in_path = PathBuf::from("../sample_openapi");
|
let mut in_path = PathBuf::from("../sample_openapi");
|
||||||
|
@ -36,7 +55,7 @@ fn verify_apis(openapi_file: &str) {
|
||||||
|
|
||||||
// Positional generation.
|
// Positional generation.
|
||||||
let mut generator = Generator::default();
|
let mut generator = Generator::default();
|
||||||
let output = generator.generate_text_normalize_comments(&spec).unwrap();
|
let output = generate_formatted(&mut generator, &spec);
|
||||||
expectorate::assert_contents(
|
expectorate::assert_contents(
|
||||||
format!("tests/output/{}-positional.out", openapi_stem),
|
format!("tests/output/{}-positional.out", openapi_stem),
|
||||||
&output,
|
&output,
|
||||||
|
@ -61,7 +80,7 @@ fn verify_apis(openapi_file: &str) {
|
||||||
[TypeImpl::Display].into_iter(),
|
[TypeImpl::Display].into_iter(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
let output = generator.generate_text_normalize_comments(&spec).unwrap();
|
let output = generate_formatted(&mut generator, &spec);
|
||||||
expectorate::assert_contents(
|
expectorate::assert_contents(
|
||||||
format!("tests/output/{}-builder.out", openapi_stem),
|
format!("tests/output/{}-builder.out", openapi_stem),
|
||||||
&output,
|
&output,
|
||||||
|
@ -73,14 +92,16 @@ fn verify_apis(openapi_file: &str) {
|
||||||
.with_interface(InterfaceStyle::Builder)
|
.with_interface(InterfaceStyle::Builder)
|
||||||
.with_tag(TagStyle::Separate),
|
.with_tag(TagStyle::Separate),
|
||||||
);
|
);
|
||||||
let output = generator.generate_text_normalize_comments(&spec).unwrap();
|
let output = generate_formatted(&mut generator, &spec);
|
||||||
expectorate::assert_contents(
|
expectorate::assert_contents(
|
||||||
format!("tests/output/{}-builder-tagged.out", openapi_stem),
|
format!("tests/output/{}-builder-tagged.out", openapi_stem),
|
||||||
&output,
|
&output,
|
||||||
);
|
);
|
||||||
|
|
||||||
// CLI generation.
|
// CLI generation.
|
||||||
let output = generator.cli_text(&spec, "sdk").unwrap();
|
let tokens = generator.cli(&spec, "sdk").unwrap();
|
||||||
|
let output = reformat_code(tokens);
|
||||||
|
|
||||||
expectorate::assert_contents(
|
expectorate::assert_contents(
|
||||||
format!("tests/output/{}-cli.out", openapi_stem),
|
format!("tests/output/{}-cli.out", openapi_stem),
|
||||||
&output,
|
&output,
|
||||||
|
|
|
@ -9,10 +9,25 @@ use dropshot::{
|
||||||
use http::Response;
|
use http::Response;
|
||||||
use hyper::Body;
|
use hyper::Body;
|
||||||
use openapiv3::OpenAPI;
|
use openapiv3::OpenAPI;
|
||||||
use progenitor_impl::{GenerationSettings, Generator, InterfaceStyle};
|
use progenitor_impl::{
|
||||||
|
space_out_items, GenerationSettings, Generator, InterfaceStyle,
|
||||||
|
};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
fn generate_formatted(generator: &mut Generator, spec: &OpenAPI) -> String {
|
||||||
|
let content = generator.generate_tokens(&spec).unwrap();
|
||||||
|
let rustfmt_config = rustfmt_wrapper::config::Config {
|
||||||
|
normalize_doc_attributes: Some(true),
|
||||||
|
wrap_comments: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
space_out_items(
|
||||||
|
rustfmt_wrapper::rustfmt_config(rustfmt_config, content).unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Deserialize, JsonSchema)]
|
#[derive(Deserialize, JsonSchema)]
|
||||||
struct CursedPath {
|
struct CursedPath {
|
||||||
|
@ -65,7 +80,7 @@ fn test_renamed_parameters() {
|
||||||
let spec = serde_json::from_str::<OpenAPI>(out).unwrap();
|
let spec = serde_json::from_str::<OpenAPI>(out).unwrap();
|
||||||
|
|
||||||
let mut generator = Generator::default();
|
let mut generator = Generator::default();
|
||||||
let output = generator.generate_text_normalize_comments(&spec).unwrap();
|
let output = generate_formatted(&mut generator, &spec);
|
||||||
expectorate::assert_contents(
|
expectorate::assert_contents(
|
||||||
format!("tests/output/{}.out", "test_renamed_parameters"),
|
format!("tests/output/{}.out", "test_renamed_parameters"),
|
||||||
&output,
|
&output,
|
||||||
|
@ -98,7 +113,7 @@ fn test_freeform_response() {
|
||||||
let spec = serde_json::from_str::<OpenAPI>(out).unwrap();
|
let spec = serde_json::from_str::<OpenAPI>(out).unwrap();
|
||||||
|
|
||||||
let mut generator = Generator::default();
|
let mut generator = Generator::default();
|
||||||
let output = generator.generate_text_normalize_comments(&spec).unwrap();
|
let output = generate_formatted(&mut generator, &spec);
|
||||||
expectorate::assert_contents(
|
expectorate::assert_contents(
|
||||||
format!("tests/output/{}.out", "test_freeform_response"),
|
format!("tests/output/{}.out", "test_freeform_response"),
|
||||||
&output,
|
&output,
|
||||||
|
@ -152,7 +167,7 @@ fn test_default_params() {
|
||||||
let spec = serde_json::from_str::<OpenAPI>(out).unwrap();
|
let spec = serde_json::from_str::<OpenAPI>(out).unwrap();
|
||||||
|
|
||||||
let mut generator = Generator::default();
|
let mut generator = Generator::default();
|
||||||
let output = generator.generate_text_normalize_comments(&spec).unwrap();
|
let output = generate_formatted(&mut generator, &spec);
|
||||||
expectorate::assert_contents(
|
expectorate::assert_contents(
|
||||||
format!("tests/output/{}.out", "test_default_params_positional"),
|
format!("tests/output/{}.out", "test_default_params_positional"),
|
||||||
&output,
|
&output,
|
||||||
|
@ -161,7 +176,7 @@ fn test_default_params() {
|
||||||
let mut generator = Generator::new(
|
let mut generator = Generator::new(
|
||||||
GenerationSettings::default().with_interface(InterfaceStyle::Builder),
|
GenerationSettings::default().with_interface(InterfaceStyle::Builder),
|
||||||
);
|
);
|
||||||
let output = generator.generate_text_normalize_comments(&spec).unwrap();
|
let output = generate_formatted(&mut generator, &spec);
|
||||||
expectorate::assert_contents(
|
expectorate::assert_contents(
|
||||||
format!("tests/output/{}.out", "test_default_params_builder"),
|
format!("tests/output/{}.out", "test_default_params_builder"),
|
||||||
&output,
|
&output,
|
||||||
|
|
|
@ -16,6 +16,7 @@ progenitor-impl = { version = "0.2.1-dev", path = "../progenitor-impl" }
|
||||||
progenitor-macro = { version = "0.2.1-dev", path = "../progenitor-macro" }
|
progenitor-macro = { version = "0.2.1-dev", path = "../progenitor-macro" }
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
openapiv3 = "1.0.0"
|
openapiv3 = "1.0.0"
|
||||||
|
rustfmt-wrapper = "0.2.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde_yaml = "0.9"
|
serde_yaml = "0.9"
|
||||||
|
|
|
@ -11,6 +11,7 @@ use anyhow::{bail, Result};
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
use openapiv3::OpenAPI;
|
use openapiv3::OpenAPI;
|
||||||
use progenitor::{GenerationSettings, Generator, InterfaceStyle, TagStyle};
|
use progenitor::{GenerationSettings, Generator, InterfaceStyle, TagStyle};
|
||||||
|
use progenitor_impl::space_out_items;
|
||||||
|
|
||||||
pub mod built_info {
|
pub mod built_info {
|
||||||
// The file has been placed there by the build script.
|
// The file has been placed there by the build script.
|
||||||
|
@ -84,6 +85,16 @@ impl From<TagArg> for TagStyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn reformat_code(input: String) -> String {
|
||||||
|
let config = rustfmt_wrapper::config::Config {
|
||||||
|
normalize_doc_attributes: Some(true),
|
||||||
|
wrap_comments: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
space_out_items(rustfmt_wrapper::rustfmt_config(config, input).unwrap())
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
fn save<P>(p: P, data: &str) -> Result<()>
|
fn save<P>(p: P, data: &str) -> Result<()>
|
||||||
where
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
|
@ -179,6 +190,8 @@ fn main() -> Result<()> {
|
||||||
} else {
|
} else {
|
||||||
api_code
|
api_code
|
||||||
};
|
};
|
||||||
|
let lib_code = reformat_code(lib_code);
|
||||||
|
|
||||||
let mut librs = src.clone();
|
let mut librs = src.clone();
|
||||||
librs.push("lib.rs");
|
librs.push("lib.rs");
|
||||||
save(librs, lib_code.as_str())?;
|
save(librs, lib_code.as_str())?;
|
||||||
|
|
Loading…
Reference in New Issue