Derive Macro apistos::ApiSecurity
source · #[derive(ApiSecurity)]
{
// Attributes available to this derive:
#[openapi_security]
}
Expand description
Generates a reusable OpenAPI security scheme.
This #[derive]
macro should be used in combination with api_operation.
The macro requires one and only one openapi_security
.
use apistos::ApiSecurity;
#[derive(ApiSecurity)]
#[openapi_security(scheme(security_type(api_key(name = "api_key", api_key_in = "header"))))]
pub struct ApiKey;
§#[openapi_security(...)]
options:
name = "..."
an optional name for your security definition. If not provided, the struct ident will be used.scheme(...)
a required parameter with:description = "..."
an optional descriptionsecurity_type(...)
a required parameter with one ofoauth2(flows(...))
withimplicit(...)
withauthorization_url = "..."
a required parameter,refresh_url = "..."
an optional parameter andscopes(scope = "...", description = "...")
a list of scopespassword(...)
withtoken_url = "..."
a required parameter,refresh_url = "..."
an optional parameter andscopes(scope = "...", description = "...")
a list of scopesclient_credentials(...)
withtoken_url = "..."
a required parameter,refresh_url = "..."
an optional parameter andscopes(scope = "...", description = "...")
a list of scopesauthorization_code(...)
withtoken_url = "..."
a required parameter,refresh_url = "..."
an optional parameter andscopes(scope = "...", description = "...")
a list of scopes
api_key(...)
withname = "..."
a required parameterapi_key_in = "..."
a required parameter being one ofquery
,header
orcookie
http(...)
withscheme = "..."
a required parameterbearer_format = "..."
a required parameter
open_id_connect(open_id_connect_url = "...")
§Examples:
§oauth2
use apistos::ApiSecurity;
#[derive(ApiSecurity)]
#[openapi_security(scheme(security_type(oauth2(flows(implicit(
authorization_url = "https://authorize.com",
refresh_url = "https://refresh.com",
scopes(scope = "all:read", description = "Read all the things"),
scopes(scope = "all:write", description = "Write all the things")
))))))]
pub struct ApiKey;
§api_key
use apistos::ApiSecurity;
#[derive(ApiSecurity)]
#[openapi_security(scheme(security_type(api_key(name = "api_key", api_key_in = "header"))))]
pub struct ApiKey;
§http
use apistos::ApiSecurity;
#[derive(ApiSecurity)]
#[openapi_security(scheme(security_type(http(scheme = "bearer", bearer_format = "JWT"))))]
pub struct ApiKey;
§open_id_connect
use apistos::ApiSecurity;
#[derive(ApiSecurity)]
#[openapi_security(scheme(security_type(open_id_connect(open_id_connect_url = "https://connect.com"))))]
pub struct ApiKey;