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

Default tag does not get overriden. #955

Closed
EinarasGar opened this issue Jun 5, 2024 · 4 comments · Fixed by #1002
Closed

Default tag does not get overriden. #955

EinarasGar opened this issue Jun 5, 2024 · 4 comments · Fixed by #1002

Comments

@EinarasGar
Copy link

Hi, Im trying out version 5.0.0-alpha.0 and have noticed new behavior with tags.
As mentioned in #916

This means that the default tag (the handler function name by default) will be added if not overridden with the tag attribute.

However, I do not experience this behavior.
Using this configuration

#[derive(OpenApi)]
#[openapi(
    paths(
        super::handlers::accounts_handler::get_account,
         ...
    ),

and

/// Get Account
///
/// Gets a specific account of the user with metadata.
#[utoipa::path(
    get,
    path = "/api/users/:user_id/accounts/:account_id",
    tag = "Accounts",
    responses(
        ...
    ),
    params(
        ...
    ),
    security(
      ...
    )

)]
pub async fn get_account(

My openapi spec generates like this

"/api/users/:user_id/accounts/:account_id": {
      "get": {
        "tags": [
          "Accounts",
          "super::handlers::accounts_handler"
        ],
        "summary": "Get Account",
        "description": "Gets a specific account of the user with metadata.",
        "operationId": "get_account",
...

This results in my redoc view having double of everything.

Reproducable example can be found here
https://github.com/EinarasGar/myra/blob/crate-update/server/api/src/openapi.rs
https://github.com/EinarasGar/myra/blob/crate-update/server/api/src/handlers/accounts_handler.rs

@NickUfer
Copy link

NickUfer commented Jun 7, 2024

Got the same problem. You have to add an import statement for what you are using as a path or an api. In your case this should fix it, if super:: works the same as crate:: :

use super::handlers::accounts_handler::get_account;

#[derive(OpenApi)]
#[openapi(
    paths(
        get_account,
         ...
    ),

@eiswind
Copy link

eiswind commented Jun 17, 2024

I see the same issue here. But my handler and the #[derive(OpenApi)] are in the same module, so I do not need to import.
In the generated spec I see my custom tag, as well as the module name.

#[derive(OpenApi)]
#[openapi(
    tags((name = "Authentication", description = "Authentication operations")),
    paths(authenticate),
    components(schemas(
      ...
    ))
)]

@eiswind
Copy link

eiswind commented Jul 12, 2024

Solved it: Had to import the classes for nest() the same way as described in #955 (comment)

@juhaku
Copy link
Owner

juhaku commented Aug 31, 2024

While that works as well, there was a bug in the tags support that caused havoc. This is also elaborated here #978 And should be fixed here #1002.

@juhaku juhaku closed this as completed Aug 31, 2024
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

Successfully merging a pull request may close this issue.

4 participants