poem
poem copied to clipboard
Using HashMap with poem_openapi::param::Query
Hi, thanks for this library!
I am running into an issue. I would like to use a HashMap
with poem_openapi::param::Query
. Here is a small example:
#[OpenApi(prefix_path = "/v1")]
impl Api {
#[oai(path = "/my_endpoint", method = "get")]
async fn my_endpoint(
&self,
query: poem_openapi::param::Query<HashMap<String, String>>,
) -> PlainText<String> {
let maybeQueryValue = query.0.get("prop1");
PlainText(
maybeQueryValue
.unwrap_or(&"missing".to_string())
.to_string(),
)
}
}
One could, for example, call the endpoint like this:
/v1/my_endpoint?prop1=test&prop2=test2&additionalProp3=string
The expected swagger spec would look like this:
"parameters": [
{
"name": "query",
"in": "query",
"required": true,
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
],
Unfortunately, it appears that it does not work, and I get the following error:
the trait `ApiExtractor<'_>` is not implemented for `poem_openapi::param::Query<HashMap<std::string::String, std::string::String>>`
A workaround to get the application to work is to use poem::web::Query
instead. However, then it does not show up in the documentation.
Thanks!
This is not currently supported, I will add it later.
Would be great to have this...