mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-30 12:40:52 +00:00
[Rust] Add support for shallow object query params
This commit is contained in:
parent
226a784632
commit
81e7d99898
@ -155,7 +155,13 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
|
|||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
{{^isArray}}
|
{{^isArray}}
|
||||||
{{^isNullable}}
|
{{^isNullable}}
|
||||||
|
{{#isModel}}
|
||||||
|
let params = crate::apis::parse_flat_object(&serde_json::to_value({{{vendorExtensions.x-rust-param-identifier}}})?);
|
||||||
|
req_builder = req_builder.query(¶ms);
|
||||||
|
{{/isModel}}
|
||||||
|
{{^isModel}}
|
||||||
req_builder = req_builder.query(&[("{{{baseName}}}", &{{{vendorExtensions.x-rust-param-identifier}}}.to_string())]);
|
req_builder = req_builder.query(&[("{{{baseName}}}", &{{{vendorExtensions.x-rust-param-identifier}}}.to_string())]);
|
||||||
|
{{/isModel}}
|
||||||
{{/isNullable}}
|
{{/isNullable}}
|
||||||
{{#isNullable}}
|
{{#isNullable}}
|
||||||
{{#isDeepObject}}
|
{{#isDeepObject}}
|
||||||
@ -165,9 +171,17 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
|
|||||||
};
|
};
|
||||||
{{/isDeepObject}}
|
{{/isDeepObject}}
|
||||||
{{^isDeepObject}}
|
{{^isDeepObject}}
|
||||||
|
{{#isModel}}
|
||||||
|
if let Some(ref param_value) = {{{vendorExtensions.x-rust-param-identifier}}} {
|
||||||
|
let params = crate::apis::parse_flat_object(&serde_json::to_value({{{vendorExtensions.x-rust-param-identifier}}})?);
|
||||||
|
req_builder = req_builder.query(¶ms);
|
||||||
|
};
|
||||||
|
{{/isModel}}
|
||||||
|
{{^isModel}}
|
||||||
if let Some(ref param_value) = {{{vendorExtensions.x-rust-param-identifier}}} {
|
if let Some(ref param_value) = {{{vendorExtensions.x-rust-param-identifier}}} {
|
||||||
req_builder = req_builder.query(&[("{{{baseName}}}", ¶m_value.to_string())]);
|
req_builder = req_builder.query(&[("{{{baseName}}}", ¶m_value.to_string())]);
|
||||||
};
|
};
|
||||||
|
{{/isModel}}
|
||||||
{{/isDeepObject}}
|
{{/isDeepObject}}
|
||||||
{{/isNullable}}
|
{{/isNullable}}
|
||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
@ -186,7 +200,13 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
|
|||||||
req_builder = req_builder.query(¶ms);
|
req_builder = req_builder.query(¶ms);
|
||||||
{{/isDeepObject}}
|
{{/isDeepObject}}
|
||||||
{{^isDeepObject}}
|
{{^isDeepObject}}
|
||||||
|
{{#isModel}}
|
||||||
|
let params = crate::apis::parse_flat_object(&serde_json::to_value(param_value)?);
|
||||||
|
req_builder = req_builder.query(¶ms);
|
||||||
|
{{/isModel}}
|
||||||
|
{{^isModel}}
|
||||||
req_builder = req_builder.query(&[("{{{baseName}}}", ¶m_value.to_string())]);
|
req_builder = req_builder.query(&[("{{{baseName}}}", ¶m_value.to_string())]);
|
||||||
|
{{/isModel}}
|
||||||
{{/isDeepObject}}
|
{{/isDeepObject}}
|
||||||
{{/isArray}}
|
{{/isArray}}
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,33 @@ pub fn urlencode<T: AsRef<str>>(s: T) -> String {
|
|||||||
::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
|
::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn parse_flat_object(value: &serde_json::Value) -> Vec<(String, String)> {
|
||||||
|
if let serde_json::Value::Object(object) = value {
|
||||||
|
let mut params = vec![];
|
||||||
|
|
||||||
|
for (key, value) in object {
|
||||||
|
match value {
|
||||||
|
serde_json::Value::Object(_) => {
|
||||||
|
unimplemented!(
|
||||||
|
"Only flat objects are supported, use parse_deep_object() instead"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
serde_json::Value::Array(array) => {
|
||||||
|
for (i, value) in array.iter().enumerate() {
|
||||||
|
params.push((format!("{key}[{i}]"), value.to_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
serde_json::Value::String(s) => params.push((key.to_string(), s.clone())),
|
||||||
|
_ => params.push((key.to_string(), value.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
unimplemented!("Only objects are supported")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> {
|
pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> {
|
||||||
if let serde_json::Value::Object(object) = value {
|
if let serde_json::Value::Object(object) = value {
|
||||||
let mut params = vec![];
|
let mut params = vec![];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user