poem icon indicating copy to clipboard operation
poem copied to clipboard

What is the expect behavior of `Path<Vec<T>>` in openapi

Open duskmoon314 opened this issue 1 year ago • 1 comments

I describe an API like this:

#[OpenApi]
impl Api {
    /// Return status code or random status code if more than one is given
    #[oai(
        path = "/status/:codes",
        method = "get",
        tag = "ApiTags::StatusCodes"
    )]
    async fn status(&self, codes: Path<Vec<u16>>) -> StatusRes {
        if codes.len() > 1 {
            let mut rng = rand::thread_rng();
            let idx = rng.gen_range(0..codes.len());
            StatusRes::from(codes[idx])
        } else {
            StatusRes::from(codes[0])
        }
    }
}

I expect usage like /status/200,300,400 or so. And the above code will lead to array[integer] in swagger.

But when really receiving requests like 200,300, it seems there is no parse_from_parameter(&str) for Vec<T> and come across this error:

failed to parse path `codes`: failed to parse "integer(uint16)": invalid digit found in string (occurred while parsing "[integer(uint16)]")

Did I misunderstand or is this a bug?

duskmoon314 avatar Jul 30 '22 04:07 duskmoon314

This is not supported right now and I need to think about how to do it.

sunli829 avatar Jul 30 '22 13:07 sunli829

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 30 '22 03:08 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Sep 05 '22 04:09 github-actions[bot]