Skip to content

Commit

Permalink
Scrub list indices from query strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteOtter committed Sep 27, 2024
1 parent 24de542 commit 15b4bb8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/pathgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn gen_fn(name: &str, op_type: &str, op: &Operation) -> String {
};
// Format as a struct field.
fn_query_params.push(format!(
"{}\tpub {}: Option<{}>,\n",
"{}\t{}: Option<{}>,\n",
make_comment(parameter_data.description, 1),
parameter_data.name.into_safe(),
bindgen::type_to_string(query_param_type)
Expand Down Expand Up @@ -193,7 +193,13 @@ fn gen_fn(name: &str, op_type: &str, op: &Operation) -> String {
result += ", Error>";

// Build the function body.
result += " {\n\tlet r#response = state.client.";
if need_query {
result += " {\n\tlet qstring = serde_qs::to_string(&query).unwrap();";
result += "\n\tlet qstring_clean = remove_square_braces(&qstring);";
result += "\n\tlet r#response = state.client."
} else {
result += " {\n\tlet r#response = state.client.";
}
result += op_type;
result += "(format!(\"{}";
result += name;
Expand All @@ -202,7 +208,7 @@ fn gen_fn(name: &str, op_type: &str, op: &Operation) -> String {
}
result += "\", state.base_url";
if need_query {
result += ", serde_qs::to_string(&query).unwrap()";
result += ", qstring_clean";
}
result += "))\n";

Expand Down Expand Up @@ -242,7 +248,7 @@ fn gen_fn(name: &str, op_type: &str, op: &Operation) -> String {
result += &fn_response_name;
result += "::Other(r#response)) }\n\t}\n}\n";

result
return result;
}

fn make_fn_name_from_path(input: &str) -> String {
Expand Down
1 change: 1 addition & 0 deletions src/templates/Cargo.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ serde_json = "1.0.108"
serde_qs = "0.12.0"
chrono = "0.4.31"
reqwest = {{ version = "0.11.22", features = ["blocking", "json"] }}
regex = "1.10.6"
2 changes: 1 addition & 1 deletion src/templates/usings.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(warnings)]

use crate::util::ThanixClient;
use crate::util::{ThanixClient, remove_square_braces};
use crate::types::*;
use serde_qs;
use reqwest::{Error, blocking::Response};
Expand Down
7 changes: 7 additions & 0 deletions src/templates/util.rs.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use regex::Regex;

pub struct ThanixClient {
pub client: reqwest::blocking::Client,
pub base_url: String,
pub authentication_token: String,
}

pub fn remove_square_braces(s: &str) -> String {
let re = Regex::new(r"\[\d+\]").unwrap();

re.replace_all(s, "").to_string()
}

0 comments on commit 15b4bb8

Please sign in to comment.