-
Hi, how can I have optional parameters in my query? I have found similar questions with a possible solution related to query strings, but at the moment I wonder if I can keep the path syntax I am most familiar with. Related: #622 and #683. #[utoipa::path(
get,
path = "/all_users/{start_id}/{continuation_token}",
params(
("start_id", description = "Optional: Minimum ID of users to look for."),
("continuation_token", description = "Optional: Pass when requesting continuation pages."),
),
tag = TAG_USER,
responses(
(status = 200, description = "description.", body = [Vec<User>])
)
)]
pub async fn list_all_users(
Path((start_id, continuation_token)): Path<(Option<i32>, Option<String>)>,
DatabaseConnection(mut conn): DatabaseConnection,
) -> Result<Json<Vec<User>>, FetchUserDataError> {
todo!()
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The docs gives some examples of You are probably mixing up Query parameters are the ones that are defined after the question mark ( |
Beta Was this translation helpful? Give feedback.
The docs gives some examples of
params
format https://docs.rs/utoipa/latest/utoipa/attr.path.html#parameter-formats.You are probably mixing up
path
params andquery
params. Path params that are described in the path e.g./user/{id}/{type}
must be present. Path params are always required and cannot be non required. That means that in order to call the path you must give those parameters otherwise the endpoint does not match. You could call the endpoint with/user/null/null
which will result inNone
for both values. But calling it with/user
does only give the default behavior of the http framework you are using which is either 404, 415, or 500 most likely.Query parameters are the ones th…