File tree Expand file tree Collapse file tree
modules/openapi-generator/src/main/resources/rust/reqwest Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -155,7 +155,13 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
155155 { {/isArray} }
156156 { {^isArray} }
157157 { {^isNullable} }
158+ { {#isModel} }
159+ let params = crate::apis::parse_flat_object(&serde_json::to_value({ {{vendorExtensions.x-rust-param-identifier} }})?);
160+ req_builder = req_builder.query(¶ms);
161+ { {/isModel} }
162+ { {^isModel} }
158163 req_builder = req_builder.query(& [("{ {{baseName} }}", & { {{vendorExtensions.x-rust-param-identifier} }}.to_string())]);
164+ { {/isModel} }
159165 { {/isNullable} }
160166 { {#isNullable} }
161167 { {#isDeepObject} }
@@ -232,7 +238,8 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
232238 req_builder = req_builder.query(& [("{ {{baseName} }}", &serde_json::to_string(param_value)?)]);
233239 { {/isObject} }
234240 { {#isModel} }
235- req_builder = req_builder.query(& [("{ {{baseName} }}", &serde_json::to_string(param_value)?)]);
241+ let params = crate::apis::parse_flat_object(&serde_json::to_value(param_value)?);
242+ req_builder = req_builder.query(¶ms);
236243 { {/isModel} }
237244 { {^isObject} }
238245 { {^isModel} }
Original file line number Diff line number Diff line change @@ -105,6 +105,33 @@ pub fn urlencode<T: AsRef<str>>(s: T) -> String {
105105 ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
106106}
107107
108+ pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> {
109+ if let serde_json::Value::Object(object) = value {
110+ let mut params = vec! [];
111+
112+ for (key, value) in object {
113+ match value {
114+ serde_json::Value::Object(_) => {
115+ unreachable! (
116+ " This should never be reached, there's a bug on the codegen or the templates"
117+ )
118+ }
119+ serde_json::Value::Array(array) => {
120+ for (i, value) in array.iter().enumerate() {
121+ params.push((format! (" {key}[{i}]" ), value.to_string()));
122+ }
123+ }
124+ serde_json::Value::String(s) => params.push((key.to_string(), s.clone())),
125+ _ => params.push((key.to_string(), value.to_string())),
126+ }
127+ }
128+
129+ return params;
130+ }
131+
132+ unimplemented!("Only objects are supported")
133+ }
134+
108135pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> {
109136 if let serde_json::Value::Object(object) = value {
110137 let mut params = vec! [];
You can’t perform that action at this time.
0 commit comments