pub enum SecurityScheme {
Bearer {
format: Option<String>,
description: Option<String>,
},
Basic {
description: Option<String>,
},
ApiKey {
name: String,
location: ApiKeyLocation,
description: Option<String>,
},
OAuth2 {
flows: Box<OAuth2Flows>,
description: Option<String>,
},
OpenIdConnect {
open_id_connect_url: String,
description: Option<String>,
},
}Expand description
OpenAPI security scheme configuration.
This enum represents the different types of security schemes supported by OpenAPI. Each variant maps directly to an OpenAPI security scheme type.
§Supported Schemes
- Bearer: HTTP Bearer token authentication (RFC 6750)
- Basic: HTTP Basic authentication (RFC 7617)
- ApiKey: API key passed in header, query, or cookie
- OAuth2: OAuth 2.0 authentication flows
- OpenIdConnect: OpenID Connect Discovery
§Example
use clawspec_core::{SecurityScheme, ApiKeyLocation};
// Simple bearer token
let bearer = SecurityScheme::bearer();
// Bearer with JWT format hint
let jwt = SecurityScheme::bearer_with_format("JWT");
// API key in header
let api_key = SecurityScheme::api_key("X-API-Key", ApiKeyLocation::Header);
// Basic auth
let basic = SecurityScheme::basic();Variants§
Bearer
HTTP Bearer authentication (RFC 6750).
Used for token-based authentication where the client sends
an Authorization: Bearer <token> header.
Fields
Basic
HTTP Basic authentication (RFC 7617).
Uses Authorization: Basic <base64(username:password)> header.
ApiKey
API Key authentication.
The API key can be passed in a header, query parameter, or cookie.
Fields
location: ApiKeyLocationWhere the API key is passed
OAuth2
OAuth 2.0 authentication.
Supports multiple OAuth2 flows: authorization code, client credentials, implicit, and password.
Fields
flows: Box<OAuth2Flows>OAuth2 flows configuration (boxed to reduce enum size)
OpenIdConnect
OpenID Connect Discovery.
Uses OpenID Connect for authentication with automatic discovery of the provider’s configuration.
Implementations§
Source§impl SecurityScheme
impl SecurityScheme
Sourcepub fn bearer() -> Self
pub fn bearer() -> Self
Creates a simple HTTP Bearer authentication scheme.
§Example
use clawspec_core::SecurityScheme;
let scheme = SecurityScheme::bearer();Sourcepub fn bearer_with_format(format: impl Into<String>) -> Self
pub fn bearer_with_format(format: impl Into<String>) -> Self
Sourcepub fn basic() -> Self
pub fn basic() -> Self
Creates an HTTP Basic authentication scheme.
§Example
use clawspec_core::SecurityScheme;
let scheme = SecurityScheme::basic();Sourcepub fn api_key(name: impl Into<String>, location: ApiKeyLocation) -> Self
pub fn api_key(name: impl Into<String>, location: ApiKeyLocation) -> Self
Sourcepub fn openid_connect(url: impl Into<String>) -> Self
pub fn openid_connect(url: impl Into<String>) -> Self
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Adds a description to the security scheme.
§Example
use clawspec_core::SecurityScheme;
let scheme = SecurityScheme::bearer()
.with_description("JWT token obtained from /auth/login");Trait Implementations§
Source§impl Clone for SecurityScheme
impl Clone for SecurityScheme
Source§fn clone(&self) -> SecurityScheme
fn clone(&self) -> SecurityScheme
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more