juhaku / utoipa

Simple, Fast, Code first and Compile time generated OpenAPI documentation for Rust
Apache License 2.0
2.48k stars 194 forks source link

swagger-ui show request params as required even though they are Options #1058

Closed eranrund closed 1 month ago

eranrund commented 1 month ago

Hello!

On commit 576f6c129010b4f6e6445c06393cfcf2cfee30df I am seeing the following struct:

#[derive(Clone, Debug, Default, Serialize, Deserialize, IntoParams)]
pub struct PageRequest {
    /// The maximum number of responses in a page
    /// Each route may have its own default if this is omitted
    #[serde(default)]
    #[param(required = false)]
    pub limit: Option<u64>,

    /// The page token, if the requester earlier got a paginated response.
    #[serde(default)]

    pub page_token: Option<String>,
}

Produce the following Swagger UI:

image

Specifying #[param(required = false)] has no effect either, both parameters still show up as required.

I am at a loss as to why this happens.

Thanks :)

eranrund commented 1 month ago

Wrapping in #[into_params(parameter_in = Query)] as suggested in https://github.com/juhaku/utoipa/issues/622 seems to address this.