paperclip
paperclip copied to clipboard
HashMap as string type in QsQuery
I have a HashMap which will be deserialized with QsQuery. So the input is a string. But based on paperclip, the type is Object.
Is there any way to override this? Or implement TypedData for my HashMap?
I did this with introducing a new struct.
It was similar to:
#[derive(Deserialize, Apiv2Schema)]
pub struct MainType {
pub something: Option<HashMap<String, String>>,
}
Now it's like:
#[derive(Deserialize)]
pub struct MyNewType {
#[serde(flatten)]
pub inner: HashMap<String, String>
}
impl TypedData for MyNewType {
fn data_type() -> DataType {
DataType::String
}
}
#[derive(Deserialize, Apiv2Schema)]
pub struct MainType {
pub something: Option<MyNewType>,
}
Would be cool if you know a better/simpler/standard way and mention it here.
So I think there is no better way :D Going to close it :)
Let's keep it open so that we can track that there's an issue with this usage.
Hi @omid, I did some work yesterday to improve support for QsQuery
with some specific handling which I think will make an improvement for your usage.
I'm finding it quite difficult with qs to figure out if this works generally as qs doesn't really fit in with openapi very well. It would be good to hear if this improves things for you.
https://github.com/wafflespeanut/paperclip/pull/242/files
Hey @platy, thanks. I couldn't make it work with:
#[derive(Deserialize, Apiv2Schema)]
pub struct QueryParams {
pub limit: i32,
pub filter: Option<HashMap<String, Vec<String>>>,
}
nor this:
#[derive(Deserialize, Apiv2Schema)]
pub struct QueryParams {
pub limit: i32,
pub filter: Option<HashMap<String, String>>,
}
It doesn't show up any error, but also this field is not included in the OpenAPI output.
The limit
field does exist, but the filter
doesn't!