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

Allow SecurityScheme as Macro parameter of OpenApi or oai #822

Open
Bednys94 opened this issue May 28, 2024 · 1 comment
Open

Allow SecurityScheme as Macro parameter of OpenApi or oai #822

Bednys94 opened this issue May 28, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Bednys94
Copy link

Bednys94 commented May 28, 2024

Description of the feature

Hi, would be possible to add attribute security_scheme for generating swagger-ui security scheme without need to have it as a fn param? I have several APIs and it's little bit confusing to have _auth: SecuritySchema as parameter in almost all open api functions and only because of generating swagger api doc with lock icon next to the request definition.

Code example (if possible)

#[derive(SecurityScheme)]
#[oai(ty = "basic")]
pub struct BasicSecurityScheme(Basic);

It would be nice instead of this
#[OpenApi(
prefix_path = "/secure",
tag = "CustomApiTags::Custom",
)]
impl CustomApi {
#[oai(path = "/test-auth", method = "get")]
async fn test_auth(&self, _auth: SecurityScheme) -> Result {
Ok("Test auth".to_string())
}
}

use this

#[OpenApi(
prefix_path = "/secure",
tag = "CustomApiTags::Custom",
security_scheme = "BasicSecurityScheme"
)]
impl CustomApi {
#[oai(path = "/test", method = "get")]
async fn test(&self) -> Result {
Ok("Test auth".to_string())
}
}

or this

#[OpenApi(
prefix_path = "/secure",
tag = "CustomApiTags::Custom",
)]
impl CustomApi {
#[oai(path = "/test-auth", method = "get", security_scheme = "BasicSecurityScheme")]
async fn test_auth(&self) -> Result {
Ok("Test auth".to_string())
}

#[oai(path = "/test-no-auth", method = "get")]
async fn test_no_auth(&self) -> Result<String> {
    Ok("Test auth".to_string())
}

}

@Bednys94 Bednys94 added the enhancement New feature or request label May 28, 2024
@skrcka
Copy link

skrcka commented Oct 7, 2024

yes please

there is this library that works in a similar way: https://crates.io/crates/poem-grants

but it doesnt add auth in the specification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants