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 @@ -163,7 +163,18 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
163163 { {/isArray} }
164164 { {^isArray} }
165165 { {^isNullable} }
166+ { {#isModel} }
167+ { {#isDeepObject} }
168+ let params = crate::apis::parse_deep_object("{ {{baseName} }}", &serde_json::to_value(param_value)?);
169+ { {/isDeepObject} }
170+ { {^isDeepObject} }
171+ let params = crate::apis::parse_flat_object(&serde_json::to_value({ {{vendorExtensions.x-rust-param-identifier} }})?);
172+ { {/isDeepObject} }
173+ req_builder = req_builder.query(¶ms);
174+ { {/isModel} }
175+ { {^isModel} }
166176 req_builder = req_builder.query(& [("{ {{baseName} }}", & { {{vendorExtensions.x-rust-param-identifier} }}.to_string())]);
177+ { {/isModel} }
167178 { {/isNullable} }
168179 { {#isNullable} }
169180 { {#isDeepObject} }
@@ -240,7 +251,8 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
240251 req_builder = req_builder.query(& [("{ {{baseName} }}", &serde_json::to_string(param_value)?)]);
241252 { {/isObject} }
242253 { {#isModel} }
243- req_builder = req_builder.query(& [("{ {{baseName} }}", &serde_json::to_string(param_value)?)]);
254+ let params = crate::apis::parse_flat_object(&serde_json::to_value(param_value)?);
255+ req_builder = req_builder.query(¶ms);
244256 { {/isModel} }
245257 { {^isObject} }
246258 { {^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