Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-tuple path parameters in axum #1302

Open
srkaj opened this issue Jan 27, 2025 · 0 comments
Open

Non-tuple path parameters in axum #1302

srkaj opened this issue Jan 27, 2025 · 0 comments

Comments

@srkaj
Copy link

srkaj commented Jan 27, 2025

We (me and @lisasvenssonsr) have noticed a discrepancy in how url parameters are detected for the openapi specification. If we use a tuple, the arguments are auto-detected, but if we use a single parameeter, we seem to need an annotation that I think should no longer be needed because of #1224.

These endpoints work as expected:

#[utoipa::path(
    get, path = "/{id}",
    params(MyId),  // This is still needed?
)]
async fn one(
    Path(id): Path<MyId>,
) -> Result<Json<MyDTO>> {
    // ...
}

#[utoipa::path(
    get, path = "/{id}/with/{subid}", // No "params" needed here!
)]
async fn other(
    Path((id, subid)): Path<(MyId, SubId)>,
) -> Result<Json<MyDTO>> {
    // ...
}

Having a single argument and no "params" annotation, like this endpoint, also works as expected in axum, except it does not get any parameters in the openapi specification / swagger guide:

#[utoipa::path(
    get, path = "/{id}",
)]
async fn one(
    Path(id): Path<MyId>,
) -> Result<Json<MyDTO>> {
    // ...
}

As a workaround, it seems wrapping the parameter in a single-value tuple is enogh to get it to work:

#[utoipa::path(
    get, path = "/{id}",
)]
async fn one(
    Path((id,)): Path<(MyId,)>,
) -> Result<Json<MyDTO>> {
    // ...
}

Are we missing anything? Should there be another trait implemented for MyId that is somehow implemented for the tuple? Or is this a bug in utoipa?

Versions used

According to our Cargo.toml:

axum = "0.8.1"
utoipa = { version = "5.2.0", features = ["axum_extras", "openapi_extensions", "preserve_order", "uuid"] }
utoipa-axum = "0.2.0"
utoipa-swagger-ui = { version="9.0.0", features = ["axum"] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant