summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-01-17 00:59:46 +0100
committerCyborus <cyborus@cyborus.xyz>2024-01-17 00:59:46 +0100
commitc83eecc7ff90fa03e843b751e2c64c9639d065fc (patch)
tree1f33ae8c81e9610d487cedc50efbd211a3e9b16a /generator
parentguess which types are url by field name (diff)
downloadforgejo-api-c83eecc7ff90fa03e843b751e2c64c9639d065fc.tar.xz
forgejo-api-c83eecc7ff90fa03e843b751e2c64c9639d065fc.zip
praise rustfmt
Diffstat (limited to 'generator')
-rw-r--r--generator/src/main.rs45
1 files changed, 32 insertions, 13 deletions
diff --git a/generator/src/main.rs b/generator/src/main.rs
index b0da534..24ff7e2 100644
--- a/generator/src/main.rs
+++ b/generator/src/main.rs
@@ -875,24 +875,41 @@ fn create_query_struct(spec: &OpenApiV2, path: &str, op: &Operation) -> eyre::Re
};
match format {
CollectionFormat::Csv => {
- handler.push_str(&simple_query_array(param, item_pusher, &field_name, ",")?);
+ handler.push_str(&simple_query_array(
+ param,
+ item_pusher,
+ &field_name,
+ ",",
+ )?);
}
CollectionFormat::Ssv => {
- handler.push_str(&simple_query_array(param, item_pusher, &field_name, " ")?);
+ handler.push_str(&simple_query_array(
+ param,
+ item_pusher,
+ &field_name,
+ " ",
+ )?);
}
CollectionFormat::Tsv => {
- handler.push_str(&simple_query_array(param, item_pusher, &field_name, "\\t")?);
+ handler.push_str(&simple_query_array(
+ param,
+ item_pusher,
+ &field_name,
+ "\\t",
+ )?);
}
CollectionFormat::Pipes => {
- handler.push_str(&simple_query_array(param, item_pusher, &field_name, "|")?);
+ handler.push_str(&simple_query_array(
+ param,
+ item_pusher,
+ &field_name,
+ "|",
+ )?);
}
CollectionFormat::Multi => {
writeln!(&mut handler, "")?;
writeln!(&mut handler, "if !{field_name}.is_empty() {{")?;
- writeln!(
- &mut handler,
- "for item in {field_name} {{"
- )?;
+ writeln!(&mut handler, "for item in {field_name} {{")?;
writeln!(&mut handler, "s.push_str(\"{}=\");", param.name)?;
handler.push_str(item_pusher);
handler.push('\n');
@@ -923,15 +940,17 @@ fn create_query_struct(spec: &OpenApiV2, path: &str, op: &Operation) -> eyre::Re
}
}
-fn simple_query_array(param: &Parameter, item_pusher: &str, name: &str, sep: &str) -> eyre::Result<String,> {
+fn simple_query_array(
+ param: &Parameter,
+ item_pusher: &str,
+ name: &str,
+ sep: &str,
+) -> eyre::Result<String> {
let mut out = String::new();
writeln!(&mut out, "s.push_str(\"{}=\");", param.name)?;
writeln!(&mut out, "")?;
writeln!(&mut out, "if !{name}.is_empty() {{")?;
- writeln!(
- &mut out,
- "for (i, item) in {name}.iter().enumerate() {{"
- )?;
+ writeln!(&mut out, "for (i, item) in {name}.iter().enumerate() {{")?;
out.push_str(item_pusher);
out.push('\n');
writeln!(&mut out, "if i < {name}.len() - 1 {{")?;