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

Derive URL path form handler to avoid declaring it twice (axum) #537

Closed
lcmgh opened this issue Mar 22, 2023 · 2 comments · Fixed by #1004
Closed

Derive URL path form handler to avoid declaring it twice (axum) #537

lcmgh opened this issue Mar 22, 2023 · 2 comments · Fixed by #1004

Comments

@lcmgh
Copy link

lcmgh commented Mar 22, 2023

Hi!

I think it is quite error prone when the URL of an API endpoint has to be declared twice.

let app = Router::new()
    .route("/users", post(create_user))
/// Create new user
#[utoipa::path(
    post,
    path = "/users",
    request_body = CreateUser,
    responses(
        (status = 201, description = "Create user", body = [String])
    )
)]
pub async fn create_user(
    // this argument tells axum to parse the request body
    // as JSON into a `CreateUser` type
    Json(payload): Json<CreateUser>,
) -> (StatusCode, Json<User>) {
   // .. 
}

Could we add an option to make utoipa derive it from the API handler declaration? If that is possible I can also imagine that the Method (GET, POST) and even the output schema can be derived to avoid boilerplate.

Thanks!

@juhaku
Copy link
Owner

juhaku commented Mar 22, 2023

I think it is quite error prone when the URL of an API endpoint has to be declared twice.

That is error prone and suboptimal to say the least but that is what we have for now for axum.

There is existing issue related to this #394. So there are plans to improve the support for axum in future. Thank you for your patience 🙂

@juhaku
Copy link
Owner

juhaku commented Aug 16, 2024

There is now coming up implementation for this to reduce the duplicate endpoint registration. Currently in experimenting phase #991

@juhaku juhaku moved this to In Progress in utoipa kanban Aug 26, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in utoipa kanban Aug 26, 2024
@juhaku juhaku moved this from Done to Released in utoipa kanban Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Released
Development

Successfully merging a pull request may close this issue.

2 participants