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

IntoResponses #[response(...)] attributes only allows status #659

Open
Piscolero opened this issue Jun 27, 2023 · 4 comments
Open

IntoResponses #[response(...)] attributes only allows status #659

Piscolero opened this issue Jun 27, 2023 · 4 comments

Comments

@Piscolero
Copy link

Piscolero commented Jun 27, 2023

If using the IntoResponses derive macro, you cannot specify other response attributes besides status, although documentation says otherwise.

Example:

use utoipa::IntoResponses;

#[derive(IntoResponses)]
enum MyResponses {
    // this works
    #[response(status = NOT_FOUND)]
    #[allow(unused)]
    NotFound,

    // adding other attributes to response except status doesn't build
    // Error: expected identifier
    #[response(status = UNAUTHORIZED, example = json!({error: "not authorized"}))]
    NotAuthorized,
}

fn main() {}

Compilation fails with:

error: expected identifier
  --> src/main.rs:11:37
   |
11 |     #[response(status = UNAUTHORIZED, example = json!({error: "not authorized"}))]
   |                                     ^
@afidegnum
Copy link

try adding a status code.

@Piscolero
Copy link
Author

try adding a status code.

If you mean using status = 401 instead of status = UNAUTHORIZED, I already tried that without success.

@JMLX42
Copy link
Contributor

JMLX42 commented Jun 29, 2023

I can confirm I have the exact same problem. In addition to example I also tried content_type (cf #660). But the same problem occurs.

Only status works.

@juhaku
Copy link
Owner

juhaku commented Jul 3, 2023

Try removing the comma, this is actually a bug in the latest release: 3.3.0 that is fixed here: 16bec9d.

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

4 participants