pub async fn handle_metrics_metrics_get<'a>(
&'a self,
accept: Option<&'a Vec<String>>,
) -> Result<ResponseValue<String>, Error<types::ErrorResponse>> {
let url = format!("{}/metrics/", self.baseurl,);
let mut header_map = HeaderMap::with_capacity(1usize);
if let Some(v) = accept {
header_map.append("accept", HeaderValue::try_from(v.first().unwrap())?);
}
#[allow(unused_mut)]
let mut request = self
.client
.get(url)
.header(
reqwest::header::ACCEPT,
reqwest::header::HeaderValue::from_static("application/json"),
)
.headers(header_map)
.build()?;
let result = self.client.execute(request).await;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
422u16 => Err(Error::ErrorResponse(
ResponseValue::from_response(response).await?,
)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
This fails to compile:
error[E0277]: the trait bound `HeaderValue: From<&Vec<std::string::String>>` is not satisfied
--> catalog-api-v1/src/client.rs:2635:41
|
2635 | header_map.append("accept", HeaderValue::try_from(v)?);
| ^^^^^^^^^^^ the trait `From<&Vec<std::string::String>>` is not implemented for `HeaderValue`, which is required by `HeaderValue: TryFrom<&Vec<std::string::String>>`
|
= help: the following other types implement trait `From<T>`:
<HeaderValue as From<isize>>
<HeaderValue as From<i16>>
<HeaderValue as From<i32>>
<HeaderValue as From<i64>>
<HeaderValue as From<usize>>
<HeaderValue as From<u16>>
<HeaderValue as From<u32>>
<HeaderValue as From<u64>>
and 2 others
= note: required for `&Vec<std::string::String>` to implement `Into<HeaderValue>`
= note: required for `HeaderValue` to implement `TryFrom<&Vec<std::string::String>>`
In short, all that's necessary for this to compile is for the generated code to loop over the values in the Vec and append them individually rather than appending the entire Vec. Now, detecting that you have a Vec and special casing it may be another story that I'll leave as an exercise to the ~reader~implementor.
Given this snippet from an OpenAPI spec:
You'll generate the following code:
This fails to compile:
In short, all that's necessary for this to compile is for the generated code to loop over the values in the
Vec
andappend
them individually rather than appending the entireVec
. Now, detecting that you have aVec
and special casing it may be another story that I'll leave as an exercise to the ~reader~implementor.