poem-web / poem

A full-featured and easy-to-use web framework with the Rust programming language.
Apache License 2.0
3.62k stars 295 forks source link

How to get nested objects when retrieving query parameters with Query? #866

Open jctaveras opened 3 months ago

jctaveras commented 3 months ago

First of all, thank you for this awesome crate. With that being said, I was wondering how do I get nested objects when retrieving query parameters with Query based on the Parameter Serialization standard?

Let's say we have the following:

use poem::web::Query;
use poem_openapi::OpenApi;

#[derive(Deserialize, Object)]
pub struct Search {
    #[oai(rename = "search[term]")]
    pub term: String,
    #[oai(rename = "search[columns]")]
    pub columns: Vec<String>
}

#[derive(Deserialize)]
pub struct Params {
    pub limit: Option<i64>,
    pub search: Option<Search>
}

pub struct API;

#[OpenApi]
impl API {
    #[oai(path = "/", method = "get")]
    fn async fn with_search(&self, Query(params): Query<Params>) {
        // curl http://localhost:PORT/?search[term]=foo&search[columns]=bar,baz
        println!("{:?}",  params.search) // None
    }
}

Is this supported?