summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-01-16 19:07:28 +0100
committerCyborus <cyborus@cyborus.xyz>2024-01-16 19:07:28 +0100
commit12f2800b2630d354fa834be3accecef13833ebfa (patch)
tree75271deae46466aecc8125031c3d7d092b7b782e
parentmethods should be `pub` and `async` (diff)
downloadforgejo-api-12f2800b2630d354fa834be3accecef13833ebfa.tar.xz
forgejo-api-12f2800b2630d354fa834be3accecef13833ebfa.zip
convert path args to camel case in format string
-rw-r--r--generator/src/main.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/generator/src/main.rs b/generator/src/main.rs
index 9a8acd7..23a8bd0 100644
--- a/generator/src/main.rs
+++ b/generator/src/main.rs
@@ -392,7 +392,7 @@ fn create_method_request(
}
}
}
- let mut fmt_str = path.to_string();
+ let mut fmt_str = sanitize_path_arg(path)?;
let mut fmt_args = String::new();
if has_query {
fmt_str.push_str("?{}");
@@ -408,6 +408,32 @@ fn create_method_request(
Ok(out)
}
+fn sanitize_path_arg(mut path: &str) -> eyre::Result<String> {
+ let mut out = String::new();
+ loop {
+ let (head, tail) = match path.split_once("{") {
+ Some(i) => i,
+ None => {
+ out.push_str(path);
+ break;
+ }
+ };
+ path = tail;
+ out.push_str(head);
+ out.push('{');
+ let (head, tail) = match path.split_once("}") {
+ Some(i) => i,
+ None => {
+ eyre::bail!("unmatched bracket");
+ }
+ };
+ path = tail;
+ out.push_str(&head.to_snake_case());
+ out.push('}');
+ }
+ Ok(out)
+}
+
fn create_method_response(
spec: &OpenApiV2,
method: &str,