Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
fcd5e66
fix(clippy): retain the public error representation (clippy::result_l…
danieleades Jul 10, 2026
1157204
style(clippy): simplify optional requirement check (clippy::unnecessa…
danieleades Jul 10, 2026
84c0baf
style(clippy): remove redundant format borrows (clippy::useless_borro…
danieleades Jul 10, 2026
09b23dc
style(clippy): collapse nested response check (clippy::collapsible_if)
danieleades Jul 10, 2026
4a4ab4f
style(clippy): defer panic message formatting (clippy::expect_fun_call)
danieleades Jul 10, 2026
4b52f71
refactor(clippy): implement Display for path templates (clippy::to_st…
danieleades Jul 10, 2026
eee7a19
style(clippy): insert an identifier character directly (clippy::singl…
danieleades Jul 10, 2026
e24fe08
style(clippy): derive default generator styles (clippy::derivable_impls)
danieleades Jul 10, 2026
04bf539
style(clippy): format path templates directly (clippy::to_string_in_f…
danieleades Jul 10, 2026
3ad50a1
style(clippy): use arrays for fixed test cases (clippy::useless_vec)
danieleades Jul 10, 2026
9d372d8
style(clippy): elide a constant static lifetime (clippy::redundant_st…
danieleades Jul 10, 2026
ea2abdf
style(clippy): avoid an immediately dereferenced borrow (clippy::need…
danieleades Jul 10, 2026
353d816
style(clippy): name intentionally unused futures (clippy::let_undersc…
danieleades Jul 10, 2026
60ada62
chore(lints): narrow the client hook suppression (unused_variables)
danieleades Jul 10, 2026
56b2a56
style(clippy): inline formatting arguments (clippy::uninlined_format_…
danieleades Jul 10, 2026
432a87b
docs(clippy): mark code terms in documentation (clippy::doc_markdown)
danieleades Jul 10, 2026
6025da7
docs(clippy): mark returned values as significant (clippy::must_use_c…
danieleades Jul 10, 2026
0a1284a
style(clippy): combine identical error match arms (clippy::match_same…
danieleades Jul 10, 2026
622b568
style(clippy): nest shared response patterns (clippy::unnested_or_pat…
danieleades Jul 10, 2026
a82c500
style(clippy): remove a redundant response else (clippy::redundant_else)
danieleades Jul 10, 2026
cedd56f
style(clippy): remove unnecessary raw string hashes (clippy::needless…
danieleades Jul 10, 2026
5421f90
style(clippy): name concrete default types (clippy::default_trait_acc…
danieleades Jul 10, 2026
7870791
style(clippy): copy static implementation names (clippy::cloned_inste…
danieleades Jul 10, 2026
0d37ea9
style(clippy): remove trailing format argument commas (clippy::unnece…
danieleades Jul 10, 2026
76cd005
style(clippy): clone owned strings explicitly (clippy::implicit_clone)
danieleades Jul 10, 2026
e583db7
style(clippy): write into documentation buffers directly (clippy::for…
danieleades Jul 10, 2026
96818d1
refactor(clippy): borrow generation inputs where possible (clippy::ne…
danieleades Jul 10, 2026
d324dcb
refactor(clippy): pass optional components idiomatically (clippy::ref…
danieleades Jul 10, 2026
83dbf78
fix(clippy): reject oversized schema bounds (clippy::cast_possible_tr…
danieleades Jul 10, 2026
76e1638
docs(clippy): describe generation failures (clippy::missing_errors_doc)
danieleades Jul 10, 2026
0f30bee
docs(clippy): describe generation panic invariants (clippy::missing_p…
danieleades Jul 10, 2026
3a10bda
chore(clippy): document cohesive generation functions (clippy::too_ma…
danieleades Jul 10, 2026
67d745a
style(clippy): terminate unit-returning statements (clippy::semicolon…
danieleades Jul 10, 2026
a7c7726
chore(clippy): preserve explicit CLI execution modes (clippy::single_…
danieleades Jul 10, 2026
fdc4cc6
style(clippy): branch directly on inner client state (clippy::match_b…
danieleades Jul 10, 2026
f2fe5cf
style(clippy): destructure response details with let-else (clippy::ma…
danieleades Jul 10, 2026
6439ca2
style(clippy): collect builder parameters directly (clippy::unnecessa…
danieleades Jul 10, 2026
67722fe
style(clippy): use loops for builder tag generation (clippy::needless…
danieleades Jul 10, 2026
1375b3e
style(clippy): iterate over container references (clippy::explicit_it…
danieleades Jul 10, 2026
b4972b7
style(clippy): remove an unnecessary match semicolon (clippy::unneces…
danieleades Jul 10, 2026
c64a3ba
chore(clippy): document numeric schema conversion (clippy::cast_preci…
danieleades Jul 10, 2026
8cd661b
refactor(clippy): return generation values directly (clippy::unnecess…
danieleades Jul 10, 2026
123b4b3
refactor(clippy): make stateless helpers associated (clippy::unused_s…
danieleades Jul 11, 2026
610dc0e
style(clippy): elide response helper lifetimes (clippy::needless_life…
danieleades Jul 11, 2026
042c637
style(clippy): build parameter examples in place (clippy::format_coll…
danieleades Jul 11, 2026
1630cf9
chore(clippy): keep snapshot modules near test phases (clippy::items_…
danieleades Jul 11, 2026
6839bf3
chore(clippy): retain stream parameter lifetimes (clippy::elidable_li…
danieleades Jul 11, 2026
0b817b6
chore(clippy): isolate typify field naming (clippy::struct_field_names)
danieleades Jul 11, 2026
8cf53b2
docs(clippy): explain the ignored GitHub fixture (clippy::ignore_with…
danieleades Jul 11, 2026
30d37fd
style(clippy): construct empty strings directly (clippy::manual_strin…
danieleades Jul 11, 2026
630a467
style(clippy): split the client hook overview (clippy::too_long_first…
danieleades Jul 11, 2026
acf5038
refactor(clippy): make immutable helpers const (clippy::missing_const…
danieleades Jul 11, 2026
79d5ce6
style(clippy): align visibility with private modules (clippy::redunda…
danieleades Jul 11, 2026
ae50982
style(clippy): refer to error variants through Self (clippy::use_self)
danieleades Jul 11, 2026
b92cce6
style(clippy): express optional fallbacks directly (clippy::option_if…
danieleades Jul 11, 2026
3d20ce4
style(clippy): test simple enum variants directly (clippy::equatable_…
danieleades Jul 11, 2026
21cfe32
style(clippy): check upgrade responses with any (clippy::search_is_some)
danieleades Jul 11, 2026
abeba68
style(clippy): move converted array items directly (clippy::redundant…
danieleades Jul 11, 2026
7c223b0
refactor(clippy): borrow helper receivers immutably (clippy::needless…
danieleades Jul 11, 2026
43450f1
chore(clippy): preserve path template placeholders (clippy::literal_s…
danieleades Jul 11, 2026
5658b15
style(clippy): construct the single type implementation iterator (cli…
danieleades Jul 11, 2026
4514647
style(clippy): derive the JSON dependency flag from the branch (clipp…
danieleades Jul 11, 2026
3ffc65c
style(clippy): use shorthand for generated client fields (clippy::red…
danieleades Jul 11, 2026
56a515e
chore(clippy): retain schema-shaped method parameters (clippy::too_ma…
danieleades Jul 11, 2026
6dc453e
style(clippy): compare the wasm base URL directly (clippy::manual_ass…
danieleades Jul 11, 2026
a123c0a
chore(clippy): allow browser-local response futures on wasm (clippy::…
danieleades Jul 11, 2026
2e100ed
style(clippy): consume the inert compile-check future (clippy::no_eff…
danieleades Jul 11, 2026
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
53 changes: 26 additions & 27 deletions cargo-progenitor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use openapiv3::OpenAPI;
use progenitor::{GenerationSettings, Generator, InterfaceStyle, TagStyle};
use progenitor_impl::space_out_items;

fn is_non_release() -> bool {
const fn is_non_release() -> bool {
cfg!(debug_assertions)
}

Expand All @@ -23,10 +23,10 @@ enum CargoCli {
Progenitor(Args),
}

/// Generate a stand-alone crate from an OpenAPI document
/// Generate a stand-alone crate from an `OpenAPI` document
#[derive(Parser)]
struct Args {
/// OpenAPI definition document (JSON or YAML)
/// `OpenAPI` definition document (JSON or YAML)
#[clap(short = 'i', long)]
input: String,
/// Output directory for Rust crate
Expand Down Expand Up @@ -65,8 +65,8 @@ enum InterfaceArg {
impl From<InterfaceArg> for InterfaceStyle {
fn from(arg: InterfaceArg) -> Self {
match arg {
InterfaceArg::Positional => InterfaceStyle::Positional,
InterfaceArg::Builder => InterfaceStyle::Builder,
InterfaceArg::Positional => Self::Positional,
InterfaceArg::Builder => Self::Builder,
}
}
}
Expand All @@ -80,8 +80,8 @@ enum TagArg {
impl From<TagArg> for TagStyle {
fn from(arg: TagArg) -> Self {
match arg {
TagArg::Merged => TagStyle::Merged,
TagArg::Separate => TagStyle::Separate,
TagArg::Merged => Self::Merged,
TagArg::Separate => Self::Separate,
}
}
}
Expand All @@ -92,7 +92,7 @@ fn reformat_code(input: String) -> String {
wrap_comments: Some(true),
..Default::default()
};
space_out_items(rustfmt_wrapper::rustfmt_config(config, input).unwrap()).unwrap()
space_out_items(&rustfmt_wrapper::rustfmt_config(config, input).unwrap()).unwrap()
}

fn save<P>(p: P, data: &str) -> Result<()>
Expand Down Expand Up @@ -131,7 +131,7 @@ fn main() -> Result<()> {
println!("-----------------------------------------------------");
for (idx, type_entry) in type_space.iter_types().enumerate() {
let n = type_entry.describe();
println!("{:>4} {}", idx, n);
println!("{idx:>4} {n}");
}
println!("-----------------------------------------------------");
println!();
Expand All @@ -153,18 +153,18 @@ fn main() -> Result<()> {
version = \"{}\"\n\
edition = \"2024\"\n\
license = \"{}\"\n",
name, version, &args.license_name,
name, version, args.license_name,
);
if let Some(registry_name) = args.registry_name {
tomlout.extend(format!("publish = [\"{}\"]\n", registry_name).chars());
tomlout.extend(format!("publish = [\"{registry_name}\"]\n").chars());
}
tomlout.extend(
format!(
"\n\
[dependencies]\n\
{}\n\
\n",
dependencies(builder, args.include_client).join("\n"),
dependencies(&builder, args.include_client).join("\n"),
)
.chars(),
);
Expand All @@ -178,7 +178,7 @@ fn main() -> Result<()> {

// Create the Rust source file containing the generated client:
let lib_code = if args.include_client {
format!("mod progenitor_client;\n\n{}", api_code)
format!("mod progenitor_client;\n\n{api_code}")
} else {
api_code.to_string()
};
Expand All @@ -198,7 +198,7 @@ fn main() -> Result<()> {
}

Err(e) => {
println!("gen fail: {:?}", e);
println!("gen fail: {e:?}");
bail!("generation experienced errors");
}
}
Expand Down Expand Up @@ -239,7 +239,8 @@ static DEPENDENCIES: Dependencies = Dependencies {
uuid: "1.0",
};

pub fn dependencies(builder: Generator, include_client: bool) -> Vec<String> {
#[must_use]
pub fn dependencies(builder: &Generator, include_client: bool) -> Vec<String> {
let mut deps = vec![
format!("bytes = \"{}\"", DEPENDENCIES.bytes),
format!("futures-core = \"{}\"", DEPENDENCIES.futures),
Expand All @@ -255,25 +256,24 @@ pub fn dependencies(builder: Generator, include_client: bool) -> Vec<String> {
];

let type_space = builder.get_type_space();
let mut needs_serde_json = false;

if include_client {
let needs_serde_json = if include_client {
// code included from progenitor-client needs extra dependencies
deps.push(format!(
"percent-encoding = \"{}\"",
DEPENDENCIES.percent_encoding
));
needs_serde_json = true;
true
} else {
let crate_version =
if let (false, Some(value)) = (is_non_release(), option_env!("CARGO_PKG_VERSION")) {
value
} else {
"*"
};
let client_version_dep = format!("progenitor-client = \"{}\"", crate_version);
let client_version_dep = format!("progenitor-client = \"{crate_version}\"");
deps.push(client_version_dep);
}
false
};

if type_space.uses_regress() {
deps.push(format!("regress = \"{}\"", DEPENDENCIES.regress));
Expand Down Expand Up @@ -309,12 +309,11 @@ where
P: AsRef<Path> + std::clone::Clone + std::fmt::Debug,
{
let mut f = File::open(p.clone())?;
let api = match serde_json::from_reader(f) {
Ok(json_value) => json_value,
_ => {
f = File::open(p)?;
serde_yaml::from_reader(f)?
}
let api = if let Ok(json_value) = serde_json::from_reader(f) {
json_value
} else {
f = File::open(p)?;
serde_yaml::from_reader(f)?
};
Ok(api)
}
4 changes: 2 additions & 2 deletions cargo-progenitor/tests/data/test_help.stdout
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Generate a stand-alone crate from an OpenAPI document
Generate a stand-alone crate from an `OpenAPI` document

Usage: cargo progenitor [OPTIONS] --input <INPUT> --output <OUTPUT> --name <NAME> --version <VERSION>

Options:
-i, --input <INPUT>
OpenAPI definition document (JSON or YAML)
`OpenAPI` definition document (JSON or YAML)
-o, --output <OUTPUT>
Output directory for Rust crate
-n, --name <NAME>
Expand Down
2 changes: 1 addition & 1 deletion example-build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{

fn main() {
let src = "../sample_openapi/keeper.json";
println!("cargo:rerun-if-changed={}", src);
println!("cargo:rerun-if-changed={src}");
let file = File::open(src).unwrap();
let spec = serde_json::from_reader(file).unwrap();
let mut generator = progenitor::Generator::default();
Expand Down
12 changes: 5 additions & 7 deletions example-build/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ include!(concat!(env!("OUT_DIR"), "/codegen.rs"));

fn main() {
let client = Client::new("https://foo/bar");
let _ = client.enrol(
"auth-token",
&types::EnrolBody {
host: "".to_string(),
key: "".to_string(),
},
);
let body = types::EnrolBody {
host: String::new(),
key: String::new(),
};
let _future = client.enrol("auth-token", &body);
}
6 changes: 3 additions & 3 deletions example-macro/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use progenitor::generate_api;
generate_api!(
spec = "../sample_openapi/keeper.json",
pre_hook = (|request| {
println!("doing this {:?}", request);
println!("doing this {request:?}");
}),
pre_hook_async = crate::add_auth_headers,
post_hook = crate::all_done,
Expand All @@ -27,12 +27,12 @@ async fn add_auth_headers(
Ok(())
}

fn all_done(_result: &reqwest::Result<reqwest::Response>) {}
const fn all_done(_result: &reqwest::Result<reqwest::Response>) {}

mod buildomat {
use progenitor::generate_api;

generate_api!("../sample_openapi/buildomat.json");
}

fn main() {}
const fn main() {}
2 changes: 1 addition & 1 deletion example-out-dir/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
// complex build script might, for example, extract the OpenAPI document
// from a non-file source, writing it out to OUT_DIR.
let src = "../sample_openapi/keeper.json";
println!("cargo:rerun-if-changed={}", src);
println!("cargo:rerun-if-changed={src}");

let out_dir = env::var("OUT_DIR").unwrap();
let dest = Path::new(&out_dir).join("keeper.json");
Expand Down
12 changes: 5 additions & 7 deletions example-out-dir/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ generate_api!(

fn main() {
let client = Client::new("https://example.com");
std::mem::drop(client.enrol(
"auth-token",
&types::EnrolBody {
host: "".to_string(),
key: "".to_string(),
},
));
let body = types::EnrolBody {
host: String::new(),
key: String::new(),
};
let _future = client.enrol("auth-token", &body);
}
2 changes: 1 addition & 1 deletion example-wasm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{

fn main() {
let src = "../sample_openapi/keeper.json";
println!("cargo:rerun-if-changed={}", src);
println!("cargo:rerun-if-changed={src}");
let file = File::open(src).unwrap();
let spec = serde_json::from_reader(file).unwrap();
let mut generator = progenitor::Generator::default();
Expand Down
12 changes: 5 additions & 7 deletions example-wasm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ include!(concat!(env!("OUT_DIR"), "/codegen.rs"));

fn main() {
let client = Client::new("https://foo/bar");
let _ = client.enrol(
"auth-token",
&types::EnrolBody {
host: "".to_string(),
key: "".to_string(),
},
);
let body = types::EnrolBody {
host: String::new(),
key: String::new(),
};
let _future = client.enrol("auth-token", &body);
}
2 changes: 1 addition & 1 deletion example-wasm/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
#[wasm_bindgen_test::wasm_bindgen_test]
fn test_client_new() {
let client = Client::new("http://foo/bar");
assert!(client.baseurl == "http://foo/bar");
assert_eq!(client.baseurl, "http://foo/bar");
}
3 changes: 2 additions & 1 deletion progenitor-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub use crate::progenitor_client::*;
// need to determine the provenance of progenitor (crates.io, github, etc.)
// when generating the stand-alone crate.
#[doc(hidden)]
pub fn code() -> &'static str {
#[must_use]
pub const fn code() -> &'static str {
include_str!("progenitor_client.rs")
}
Loading